如何使用 ffmpeg 在视频上按秒叠加多幅图像

如何使用 ffmpeg 在视频上按秒叠加多幅图像

我在视频上叠加图像,我浏览了很多链接,但没有得到我想要的结果,

我有多个图像名称框架0.jpg 框架1.jpg 框架2.jpg等等

所以我尝试用这个命令

String[] complexCommand = {"-y", "-i", videoPath, "-i", dir.getAbsolutePath() + "/"
 + filePrefix + "1" + fileExtn ,"-filter_complex", "[1][0]scale2ref[i][m];[m][i]overlay[v]" ,
"-map", "[v]", "-map",  "0:a?", "-ac", "2", dir.getAbsolutePath() + "/out.mp4"};



ffmpeg -y -i /storage/emulated/0/DCIM/Camera/VID_20171211_105946.3gp -i 
/storage/emulated/0/Pictures/Video/frame1.jpg -filter_complex 
[1][0]scale2ref[i][m];[m][i]overlay[v] -map [v] -map 0:a? -ac 2 
/storage/emulated/0/Pictures/Video/out.mp4 

输出:成功在视频上叠加单幅图像

我需要在视频上每秒叠加图像,我的图像序列是 frame1.jpg、frame2.jpg 等等

尝试输出是视频中每秒添加的新帧。

例子 :

第二个1:frame1.jpg

第二个2:frame2.jpg

第二个3:frame3.jpg

第二个4:frame4.jpg

Error Logs:
Metadata:
     major_brand     : 3gp4
     minor_version   : 0
     compatible_brands: isom3gp4
     creation_time   : 2017-12-11 05:29:46
     com.android.version: 6.0
     Duration: 00:00:02.60, start: 0.000000, bitrate: 17382 kb/s
     Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 17378 kb/s, SAR 1:1 DAR 16:9, 30.01 fps, 30.01 tbr, 90k tbn, 180k tbc (default)
                                                                                                               Metadata:
       rotate          : 90
       creation_time   : 2017-12-11 05:29:46
       handler_name    : VideoHandle
       Side data:
       displaymatrix: rotation of -90.00 degrees
 [mjpeg @ 0xf5b03800] bits 95 is invalid
 [mjpeg @ 0xf5b03800] bits 200 is invalid
 [mjpeg @ 0xf5b03800] Changing bps to 6
 [mjpeg @ 0xf5b03800] [IMGUTILS @ 0xff9086a0] Picture size 7168x52505 is invalid
 [image2 @ 0xf5b23600] decoding for stream 0 failed
 [image2 @ 0xf5b23600] Could not find codec parameters for stream 0 (Video: mjpeg, none(bt470bg/unknown/unknown)): unspecified size
 Consider increasing the value for the 'analyzeduration' and 'probesize' options
 /storage/emulated/0/Pictures/Video/frame%d.jpg: could not find codec parameters
 Input #1, image2, from '/storage/emulated/0/Pictures/Video/frame%d.jpg':
   Duration: 00:00:03.00, start: 0.000000, bitrate: N/A
     Stream #1:0: Video: mjpeg, none(bt470bg/unknown/unknown), 1 fps, 1 tbr, 1 tbn, 1 tbc
 [buffer @ 0xf5a7a000] Unable to parse option value "0x0" as image size
 [buffer @ 0xf5a7a000] Unable to parse option value "-1" as pixel format
 [buffer @ 0xf5a7a000] Unable to parse option value "0x0" as image size
 [buffer @ 0xf5a7a000] Error setting option video_size to value 0x0.
 [graph 0 input from stream 1:0 @ 0xf5b17460] Error applying options to the filter.
 Error configuring complex filters.
                                                                                                           Invalid argument
12-12 12:21:09.298 22264-22264/com.package E/background: Finished command : ffmpeg 

这是创建的文件

/storage/emulated/0/Pictures/Video/frame1.jpg
/storage/emulated/0/Pictures/Video/frame2.jpg
/storage/emulated/0/Pictures/Video/frame3.jpg

答案1

如果你的图像被命名为序列,你可以使用

ffmpeg -y -i /storage/emulated/0/DCIM/Camera/VID_20171211_105946.3gp -framerate 1 -i 
/storage/emulated/0/Pictures/Video/frame%d.jpg -filter_complex 
[1][0]scale2ref[i][m];[i]fps=25[i];[m][i]overlay[v] -map [v] -map 0:a? -ac 2 
/storage/emulated/0/Pictures/Video/out.mp4 

相关内容