从Android上的摄像头录制视频到mp4

在FireMonkey(Delphi XE6)中似乎有TVideoCaptureDevice,但在官方文档中,捕获过程最终在线:

if(VideoCamera){
  //do something
}

如何在飞行中将视频录制到mp4?试过看谷歌,但没有找到任何答案……

解决方法:

请参阅以下docwiki以获取答案(排序).

Delphi Video Capturing in XE7

当然,这里的“捕获”一词意味着,获取视频输入并将其放在显示器上. “录制”意味着将帧连接在一起以制作电影文件.

以下代码由人们提供给我

flashavconverter并在此处发布并获得批准:

uses
  Androidapi.JNI.GraphicsContentViewText;

const
  RECORD_VIDEO = 9;

implementation

uses 
  System.IOUtils,
  Androidapi.JNI.Provider,
  Androidapi.JNI.App,
  Androidapi.JNI.Net,
  Androidapi.JNIBridge,
  Androidapi.Helpers,
  Androidapi.JNI.JavaTypes,
  Androidapi.JNI.Os;

{$R *.fmx}

procedure TFormMain.btnRecordClick(Sender: TObject);
var
  VideoIntent: JIntent;
  videoUri: Jnet_Uri;
  AFile: JFile;
  FileName: TFileName;
begin
  FMessageSubscriptionID := 
    TMessageManager.DefaultManager.SubscribeToMessage(
      TMessageResultNotification, HandleActivityMessage);
  VideoIntent := 
    TJIntent.JavaClass.init(
      TJMediaStore.JavaClass.ACTION_VIDEO_CAPTURE
    );
  if (
    VideoIntent.resolveActivity(
      SharedActivityContext.getPackageManager()
    ) <> nil) then
  begin
    FileName := TPath.Combined(
      TPath.GetSharedDocumentsPath, 'recording.mp4')
    AFile:=TJFile.JavaClass.init(
      StringToJString(FileName));
    videoUri:=TJnet_Uri.JavaClass.fromFile(AFile);
    VideoIntent.putExtra(
      TJMediaStore.JavaClass.EXTRA_OUTPUT, 
      TJParcelable.Wrap((videoUri as ILocalObject).GetObjectID));
    SharedActivity.startActivityForResult(VideoIntent, RECORD_VIDEO);
  end;
end;

procedure TFormMain.HandleActivityMessage(const Sender: TObject;
  const M: TMessage);
begin
  if M is TMessageResultNotification then
    OnActivityResult(
      TMessageResultNotification(M).RequestCode,
      TMessageResultNotification(M).ResultCode,
      TMessageResultNotification(M).Value);
end;

function TFormMain.OnActivityResult(RequestCode, ResultCode: Integer;
  Data: JIntent): Boolean;
begin
  Result := False;

  TMessageManager.DefaultManager.Unsubscribe(
    TMessageResultNotification, FMessageSubscriptionID);
  FMessageSubscriptionID := 0;

  if RequestCode = RECORD_VIDEO then
  begin
    if ResultCode = TJActivity.JavaClass.RESULT_OK then
    begin
      TThread.Queue(nil, procedure
      begin
        lable1.Text:='recording completed';
        Invalidate;
      end);
    end;
  end;

结束;

此代码是(接近)完整的问题答案.启动特定于设备的视频记录器UI以供用户与之交互.除了保存录制文件的名称之外,没有编程控制.作为一个被Android API淹没的Delphi开发人员,我很感激这个解决方案.

上一篇:音视频基础1:H264、H265、MPEG-4、VP8、VP9编码基础知识


下一篇:MPEG DASH编码的基于frame的视频数据集下载