Запись видео с камеры, наложение растровых изображений, добавление звука, сохранение на устройстве - все в as3 / AIR mobile - PullRequest
4 голосов
/ 17 августа 2011

Мне поручено записать видеоизображение в реальном времени с камеры на мобильное устройство, затем наложить растровые изображения, которые меняются с течением времени, добавить звуковую mp3-дорожку в видеофайл, а затем сохранить ее где-нибудь на устройстве, например Фотопленка.

Я видел несколько полезных постов, в основном это: AS3 Flash / AIR записывает видео с веб-камеры и сохраняет его

Но, видимо, некоторые из них испытывали зависание приложений на настольных компьютерах Я могу только представить, что на мобильном устройстве было бы хуже ...

Кроме того, как я могу добавить информацию о видео вместе с отдельным аудио-mp3 в один файл?

Кто-нибудь совершил что-то подобное?

1 Ответ

7 голосов
/ 18 августа 2011

Обновление, у меня видео работает.Своего рода.Я до сих пор иногда получаю эту ошибку.Даже с короткими видео.

Error #2030: End of file was encountered.

Иногда все работает нормально.Но, по крайней мере, я могу записывать FLV из компонентов.Я еще не добавил аудио.

Для запуска этого кода вам понадобится FLVRecorder, найденный здесь: http://www.joristimmerman.be/wordpress/2008/12/18/flvrecorder-record-to-flv-using-air/

<?xml version="1.0" encoding="utf-8"?>

        import mx.core.UIComponent;
        import mx.events.FlexEvent;
        private var file:File;
        private var recorder:FLVRecorder=FLVRecorder.getInstance()
        private var fps:uint = 10;
        private var timer:Timer;
        protected function viewnavigator1_creationCompleteHandler(event:FlexEvent):void
        {

            //              2. Define the target FLV-file’s properties, the file instance to your flv-file, width & height, framerate and the systemManager instance, that’s a Flash internal declared variable and the optional duration in seconds:
            file=File.desktopDirectory.resolvePath("recording.flv");
            recorder.setTarget(file,320,320,fps,systemManager)

            var camera : Camera = Camera.getCamera();

            if (camera)
            {
                var ui      : UIComponent   = new UIComponent();
                var video   : Video     = new Video(320, 320);

                camera.setMode(320, 320, 24.);

                video.attachCamera(camera);
                ui.addChild(video);
                cameraGroup.addElement(ui);
            }

            timer = new Timer(1000/fps);
            timer.addEventListener(TimerEvent.TIMER, captureScreen);
            timer.addEventListener(TimerEvent.TIMER_COMPLETE, stopRecording);


        }

        protected function stopRecording(event:Event):void
        {
            timer.stop();
            //when saving is done
            recorder.addEventListener(FLVRecorderEvent.FLV_CREATED, fileMade)
            //when saving starts
            recorder.addEventListener(FLVRecorderEvent.FLV_START_CREATION, startCreatingFLV)

            // TODO Auto-generated method stub
            recorder.stopRecording()

        }

        private function startCreatingFLV(e:FLVRecorderEvent):void{
            recorder.addEventListener(FLVRecorderEvent.PROGRESS,onFLVCreationProgress)
        }

        private function onFLVCreationProgress(e:FLVRecorderEvent):void{
            //e.progress: percent complete (0 to 1)
            //pbSaving: ProgressBar component in Flex
            trace("saving progress ", e.progress,1);
        }

        protected function captureScreen(event:TimerEvent):void
        {
            trace("captured screen");
            recorder.captureComponent(movieGroup)     //DisplayObject, takes a screenshot from that component

        }

        protected function startRecording(event:MouseEvent):void
        {
            // TODO Auto-generated method stub
            timer.start();
        }

        protected function fileMade(event:Event):void
        {
            trace("file made");
        }

    ]]>
</fx:Script>
<s:VGroup>
    <s:HGroup>
        <s:Button label="start" click="startRecording(event)"/>
        <s:Button label="stop" click="stopRecording(event)"/>
        <s:Label id="progress" text="waiting..."/>
    </s:HGroup>
    <s:Group id="movieGroup" width="50%" height="50%">
        <s:Group id="cameraGroup" width="100%" height="100%"/>
        <s:Image source="image.png" width="25%" height="25%"/>
    </s:Group>
</s:VGroup>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...