ffmpeg:组合/合并多个 mp4 视频不起作用,输出仅包含第一个视频 [英] ffmpeg: Combine/merge multiple mp4 videos not working, output only contains the first video

查看:83
本文介绍了ffmpeg:组合/合并多个 mp4 视频不起作用,输出仅包含第一个视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用来组合多个视频的命令:

ffmpeg -i 75_540_38HQ2.mp4 -i 76_70_20.mp4 -i 76_173_80.mp4 -i 81_186_35.mp4 -vcodec copy -acodec copy Mux1.mp4

生成的 Mux1.mp4 不包含所有视频.只有第一个视频 (75_540_38HQ2.mp4).源和生成的视频的文件大小如下(如您所见,生成的视频比第一个视频略大):

<前>$ ls -lh-rw-r--r-- 1 dbaker dbaker 42M 2011-03-24 11:59 75_540_38HQ2.mp4-rw-r--r-- 1 dbaker dbaker 236M 2011-03-24 12:09 76_173_80.mp4-rw-r--r-- 1 dbaker dbaker 26M 2011-03-24 12:05 76_70_20.mp4-rw-r--r-- 1 dbaker dbaker 54M 2011-03-24 12:15 81_186_35.mp4-rw-r--r-- 1 dbaker dbaker 44M 2011-03-24 14:48 Mux1.mp4

这是 ffmpeg 命令的输出.对我来说它看起来不错,显示了多个源输入和单个输出.

<前>FFmpeg 版本 SVN-r26402,版权所有 (c) 2000-2011 FFmpeg 开发人员建于 2011 年 3 月 21 日 18:05:32,使用 gcc 4.4.5配置:--enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grablibavutil 50.36.0/50.36.0libavcore 0.16.1/0.16.1libavcodec 52.108.0/52.108.0libav格式 52.93.0/52.93.0libavdevice 52. 2. 3/52. 2. 3库过滤器 1.74.0/1.74.0libswscale 0.12.0/0.12.0libpostproc 51. 2. 0/51. 2. 0输入 #0, mov,mp4,m4a,3gp,3g2,mj2,来自'75_540_38HQ2.mp4':元数据:主要品牌:isom次要版本:512兼容品牌:isomiso2avc1mp41创作时间:1970-01-01 00:00:00编码器:Lavf52.93.0持续时间:00:00:29.99,开始:0.000000,比特率:11517 kb/s流 #0.0(eng):视频:h264、yuv420p、1280x960 [PAR 1:1 DAR 4:3]、11575 kb/s、29.94 fps、29.97 tbr、30k tbn、59.94 tbc元数据:创作时间:1970-01-01 00:00:00流 #0.1(eng):音频:aac,48000 Hz,立体声,s16,127 kb/s元数据:创作时间:1970-01-01 00:00:00输入 #1, mov,mp4,m4a,3gp,3g2,mj2,来自'76_70_20.mp4':元数据:主要品牌:isom次要版本:512兼容品牌:isomiso2avc1mp41创作时间:1970-01-01 00:00:00编码器:Lavf52.93.0持续时间:00:00:19.98,开始:0.000000,比特率:10901 kb/s流 #1.0(eng):视频:h264、yuv420p、1280x960 [PAR 1:1 DAR 4:3]、10804 kb/s、29.97 fps、29.97 tbr、30k tbn、59.94 tbc元数据:创作时间:1970-01-01 00:00:00流 #1.1(eng):音频:aac,48000 Hz,立体声,s16,128 kb/s元数据:创作时间:1970-01-01 00:00:00输入 #2, mov,mp4,m4a,3gp,3g2,mj2,来自'76_173_80.mp4':元数据:主要品牌:isom次要版本:512兼容品牌:isomiso2avc1mp41创作时间:1970-01-01 00:00:00编码器:Lavf52.93.0持续时间:00:03:09.99,开始:0.000000,比特率:10393 kb/s流 #2.0(eng):视频:h264、yuv420p、1280x960 [PAR 1:1 DAR 4:3]、10321 kb/s、29.96 fps、29.97 tbr、30k tbn、59.94 tbc元数据:创作时间:1970-01-01 00:00:00流 #2.1(eng):音频:aac,48000 Hz,立体声,s16,128 kb/s元数据:创作时间:1970-01-01 00:00:00似乎流 0 编解码器帧速率与容器帧速率不同:119.88 (120000/1001) -> 30000.00 (30000/1)输入 #3, mov,mp4,m4a,3gp,3g2,mj2,来自'81_186_35.mp4':元数据:主要品牌:isom次要版本:512兼容品牌:isomiso2avc1mp41创作时间:1970-01-01 00:00:00编码器:Lavf52.93.0持续时间:00:00:35.00,开始:0.000000,比特率:12700 kb/s流 #3.0(eng):视频:h264、yuv420p、1280x720 [PAR 1:1 DAR 16:9]、12620 kb/s、59.91 fps、30k tbr、60k tbn、119.88 tbc元数据:创作时间:1970-01-01 00:00:00流 #3.1(eng):音频:aac,48000 Hz,立体声,s16,128 kb/s元数据:创作时间:1970-01-01 00:00:00输出 #0,mp4,到Mux1.mp4":元数据:主要品牌:isom次要版本:512兼容品牌:isomiso2avc1mp41创作时间:1970-01-01 00:00:00编码器:Lavf52.93.0流 #0.0(eng):视频:libx264、yuv420p、1280x960 [PAR 1:1 DAR 4:3]、q=2-31、11575 kb/s、30k tbn、29.97 tbc元数据:创作时间:1970-01-01 00:00:00流 #0.1(eng):音频:libfaac,48000 Hz,立体声,128 kb/s元数据:创作时间:1970-01-01 00:00:00流映射:流#0.0 -> #0.0流 #2.1 -> #0.1按 [q] 停止编码帧= 883 fps=632 q=-1.0 Lsize= 44730kB 时间=29.40 比特率=12465.1kbits/s视频:41678kB 音频:2969kB 全局标头:0kB 复用开销 0.184548%

我在这里做了一些非常愚蠢的事情吗?

源视频来自摄像机,是使用 ffmpeg -i bigfile.mp4 -ss 20 -t 10 -vcodec copy 等拍摄的小片段.

谢谢堆!!戴夫

<小时>

无法解决,所以我只使用 avidemux GUI 工具.它似乎附加 MP4 就好了.

一定是 MP4 的问题,或者只是 gopro 相机的问题.

解决方案

您必须将它们转换为可以轻松连接的 MPEG 格式.以下是我为 GoPro 视频使用并称为ffcat"的脚本.它本质上运行了几个ffmpeg -i"命令,这些命令生成可连接的 MPEG,然后通过管道传输到 ffmpeg 命令,然后将它们转换为 H.264 mp4 文件.

它还可以将视频大小调整为 720p,但您可能不希望那样.

h264options"是我最近在 Internet 上找到的标志 h264.code-shop.com

希望这有帮助,里德

<小时>

cmd="( "h264options="-vcodec libx264 -b 512k -flags +loop+mv4 -cmp 256 -分区+parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -me_method hex -subq 7 -trellis 1 -refs 5 -bf 3 -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10-qmax 51 -qdiff 4"outfile="out-`date +%F-%H%M.%S`.mp4"为我;做cmd="${cmd}ffmpeg -i $i -ab 256000 -vb 10000000 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 100 -f mpeg -;"完毕cmd="${cmd} ) | ffmpeg -y -i - -threads 8 ${h264options} -vb 10000000 -acodec libfaac -ar 44100 -ab 128k -s 1280x720 ${outfile}"回声${cmd}"评估 ${cmd}

Here is the command I am using to combine multiple videos:

ffmpeg -i 75_540_38HQ2.mp4 -i 76_70_20.mp4 -i 76_173_80.mp4 -i 81_186_35.mp4 -vcodec copy -acodec copy Mux1.mp4

The resulting Mux1.mp4 does not contain all videos. Only the first video (75_540_38HQ2.mp4). The file size of the source and resulting video is below (as you can see, resulting video is slightly larger than first vid):

$ ls -lh
-rw-r--r-- 1 dbaker dbaker  42M 2011-03-24 11:59 75_540_38HQ2.mp4
-rw-r--r-- 1 dbaker dbaker 236M 2011-03-24 12:09 76_173_80.mp4
-rw-r--r-- 1 dbaker dbaker  26M 2011-03-24 12:05 76_70_20.mp4
-rw-r--r-- 1 dbaker dbaker  54M 2011-03-24 12:15 81_186_35.mp4
-rw-r--r-- 1 dbaker dbaker  44M 2011-03-24 14:48 Mux1.mp4

Here is the output of the ffmpeg command. To me it looks ok, showing the multiple source inputs and the single output.

FFmpeg version SVN-r26402, Copyright (c) 2000-2011 the FFmpeg developers
  built on Mar 21 2011 18:05:32 with gcc 4.4.5
  configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grab
  libavutil     50.36. 0 / 50.36. 0
  libavcore      0.16. 1 /  0.16. 1
  libavcodec    52.108. 0 / 52.108. 0
  libavformat   52.93. 0 / 52.93. 0
  libavdevice   52. 2. 3 / 52. 2. 3
  libavfilter    1.74. 0 /  1.74. 0
  libswscale     0.12. 0 /  0.12. 0
  libpostproc   51. 2. 0 / 51. 2. 0
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '75_540_38HQ2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01 00:00:00
    encoder         : Lavf52.93.0
  Duration: 00:00:29.99, start: 0.000000, bitrate: 11517 kb/s
    Stream #0.0(eng): Video: h264, yuv420p, 1280x960 [PAR 1:1 DAR 4:3], 11575 kb/s, 29.94 fps, 29.97 tbr, 30k tbn, 59.94 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
    Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 127 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '76_70_20.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01 00:00:00
    encoder         : Lavf52.93.0
  Duration: 00:00:19.98, start: 0.000000, bitrate: 10901 kb/s
    Stream #1.0(eng): Video: h264, yuv420p, 1280x960 [PAR 1:1 DAR 4:3], 10804 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
    Stream #1.1(eng): Audio: aac, 48000 Hz, stereo, s16, 128 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '76_173_80.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01 00:00:00
    encoder         : Lavf52.93.0
  Duration: 00:03:09.99, start: 0.000000, bitrate: 10393 kb/s
    Stream #2.0(eng): Video: h264, yuv420p, 1280x960 [PAR 1:1 DAR 4:3], 10321 kb/s, 29.96 fps, 29.97 tbr, 30k tbn, 59.94 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
    Stream #2.1(eng): Audio: aac, 48000 Hz, stereo, s16, 128 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00

Seems stream 0 codec frame rate differs from container frame rate: 119.88 (120000/1001) -> 30000.00 (30000/1)
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '81_186_35.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01 00:00:00
    encoder         : Lavf52.93.0
  Duration: 00:00:35.00, start: 0.000000, bitrate: 12700 kb/s
    Stream #3.0(eng): Video: h264, yuv420p, 1280x720 [PAR 1:1 DAR 16:9], 12620 kb/s, 59.91 fps, 30k tbr, 60k tbn, 119.88 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
    Stream #3.1(eng): Audio: aac, 48000 Hz, stereo, s16, 128 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
Output #0, mp4, to 'Mux1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01 00:00:00
    encoder         : Lavf52.93.0
    Stream #0.0(eng): Video: libx264, yuv420p, 1280x960 [PAR 1:1 DAR 4:3], q=2-31, 11575 kb/s, 30k tbn, 29.97 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
    Stream #0.1(eng): Audio: libfaac, 48000 Hz, stereo, 128 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #2.1 -> #0.1
Press [q] to stop encoding
frame=  883 fps=632 q=-1.0 Lsize=   44730kB time=29.40 bitrate=12465.1kbits/s    
video:41678kB audio:2969kB global headers:0kB muxing overhead 0.184548%

Am I doing something blindingly stupid here?

The source videos came from a video camera, and are small snippets taken with ffmpeg -i bigfile.mp4 -ss 20 -t 10 -vcodec copy etc..

Thanks heaps!! Dave


Edit: couldn't solve it so I just use avidemux GUI tool. It seemed to append the MP4's just fine.

Must be a problem with MP4's or just the ones that come off a gopro camera.

解决方案

You have to convert them into an MPEG format that can be easily concatenated. Below is a script I use and call "ffcat" for my GoPro videos. It essentially runs several "ffmpeg -i" commands which produce concatenate-able MPEG, which is piped to an ffmpeg command that then converts them to an H.264 mp4 file.

It also sizes the videos to 720p but you may not want that.

The "h264options" are flags I recently found on the internet at h264.code-shop.com

Hope this helps, Reid


cmd="( "

h264options="-vcodec libx264 -b 512k -flags +loop+mv4 -cmp 256 
 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 
 -me_method hex -subq 7 -trellis 1 -refs 5 -bf 3 
 -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -coder 1 -me_range 16 
   -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10
 -qmax 51 -qdiff 4"

outfile="out-`date +%F-%H%M.%S`.mp4"

for i; do
    cmd="${cmd}ffmpeg -i $i -ab 256000 -vb 10000000 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 100 -f mpeg -; "
done
cmd="${cmd} ) | ffmpeg -y -i - -threads 8 ${h264options} -vb 10000000 -acodec libfaac -ar 44100 -ab 128k -s 1280x720 ${outfile}"
echo "${cmd}"
eval ${cmd}

这篇关于ffmpeg:组合/合并多个 mp4 视频不起作用,输出仅包含第一个视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆