2

I'm trying to join two video files together - I'm piping the commands through PHP exec() as these videos are selected by the user. I can get it working, in that it does output a video of the correct combined size, but it seems they're actually set on different tracks and it just plays the first input video.

Command is

ffmpeg -i temp/production/videos/title.66.avi -i temp/production/videos/66.1391426205.avi \
-filter_complex '[0:0] [1:0] concat=n=2:v=1[v]' -map '[v]' \
temp/production/videos/final.66.1391426205.mp4 2>&1

and the output is

ffmpeg version 2.1.3 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jan 30 2014 14:39:10 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-x11grab --enable-libvpx --enable-libmp3lame
  libavutil      52. 48.101 / 52. 48.101
  libavcodec     55. 39.101 / 55. 39.101
  libavformat    55. 19.104 / 55. 19.104
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 90.100 /  3. 90.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, avi, from 'temp/production/videos/title.66.avi':
  Metadata:
    encoder         : Lavf55.19.104
  Duration: 00:00:05.00, start: 0.000000, bitrate: 36 kb/s
    Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p, 640x640 [SAR 641:643 DAR 641:643], 25 fps, 25 tbr, 25 tbn, 50 tbc
Input #1, avi, from 'temp/production/videos/66.1391426268.avi':
  Metadata:
    encoder         : Lavf55.19.104
  Duration: 00:00:11.42, start: 0.000000, bitrate: 943 kb/s
    Stream #1:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 640x640 [SAR 1:1 DAR 1:1], 12 tbr, 12 tbn, 12 tbc
[Parsed_concat_0 @ 0x27771e0] Input link in1:v0 parameters (size 640x640, SAR 1:1) do not match the corresponding output link in0:v0 parameters (640x640, SAR 641:643)
[Parsed_concat_0 @ 0x27771e0] Failed to configure output pad on Parsed_concat_0
slhck
  • 235,242
Josh P
  • 121

1 Answers1

2

The error is caused by the two video streams not sharing the same dimensions – or pixel aspect ratio, to be precise. The first one defines a SAR (sample = pixel) of 641/643, so it's not a perfect square.

ffmpeg cannot automatically bring both to the same dimensions, as it cannot guess which one you want to scale down or up, or whose aspect ratio needs to be changed.

You could try force-setting aspect ratio:

ffmpeg -i temp/production/videos/title.66.avi -i temp/production/videos/66.1391426205.avi \
-filter_complex '[0:0] setsar=sar=1 [in1]; [1:0] setsar=sar=1 [in2]; [in1][in2] concat [v]' -map '[v]' \
temp/production/videos/final.66.1391426205.mp4 2>&1

Instead of doing that, it could make sense to bring both videos to the same dimensions before, using the scale filter. To do so, you'd just replace setsar=sar=1 with scale=640:640 or whatever the fixed size of the needed output is.

If you want the audio copied and concatenated over, add a second concat filter:

ffmpeg -i temp/production/videos/title.66.avi -i temp/production/videos/66.1391426205.avi \
-filter_complex '[0:v] setsar=sar=1 [in1]; [1:v] setsar=sar=1 [in2]; [in1][in2] concat [v]; [0:a][1:a] concat=v=0:a=1 [a]' -map '[v]' -map '[a]' \
temp/production/videos/final.66.1391426205.mp4 2>&1

If you have two videos that you would like to fit into a certain sized player, you can use this filter: Resizing videos with ffmpeg/avconv to fit into static sized player

slhck
  • 235,242