0

I'm getting started with FFMPEG to add a title video to a few dozen videos I have. What would be the proper command to do this?

Samay Lakhani
  • 35
  • 1
  • 4

1 Answers1

0

Use the concat demuxer

There are several methods to join/merge/concatenate one video to another. This method uses the concat demuxer in ffmpeg to join the title video to the main video. Although there are several steps, it has the advantage that it does not re-encode the video you are adding a title to. So the process is quick and the quality is preserved.


Example

See the attributes of the video you want to add a title video to. In this example it is named main.mp4. When making the title video you will need to ensure that it matches the attributes of the video you want to add a title to.

ffmpeg -i main.mp4
...
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 988 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)

Generate the title video. Make sure the title video matches the attributes of the main file so it can concatenate properly. This example uses the color and anullsrc source filters to make 5 seconds of black video and silent audio, and the drawtext filter to make text:

ffmpeg -f lavfi -i color=size=1280x720:rate=30000/1001:duration=5:color=black -f lavfi -i anullsrc=sample_rate=44100:channel_layout=stereo -vf "drawtext=text='your title':fontcolor=white:fontsize=48:x=(w-text_w)/2:y=(h-text_h)/2" -c:v libx264 -profile:v main -c:a aac -shortest title.mp4

Make a text file named input.txt. This will be used by the concat demuxer and lists the files that you want to concatenate.

file 'title.mp4'
file 'main.mp4'

Finally, concatenate the title video to the main video with the concat demuxer:

ffmpeg -f concat -i input.txt -c copy output.mp4

Batch mode

ffmpeg does not have a batch mode to automatically do this for a folder of videos. However, it can be done with shell scripting but that is a whole new topic that deserves its own question. See How do you convert an entire directory with ffmpeg? for some examples.

llogan
  • 87,794
  • 21
  • 166
  • 190
  • Thanks a lot. Okay, so I'm completely new to this so can you explain what main.mp4 and the input.txt as well? Thanks. – Samay Lakhani Apr 07 '20 at 22:08
  • @SamayLakhani `main.mp4` is just an example name for a single video that a title is to be added to. `input.txt` is a simple text file containing a list of files that should be concatenated together. In my example it will join `title.mp4` to `main.mp4`. – llogan Apr 07 '20 at 23:13