Record video from camera on Android to mp4

后端 未结 2 1365
醉酒成梦
醉酒成梦 2020-12-10 09:00

There seems to be TVideoCaptureDevice in FireMonkey (Delphi XE6), but on official documentation, capturing process ends up on lines:

if(VideoCam         


        
2条回答
  •  没有蜡笔的小新
    2020-12-10 09:20

    Here is how it is done on Android using native API:

    var
        texture : JSurfaceTexture;
        surface: JSurface;
        recorder: JMediaRecorder;
    begin
      texture := TJSurfaceTexture.JavaClass.init(1);
      surface := TJSurface.JavaClass.init(texture); 
      recorder := TJMediaRecorder.Create();
    
      recorder.setPreviewDisplay(surface);
      recorder.setAudioSource(AUDIO_MIC);
      recorder.setVideoSource(VIDEO_CAMERA);
      recorder.setOutputFormat(FORMAT_THREE_GPP);
      recorder.setAudioEncoder(AFORMAT_AMR_NB);
      recorder.setVideoEncoder(VFORMAT_MPEG_4_SP);
      recorder.setMaxDuration(1800000); // 30 minutes
    
      recorder.setVideoSize(320, 240);
      recorder.setVideoFrameRate(15);
      recorder.setOutputFile(StringToJString(TPath.GetSharedCameraPath + OUTPUT_FILE));
    
      recorder.prepare();
      recorder.start();
    end;
    

    File will be recorded, just don't forget to send recorder.stop() when you wish to stop recording.

提交回复
热议问题