使用命令行工具连接 mp4 文件

Concat mp4 files with a command line tool

我无法尝试做某事,如果有人可以帮助我,我准备捐款:

我尝试在一个输出 mp4 文件中连接 http://s.serero.free.fr/rolex.mp4 video and http://s.serero.free.fr/video.mp4 视频,我尝试了很长时间但没有结果。

我想拼接http://s.serero.free.fr/rolex.mp4 + http://s.serero.free.fr/video.mp4http://s.serero.free.fr/video.mp4 + http://s.serero.free.fr/rolex.mp4.

我试过ffmpeg命令行软件和mp4box命令行软件,我觉得我没有好的方法。

我尝试转换 http://s.serero.free.fr/video.mp4 in the same format of http://s.serero.free.fr/rolex.mp4(反之亦然):

我改造了http://s.serero.free.fr/rolex.mp4 with the same frame rate of http://s.serero.free.fr/video.mp4

我改造了http://s.serero.free.fr/rolex.mp4 with the same video bitrate of http://s.serero.free.fr/video.mp4

我改造了http://s.serero.free.fr/rolex.mp4 with the same video audio bitrate of http://s.serero.free.fr/video.mp4

有人可以帮助我吗?

向我解释我的策略有什么问题?

你的输入参数不同,所以你必须在连接之前使它们相似。

  • rolex.mp4

    Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 835 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    
  • video.mp4

    Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1152x720, 1749 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, s16p, 127 kb/s (default)
    

此示例将使 video.mp4 更像 rolex.mp4 然后将它们连接起来:

ffmpeg -i rolex.mp4 -i video.mp4 -filter_complex \
"[1:v]pad=1280:720:(ow-iw)/2:0,fps=25,format=yuv420p[v1]; \
 [0:v][0:a][v1][1:a]concat=n=2:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" output.mp4

您实际上不需要声明 fpsformat 因为,正如 concat filter documentation 所述:

All corresponding streams must have the same parameters in all segments; the filtering system will automatically select a common pixel format for video streams, and a common sample format, sample rate and channel layout for audio streams, but other settings, such as resolution, must be converted explicitly by the user.

...但这样做将允许您手动选择 "common" 设置,而不是依赖过滤器自动这样做并可能选择您不想要的设置。

感谢 LordNeckbeard 的出色回答,他只是在命令上犯了一点错误,我只想做一点解释:

如果我想将 video.mp4(1152X720) 与 rolex.mp4(1280X720) 连接起来,我们必须了解 "video.mp4" 是主要的 视频所以视频(s) 连接必须具有 完全相同的帧大小

因此,在执行此操作之前,您需要使用 ffmpeg 将 rolex.mp4 视频调整为与 video.mp4 相同的大小:

ffmpeg -i rolex.mp4 -s 1152x720 -c:a copy newrolexsized.mp4

没有video.mp4和newrolexsized.mp4的帧大小相同,可以使用命令(spcifying pad=1152:720 => 主视频的大小):

ffmpeg -i video.mp4 -i newrolexsized.mp4 -filter_complex "[1:v]pad=1152:720:(ow-iw)/2:0,fps=25,format=yuv420p [v1];[0:v][0:a][v1][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -地图“[a]”out.mp4