我用 gopro 录制了一个视频,由于在大约 17 分钟后达到最大文件大小,所以视频被分成了 3 个部分,然后 gopro 会自动将其分成多个部分。我还有一个用 camstudio 录制的桌面。
我需要连接 3 个 gopro 视频,并将 camstudio 录制内容叠加为画中画视图。
即最终结果如下所示,其中 9 是覆盖图,1、2、3 是 gopro 视频
999999999999999
111111222222333
我必须定期执行此操作(以及多个视频),因此希望编写一个批处理文件来生成所需的输出,格式为 windows media player 可播放,无需下载编解码器。将文件大小最大减少到 1gb/45 分钟左右也很有用。
有人能建议在 FFmpeg 或 libav 中执行此操作的方法吗?我可以在 FFmpeg 中进行连接或叠加,但似乎无法同时完成这两项操作。也许我只需要先将连接执行到临时文件,然后将其用作叠加的输入?
目前,我正在使用 ffmpeg 中的以下 2 个命令来实现此目的,但文件大小很大,质量不佳,而且需要很长时间。目前输出大约为 1gb,持续 7 分钟,但我的视频最长可达 45 分钟,所以我真的需要将文件大小减少到 1-2gb 左右,持续 45 分钟
ffmpeg -i concat:1.mp4|2.mp4|3.mp4" -an -q:v 9 -preset veryslow -crf 28 -vcodec wmv2 temp.wmv
ffmpeg -i temp.wmv -an -vf"movie=overlay.avi, scale=iw:ih; [in][small] overlay =0:0 [out]" -q:v 9 -preset veryslow -crf 28 -vcodec wmv2 output.wmv
ffmpeg concat 的输出是:
>ffmpeg -i "concat:GOPR0133.mp4|GP010133.mp4|GP020133.mp4" -an -q:v 9 -vcodec wm
v2 70-70KMtemp.wmv
ffmpeg version N-61191-gea9399f Copyright (c) 2000-2014 the FFmpeg developers
built on Mar 8 2014 22:01:33 with gcc 4.8.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable
-zlib
libavutil 52. 66.101 / 52. 66.101
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 34.100 / 55. 34.100
libavdevice 55. 11.100 / 55. 11.100
libavfilter 4. 3.100 / 4. 3.100
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 027c29c0] Found duplicated MOOV Atom. Skipped it
Last message repeated 1 times
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'concat:GOPR0133.mp4|GP010133.mp4|GP0201
33.mp4':
Metadata:
creation_time : 2014-04-17 09:47:21
minor_version : 0
major_brand : avc1
compatible_brands: avc1isom
Duration: 00:17:24.30, start: 0.000000, bitrate: 71321 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709
), 1280x720 [SAR 1:1 DAR 16:9], 30002 kb/s, 100 fps, 100 tbr, 180k tbn, 200 tbc
(default)
Metadata:
creation_time : 2014-04-17 09:47:21
handler_name : GoPro AVC
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 12
8 kb/s (default)
Metadata:
creation_time : 2014-04-17 09:47:21
handler_name : GoPro AAC
[swscaler @ 036088a0] deprecated pixel format used, make sure you did set range
correctly
Output #0, asf, to '70-70KMtemp.wmv':
Metadata:
compatible_brands: avc1isom
minor_version : 0
major_brand : avc1
WM/EncodingSettings: Lavf55.34.100
Stream #0:0(eng): Video: wmv2 (WMV2 / 0x32564D57), yuv420p, 1280x720 [SAR 1:
1 DAR 16:9], q=2-31, 200 kb/s, 1k tbn, 100 tbc (default)
Metadata:
creation_time : 2014-04-17 09:47:21
handler_name : GoPro AVC
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> wmv2)
Press [q] to stop, [?] for help
frame= 6 fps=0.0 q=9.0 size= 60kB time=00:00:00.06 bitrate=8195.6kbits/s
frame= 15 fps= 14 q=9.0 size= 132kB time=00:00:00.15 bitrate=7203.6kbits/s
frame= 25 fps= 16 q=9.0 size= 207kB time=00:00:00.25 bitrate=6779.7kbits/s
frame= 33 fps= 16 q=9.0 size= 235kB time=00:00:00.33 bitrate=5834.4kbits/s
frame= 39 fps= 15 q=9.0 size= 294kB time=00:00:00.39 bitrate=6183.9kbits/s
frame= 47 fps= 15 q=9.0 Lsize= 326kB time=00:00:00.47 bitrate=5677.5kbits/
s
etc....
然后我在进行覆盖时得到的输出
>ffmpeg -i GOPR0131.mp4 -an -vf "movie=20140417_0930_55.avi, scale=iw:ih [small]
; [in][small] overlay =0:0 [out]" -q:v 9 -preset veryslow -crf 28 37-38KM.wmv
ffmpeg version N-61191-gea9399f Copyright (c) 2000-2014 the FFmpeg developers
built on Mar 8 2014 22:01:33 with gcc 4.8.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable
-zlib
libavutil 52. 66.101 / 52. 66.101
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 34.100 / 55. 34.100
libavdevice 55. 11.100 / 55. 11.100
libavfilter 4. 3.100 / 4. 3.100
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'GOPR0131.mp4':
Metadata:
major_brand : avc1
minor_version : 0
compatible_brands: avc1isom
creation_time : 2014-04-17 09:29:13
Duration: 00:11:59.29, start: 0.000000, bitrate: 30160 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709
), 1280x720 [SAR 1:1 DAR 16:9], 30005 kb/s, 100 fps, 100 tbr, 180k tbn, 200 tbc
(default)
Metadata:
creation_time : 2014-04-17 09:29:13
handler_name : GoPro AVC
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 12
8 kb/s (default)
Metadata:
creation_time : 2014-04-17 09:29:13
handler_name : GoPro AAC
Codec AVOption preset (Set the encoding preset (cf. x264 --fullhelp)) specified
for output file #0 (37-38KM.wmv) has not been used for any stream. The most like
ly reason is either wrong type (e.g. a video option with no video streams) or th
at it is a private option of some encoder which was not actually used for any st
ream.
Codec AVOption crf (Select the quality for constant quality mode) specified for
output file #0 (37-38KM.wmv) has not been used for any stream. The most likely r
eason is either wrong type (e.g. a video option with no video streams) or that i
t is a private option of some encoder which was not actually used for any stream
.
[swscaler @ 0401a560] deprecated pixel format used, make sure you did set range
correctly
Output #0, asf, to '37-38KM.wmv':
Metadata:
major_brand : avc1
minor_version : 0
compatible_brands: avc1isom
WM/EncodingSettings: Lavf55.34.100
Stream #0:0(eng): Video: msmpeg4v3 (msmpeg4) (MP43 / 0x3334504D), yuv420p, 1
280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 1k tbn, 100 tbc (default)
Metadata:
creation_time : 2014-04-17 09:29:13
handler_name : GoPro AVC
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> msmpeg4)
Press [q] to stop, [?] for help
frame= 6 fps=0.0 q=9.0 size= 23kB time=00:00:00.06 bitrate=3075.9kbits/s
frame= 16 fps= 15 q=9.0 size= 57kB time=00:00:00.16 bitrate=2913.4kbits/s
frame= 25 fps= 16 q=9.0 size= 91kB time=00:00:00.25 bitrate=2991.0kbits/s
frame= 32 fps= 15 q=9.0 Lsize= 113kB time=00:00:00.32 bitrate=2898.9kbits/
s
etc...
答案1
您可以使用setpts
,scale
,concat
,overlay
, 和format
过滤器。我假设所有输入都是 1280x720,因为您想要覆盖的文件的大小目前未知。
例子
ffmpeg -i gopro0.mp4 -i gopro1.mp4 -i gopro2.mp4 -i over.avi -filter_complex \
"[0:v]setpts=PTS-STARTPTS[v0]; \
[1:v]setpts=PTS-STARTPTS[v1]; \
[2:v]setpts=PTS-STARTPTS[v2]; \
[3:v]setpts=PTS-STARTPTS,scale=iw/4:-2[fg]; \
[v0][v1][v2]concat=n=3:v=1:a=1[bg][a]; \
[bg][fg]overlay=W-w-10:10,format=yuv420p[v]"
-map "[v]" -map "[a]" output.mp4
每个过滤器的作用
setpts
使时间戳从 0 开始,这是concat
和 所建议的overlay
。scale
会使over.avi
框架尺寸变小。concat
将连接每个输入。overlay
将把缩放后的图像放置over.avi
在右上角,填充 10 像素。请参阅overlay
文档有关具有不同持续时间的输入的附加选项(具体shortest
而言eof_action
)。format
将确保您的输出使用与所有播放器兼容的色度子采样方案(假设您使用的编码器libx264
是 MP4 的默认编码器(如果您的版本支持该ffmpeg
编码器))。
笔记
如果您希望输出具有较小的帧尺寸,则添加另一个
scale
:[bg][fg]overlay=W-w-10:10,scale=640:-2,format=yuv420p[v]"
我现在无法测试这些示例,所以如果任何事情没有按预期进行,请发表评论,我将在周日查看,除非其他人提供额外的帮助。
Windows Media Center 支持的文件类型 (Windows 7)几乎毫无价值,因为它没有提供具体细节,所以您可能需要进行实验,或者其他更熟悉 Windows 7 的人可以编辑这个答案。