使用 ffmpeg 创建的 Concat 2 .mp4 文件无法正常工作

使用 ffmpeg 创建的 Concat 2 .mp4 文件无法正常工作

我正在尝试连接两个用 ffmpeg 创建的 mp4 文件,但是生成的输出文件不包含任何音频,有人可以帮忙吗?

这是我当前的代码:

function appendVideo($input, $input_second, $outputfolder, $outputname) {
    // output
    $output = $outputfolder . $outputname;
    // intermediate
    $randomString1 = substr( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", mt_rand(0, 50) , 1) .substr( md5( time() ), 1);
    $randomString2 = substr( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", mt_rand(0, 50) , 1) .substr( md5( time() ), 1);
    $intermediate1 = $outputfolder . "i1_".$randomString1.".mpg";
    $intermediate2 = $outputfolder . "i2_".$randomString2.".mpg";
    //convert to mpg

    $exec1 = "ffmpeg -i $input -sameq $intermediate1 2>&1";
    $exec2 = "ffmpeg -i $input_second -sameq $intermediate2 2>&1";

    exec($exec1,$results1,$return1);
    exec($exec2,$results2,$return2);


    // join and convert back
    $exec = "cat $intermediate1 $intermediate2 | ffmpeg -i - -codec:a copy $output 2>&1";
    //delete the intermediate files


    exec ($exec,$results,$return);

        if (file_exists ( $intermediate1 )) {
        unlink ( $intermediate1 );
    }
    if (file_exists ( $intermediate2 )) {
        unlink ( $intermediate2 );
    }

    return $results;

}

这是 ffmpeg 返回的结果,希望它有帮助:

ffmpeg version 0.10.9 Copyright (c) 2000-2013 the FFmpeg developers
built on Oct 1 2013 19:47:54 with gcc 4.4.7 20120313 (Red Hat 4.4.7-3)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-gnutls --enable-libass --enable-libcdio --enable-libcelt --enable-libdc1394 --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopenjpeg --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libx264 --enable-libxvid --enable-x11grab --enable-avfilter --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
libavutil 51. 35.100 / 51. 35.100
libavcodec 53. 61.100 / 53. 61.100
libavformat 53. 32.100 / 53. 32.100
libavdevice 53. 4.100 / 53. 4.100
libavfilter 2. 61.100 / 2. 61.100
libswscale 2. 1.100 / 2. 1.100
libswresample 0. 6.100 / 0. 6.100
libpostproc 52. 0.100 / 52. 0.100
mpeg @ 0x111afc0] Estimating duration from bitrate, this may be inaccurate
nput #0, mpeg, from 'pipe:':
Duration: N/A, start: 1.000000, bitrate: 104985 kb/s
Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p, 768x432 [SAR 1:1 DAR 16:9], 104857 kb/s, 30 fps, 30 tbr, 90k tbn, 30 tbc
Stream #0:1[0x1c0]: Audio: mp2, 44100 Hz, stereo, s16, 128 kb/s
buffer @ 0x1137280] w:768 h:432 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
libx264 @ 0x11221e0] using SAR=1/1
libx264 @ 0x11221e0] using cpu capabilities: none!
libx264 @ 0x11221e0] profile High, level 3.0
libx264 @ 0x11221e0] 264 - core 120 r2151 a3f4407 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
utput #0, mp4, to 'tmp/zdee7489be42d6db4bfe9ce8e67da161.mp4':
Metadata:
encoder : Lavf53.32.100
Stream #0:0: Video: h264 (![0][0][0] / 0x0021), yuv420p, 768x432 [SAR 1:1 DAR 16:9], q=-1--1, 30 tbn, 30 tbc
Stream #0:1: Audio: mp2 (i[0][0][0] / 0x0069), 44100 Hz, stereo, 128 kb/s
Stream mapping:
    Stream #0:0 -> #0:0 (mpeg1video -> libx264)
    Stream #0:1 -> #0:1 (copy)
frame= 46 fps= 0 q=0.0 size= 0kB time=00:00:00.00 bitrate= 0.0kbits/s 
frame= 66 fps= 60 q=29.0 size= 135kB time=00:00:00.26 bitrate=4141.1kbits/s 
frame= 79 fps= 49 q=29.0 size= 257kB time=00:00:00.70 bitrate=3011.9kbits/s 
frame= 93 fps= 44 q=29.0 size= 386kB time=00:00:01.16 bitrate=2711.4kbits/s 
...
frame= 105 fps= 39 q=29.0 size= 487kideo:14440kB audio:3140kB global headers:0kB muxing overhead 1.021247%
[libx264 @ 0x11221e0] frame I:31 Avg QP:18.84 size: 42581
[libx264 @ 0x11221e0] frame P:3369 Avg QP:21.98 size: 3277
[libx264 @ 0x11221e0] frame B:2629 Avg QP:27.40 size: 923
[libx264 @ 0x11221e0] consecutive B-frames: 37.1% 14.2% 0.5% 48.2%
[libx264 @ 0x11221e0] mb I I16..4: 7.6% 68.7% 23.6%
[libx264 @ 0x11221e0] mb P I16..4: 0.6% 1.5% 0.2% P16..4: 20.9% 7.1% 5.3% 0.0% 0.0% skip:64.3%
[libx264 @ 0x11221e0] mb B I16..4: 0.1% 0.1% 0.0% B16..8: 17.2% 3.2% 1.0% direct: 0.7% skip:77.6% L0:39.4% L1:51.8% BI: 8.8%
[libx264 @ 0x11221e0] 8x8 transform intra:64.8% inter:69.2%
[libx264 @ 0x11221e0] coded y,uvDC,uvAC intra: 57.6% 72.7% 35.5% inter: 7.6% 11.8% 0.6%
[libx264 @ 0x11221e0] i16 v,h,dc,p: 41% 21% 16% 21%
[libx264 @ 0x11221e0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 21% 30% 5% 3% 3% 5% 4% 7%
[libx264 @ 0x11221e0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 23% 12% 4% 5% 5% 7% 6% 6%
[libx264 @ 0x11221e0] i8c dc,h,v,p: 44% 24% 25% 7%
[libx264 @ 0x11221e0] Weighted P-Frames: Y:0.7% UV:0.5%
[libx264 @ 0x11221e0] ref P L0: 69.8% 12.5% 10.8% 6.8% 0.0%
[libx264 @ 0x11221e0] ref B L0: 89.9% 8.5% 1.6%
[libx264 @ 0x11221e0] ref B L1: 97.2% 2.8%
[libx264 @ 0x11221e0] kb/s:588.6

答案1

我只能猜测您想要实现的目标,但问题的直接解决方案是使用-c:a aac -strict experimental而不是-codec:a copy。您的 .mpg 文件使用mp2MP4 容器显然不支持的音频编解码器。

但话说回来,这里有很多问题。通过转换.mpg而不使用任何附加选项,您将创建 MPEG-1 视频,这要么导致质量很差,要么导致文件非常大。此外,-sameq没有达到你的预期。请忘记该选项。最后,双重转换会导致质量损失。

首先,更新到最新版本ffmpeg。然后,阅读指南如何连接(结合、合并)媒体文件,尤其是有关过滤器的部分concat。在那里,您可以直接连接两个文件,而无需中间件。

答案2

FFmpeg 可以使用多个输入文件来生成输出文件。也许可以尝试使用 -concat 选项,而不是使用“cat”来合并它们。

关于此内容的文件: http://trac.ffmpeg.org/wiki/How%20to%20concatenate%20(加入,合并)%20media%20files

此外,最新版本是 2.1 版:

答案3

我按照以下页面的所有说明升级到 ffmpeg-3.0。

http://ask.xmodulo.com/compile-ffmpeg-centos-fedora-rhel.html

编译花了 10 分钟,我得到了无法打开 libavdevice.so.57 的错误,我解决了这个问题https://stackoverflow.com/questions/12901706/ffmpeg-error-in-linux。效果很好。我可以使用 ffmpeg -f concat -i list.txt -c copy Final_Video.mp4 将多个 mp4 视频合并在一起

相关内容