1

I am trying to concat 2 mp4 files that were both created with ffmpeg however the resulting output file does not contain any audio, can someone please help?

Here's my current code:

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;

}

And this is the result returned from ffmpeg in case it helps:

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
slhck
  • 235,242

3 Answers3

1

I can only guess here as to what you're trying to achieve, but the immediate solution to your problem would be to use -c:a aac -strict experimental instead of -codec:a copy. Your .mpg files use the mp2 audio codec which is apparently not supported in an MP4 container.

But then again, there are quite a few things wrong here. By converting to .mpg without any additional options you're creating MPEG-1 video, which either results in horrible quality, or terribly huge files. Also, -sameq doesn't do what you expect it to do. Please forget that option. Lastly, the double conversion introduces quality loss.

First, update to a recent version of ffmpeg. Then, read the guide at How to concatenate (join, merge) media files, especially the part about the concat filter. There you could concatenate two files directly without needing intermediates.

slhck
  • 235,242
0

FFmpeg can use more than one input file to generate an output file. Maybe try the -concat option instead of using 'cat' to combine them.

documentation on that: http://trac.ffmpeg.org/wiki/How%20to%20concatenate%20(join,%20merge)%20media%20files

Also, version 2.1 is the latest release:

Nate
  • 191
-1

I upgraded to ffmpeg-3.0 following all instruction on following page.

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

compilation took 10 minutes and I got error for not able to open libavdevice.so.57 which I resolved from https://stackoverflow.com/questions/12901706/ffmpeg-error-in-linux. It worked fine. I could join multiple mp4 videos together using ffmpeg -f concat -i list.txt -c copy Final_Video.mp4

Amit
  • 109