在FireMonkey(Delphi XE6)中似乎有TVideoCaptureDevice
,但在官方文档中,捕获过程最终在线:
if(VideoCamera){
//do something
}
如何在飞行中将视频录制为 mp4?尝试在谷歌上寻找,但没有找到任何答案......
最佳答案
请参阅以下 docwiki 以获得答案(某种程度上)。
当然这里的“捕获”一词是指获取视频输入并将其显示在显示器上。 “录制”意味着将帧连接在一起以制作电影文件。
下面的代码是由
的人友情提供给我的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 开发者,我很感激这个解决方案。
关于android - 从 Android 上的相机录制视频到 mp4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23837928/