我试图在一个视频上加水印,但FFmpeg命令不会执行,错误代码为3037.我运行相同的代码修剪视频和视频已成功修剪,因此session_destroy ()
没有问题或inputpath
我也在资产文件夹中有outputpath
。我尝试使用ic_watermark.png
中的图像,但错误代码相同。
所以这是我试图运行并在右上角加水印的命令:
Drawable
这是整个方法:
String[] cmd = new String[]{"-i", videoInputPath, "-i", imagePath, "-filter_complex", "overlay=main_w-overlay_w-5:main_h-overlay_h-5", videoOutPath };
我使用了一个基于private void executeFFmepg(String inputPath, String outputPath, String customCommand){
final Command command = videoKit.createCommand()
.overwriteOutput()
.inputPath(inputPath)
.outputPath(outputPath)
.customCommand(customCommand)
.experimentalFlag()
.build();
new AsyncCommandExecutor(command, this).execute();
}
的库:https://github.com/inFullMobile/videokit-ffmpeg-android
并且描述说这基本上是使用CLI参数调用FFmpeg main()。
这是我从FFmpeg
得到的:
Log
我尝试了类似问题的许多答案,但没有一个能奏效。
错误是否可能在引号中?
我没有FFmpeg的经验,所以任何帮助都会非常感激。感谢
答案 0 :(得分:0)
如果将来有人在视频上加水印时遇到问题,可以使用此方法。这可以使用Writingminds编译的FFmpeg库完成: http://writingminds.github.io/ffmpeg-android-java/
按照说明如何将FFmpeg
设置到您的项目中。之后,通过运行以下命令,我可以在视频上添加水印:
String commands[]={"-y","-i",videoInputPath,"-i", imagePath,"-filter_complex","[1:v]scale=200:200 [ovrl], [0:v][ovrl]overlay=main_w-overlay_w-5:main_h-overlay_h-5:enable='between(t,"+0+","+timeInSec+")'","-codec:a","copy","-strict","-2","-c:v","libx264","-preset","ultrafast",videoOutPath};
videoInputPath
-是视频的路径
imagePath
-是来自外部存储器的图像路径。我尝试使用Drawable
中的图片,但没有发现该图片有效(不是说不可能)
timeInSec
-是您可以从MediaMetadataRetriever
获得的视频长度:
File videoFile = new File(path);
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(this, Uri.fromFile(videoFile));
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long timeInMillisec = Long.parseLong(time );
timeInSec = (int) (timeInMillisec /1000);
videoOutPath
-放置水印后将保存视频的路径
上面的命令还将在200:200
上缩放水印,您可以根据需要进行调整并将其放在右下角。