1

I have two videos: a.mp4 and b.mp4. I want to scale a.mp4, trim first 10 seconds and last 10 seconds of b.mp4 then add subtitle to b.mp4 then merge two videos (a.mp4 after scaling and b.mp4 after trimming/hardsub) into one. This is my script:

ffmpeg -i a.mp4 -i b.mp4 -filter_complex
    '[0:v]scale=1280:720[in1];[1:v]trim=0:10,trim=110:120,ass=subtitle.ass[in2]; 
     [in1][in2] concat=n=2:v=1:a=1 [out]' 
    -map [out] -c:v libx264  output.mp4

(120 is the length in seconds of b.mp4)

but it gave me an error:

Media type mismatch between the 'Parsed_ass_2' filter output pad 0
(video) and the 'Parsed_concat_3' filter input pad 1 (audio)
[AVFilterGraph @ 0x406c3c0] Cannot create the link ass:0 -> concat:1
1

Use

ffmpeg -i a.mp4 -i b.mp4
   -filter_complex '[0:v]scale=1280:720,setsar=1[in1];
                    [1:v]ass=subtitle.ass,trim=10:110,setpts=PTS-STARTPTS,setsar=1[in2];
                    [1:a]atrim=10:110,asetpts=PTS-STARTPTS[1a];
                    [in1][0:a][in2][1a] concat=n=2:v=1:a=1 [v] [a]'
   -map [v] -map [a] -c:v libx264 output.mp4

Since you are concatting audio as well, the filter expects an audio stream paired with each video stream.

  • Thank for your help. I tried but got this error Input link in1:v0 parameters (size 1280x720, SAR 0:1) do not match the corresponding output link in0:v0 parameters (1280x720, SAR 4757:4800) . Failed to configure output pad on Parsed_concat_8 Do you know what's the problem? – Luvias Aug 10 '17 at 13:38
  • See edited cmd. – Gyan Aug 10 '17 at 13:56
  • Command runs without any error but the output video is similar to a.mp4 (but in 1280:720 resolution). It looks like concat is not working. – Luvias Aug 10 '17 at 14:26
  • I tried this command and it works great. ffmpeg -i a.mp4 -i b.mp4 -filter_complex '[0:v]scale=1280:720,setsar=1[in1]; [1:v]ass=subtitle.ass,trim=10:110,setpts=PTS-STARTPTS,setsar=1[in2]; [1:a]atrim=10:110,asetpts=PTS-STARTPTS[1a]; [in1][0:a][in2][1a] concat=n=2:v=1:a=1 [v] [a]' -map [v] -map [a] -c:v libx264 output.mp4 – Luvias Aug 10 '17 at 15:22
  • Oh yeah, trim takes the time range to be kept. I did not bother to examine that. – Gyan Aug 10 '17 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.