Blaze John
Blaze John

Reputation: 11

Video Concatenating in FFMPEG

I am trying to concatenate a couple of video files with ffmpeg for this i use

.././ffmpeg -i 01.mov -i op_IMG_20150221114715.mp4 -i 02.mov -i op_IMG_20150221114724.mp4 -i op_IMG_20150221114736.mp4 -strict -2 -filter_complex '[0:0] setsar=1/1[sarfix];[sarfix] [0:1] [1:0] [1:1] [2:0] [2:1] [3:0] [3:1] [4:0] [4:1] concat=n=5:v=1:a=1 [v] [a]' -map "[v]" -map "[a]" output.mp4

and it outputs this error

ffmpeg version 2.5.4 Copyright (c) 2000-2015 the FFmpeg developers
built on Feb 16 2015 16:20:23 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
configuration: --prefix=/Volumes/Ramdisk/sw --enable-gpl --enable-pthreads   --enable-version3 --enable-libspeex --enable-libvpx --disable-decoder=libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-avfilter --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-filters --enable-libgsm --enable-libvidstab --enable-libx265 --arch=x86_64 --enable-runtime-cpudetect
libavutil      54. 15.100 / 54. 15.100
libavcodec     56. 13.100 / 56. 13.100
libavformat    56. 15.102 / 56. 15.102
libavdevice    56.  3.100 / 56.  3.100
libavfilter     5.  2.103 /  5.  2.103
libswscale      3.  1.101 /  3.  1.101
libswresample   1.  1.100 /  1.  1.100
libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '01.mov':
Metadata:
major_brand     : qt  
minor_version   : 537199360
compatible_brands: qt  
creation_time   : 2015-02-13 11:31:41
xmp             : 
  Duration: 00:00:02.17, start: 0.000000, bitrate: 558 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 480x480, 402 kb/s, SAR 480:480 DAR 1:1, 24 fps, 24 tbr, 24 tbn, 48 tbc (default)
Metadata:
  creation_time   : 2015-02-13 11:31:41
  handler_name    : Apple Alias Data Handler
  encoder         : H.264
  timecode        : 00:00:00:00
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 68 kb/s (default)
Metadata:
  creation_time   : 2015-02-13 11:31:41
  handler_name    : Apple Alias Data Handler
  timecode        : 00:00:00:00
Stream #0:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
Metadata:
  creation_time   : 2015-02-13 11:31:43
  handler_name    : Apple Alias Data Handler
  timecode        : 00:00:00:00
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'op_IMG_20150221114715.mp4':
Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
encoder         : Lavf56.4.101
Duration: 00:00:04.07, start: 0.023220, bitrate: 539 kb/s
Stream #1:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x480 [SAR 1:1 DAR 1:1], 427 kb/s, 29.92 fps, 29.92 tbr, 11488 tbn, 59.83 tbc (default)
Metadata:
  rotate          : 90
  handler_name    : VideoHandler
Side data:
  displaymatrix: rotation of -90.00 degrees
Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 120 kb/s (default)
Metadata:
  handler_name    : SoundHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '02.mov':
Metadata:
   major_brand     : qt  
minor_version   : 537199360
compatible_brands: qt  
creation_time   : 2015-02-13 11:32:12
xmp             : 
  Duration: 00:00:02.38, start: 0.000000, bitrate: 666 kb/s
Stream #2:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 480x480, 445 kb/s, SAR 480:480 DAR 1:1, 24 fps, 24 tbr, 24 tbn, 48 tbc (default)
Metadata:
  creation_time   : 2015-02-13 11:32:12
  handler_name    : Apple Alias Data Handler
  encoder         : H.264
  timecode        : 00:00:02:12
Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 119 kb/s (default)
Metadata:
  creation_time   : 2015-02-13 11:32:12
  handler_name    : Apple Alias Data Handler
  timecode        : 00:00:02:12
Stream #2:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
Metadata:
  creation_time   : 2015-02-13 11:32:15
  handler_name    : Apple Alias Data Handler
  timecode        : 00:00:02:12

Input #3, mov,mp4,m4a,3gp,3g2,mj2, from 'op_IMG_20150221114724.mp4':
Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
encoder         : Lavf56.4.101
Duration: 00:00:02.07, start: 0.023220, bitrate: 549 kb/s
Stream #3:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x480 [SAR 1:1 DAR 1:1], 460 kb/s, 29.92 fps, 29.92 tbr, 11488 tbn, 59.83 tbc (default)
Metadata:
  rotate          : 90
  handler_name    : VideoHandler
Side data:
  displaymatrix: rotation of -90.00 degrees
Stream #3:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 111 kb/s (default)
Metadata:
  handler_name    : SoundHandler
Input #4, mov,mp4,m4a,3gp,3g2,mj2, from 'op_IMG_20150221114736.mp4':
Metadata:
major_brand     : isom
minor_version   : 512
compatible_brands: isomiso2avc1mp41
encoder         : Lavf56.4.101
Duration: 00:00:01.07, start: 0.023220, bitrate: 392 kb/s
Stream #4:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x480    [SAR 1:1 DAR 1:1], 334 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
  rotate          : 90
  handler_name    : VideoHandler
Side data:
  displaymatrix: rotation of -90.00 degrees
Stream #4:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 93 kb/s (default)
Metadata:
  handler_name    : SoundHandler
File 'output.mp4' already exists. Overwrite ? [y/N] y
[Parsed_concat_1 @ 0x7f922bc1cec0] Input link in2:v0 parameters (size 480x480, SAR 480:480) do not match the corresponding output link in0:v0 parameters (480x480, SAR 1:1)
[Parsed_concat_1 @ 0x7f922bc1cec0] Failed to configure output pad on   Parsed_concat_1

The issue seems like I need to apply sarfix on input files 02.mov also. But I dont know the syntax for that.

Upvotes: 0

Views: 578

Answers (1)

llogan
llogan

Reputation: 133703

Why some things must be set by the user

From the 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.

More for the same docs:

For this filter to work correctly, all segments must start at timestamp 0.

All of your inputs share the same parameters except for SAR (Sample [aka Pixel] Aspect Ratio) and frame rate. It is also always good practice to set the timestamps of all inputs to 0 (even if they already are at 0 it won't hurt to do so).

What you must do

  1. Set timestamps to 0. The setpts filter will be used.

  2. Two inputs have a SAR of 480:480, while the others has a SAR of 1:1. I'm not sure why they are set as 480:480 instead of 1:1. They all must either be 480:480 or 1:1. You can try both and see what looks best. The setsar filter will be used.

  3. Two inputs have a frame rate of 24, one is 29.92, and one is 30. They all must have the same value, so the fps filter will be used.

Filtergraph syntax

A filtergraph is your complete filtering command. A filtergraph consists of filterchains. Filterchains consist of groups of filters connected via commas. Filterchains are connected via semicolons. The inputs and outputs of filterchains and filtergraphs can be named so they can be referenced by other filters or filterchains.

Basic filtergraph example

-filter_complex \
"[0:v]filter0,filter1,filter2[fc0]; \
 [1:v]filter3,filter4,filter5[fc1]; \
 [fc0][fc1]filter5[out]"
  • [0:v] refers to the video from the first input file.
  • [fc0] refers to the output from the first filterchain.

Actual filtergraph example

-filter_complex \
"[0:v]setsar=1/1,setpts=PTS-STARTPTS[v0]; \
 [1:v]fps=24,setpts=PTS-STARTPTS[v1]; \
 [2:v]setsar=1/1,setpts=PTS-STARTPTS[v2]; \
 [3:v]fps=24,setpts=PTS-STARTPTS[v3]; \
 [4:v]fps=24,setpts=PTS-STARTPTS[v4]; \
 [v0][0:a][v1][1:a][v2][2:a][v3][3:a][v4][4:a]concat=n=5:v=1:a=1[v][a]"

Upvotes: 1

Related Questions