0

I have three clips I have extracted from a longer video. When I concatenate them together everything works fine, as would be expected since they all came from the same source.

Now I want to add a title card to the front of the merged video.

I generated an image in GIMP with the same dimensions as the video frames and then used ffmpeg to generate a 5 sec. video from it. When I concatenated it onto the front of the other three I run into problems.

The title card segment plays correctly and then the remaining segments are (both video and audio) in slow-mo. Also the titlecard runs longer than 5 sec and the main segment audio starts before the corresponding video.

I know the problem is with the generation of the title card clip but so far I can't figure out what I am missing. Obviously my bitrates are wrong but how do I get them to match up?

what I have so far:

my generation script:

#!/bin/bash

ffmpeg -y -ss 0:03:33 -t 0:0:33.5 -i seg1.vob -filter:a "volume=4" seg1.mp4
ffmpeg -y -ss 0:13:25.5 -t 0:0:57 -i seg1.vob -filter:a "volume=4" seg2.mp4
ffmpeg -y -ss 0:16:25.5 -t 0:0:43 -i seg1.vob -filter:a "volume=4" seg3.mp4
ffmpeg -y -ss 0:7:10 -t 0:0:10 -i seg1.vob -filter:a "volume=4" -vn -b:a 394k title.mp3
ffmpeg -y -loop 1 -i title.png -t 0:0:5 -i title.mp3 -c:a aac -b:a 394k -shortest title.mp4 
ffmpeg -y -f concat -safe 0 -i contents.txt -c copy merged.mp4 

and contents.txt:

file 'title.mp4'
file 'seg1.mp4'
file 'seg2.mp4'
file 'seg3.mp4'

ffprobe on seg1.mp4:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'seg1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.20.100
  Duration: 00:00:33.52, start: 0.000000, bitrate: 677 kb/s
    Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 720x480 [SAR 32:27 DAR 16:9], 275 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 30k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 6 channels, fltp, 394 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

and for title.mp4:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'title.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.20.100
  Duration: 00:00:05.02, start: 0.000000, bitrate: 1290 kb/s
    Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 720x480 [SAR 191:194 DAR 573:388], 898 kb/s, 25 fps, 25 tbr, 12800 tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 389 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

1 Answers1

0

All inputs must have the same attributes to be properly concatenated.

Yours vary in frame rate, timebase, SAR/DAR, and audio channel layout.

Because you are filtering and re-encode each segment anyway you can do this all in one command:

ffmpeg -loop 1 -t 5 -framerate 30000/1001 -i title.png -ss 0:7:10 -t 0:0:10 -i seg1.vob -ss 0:03:33 -t 0:0:33.5 -i seg1.vob -ss 0:13:25.5 -t 0:0:57 -i seg1.vob -ss 0:16:25.5 -t 0:0:43 -i seg1.vob -filter_complex "[0:v]setsar=32/27[title];[title][1:a][2:v][2:a][3:v][3:a][4:v][4:a]concat=n=4:v=1:a=1[v][aud];[aud]volume=4[a]" -map "[v]" -map "[a]" output.mp4
llogan
  • 121,796
  • 28
  • 232
  • 243