4

I would like to add an image intro to a video for about 5 seconds but the time could be variable. I made a 5 seconds during intro.mkv with the following command:

ffmpeg -loop 1 -f image2 -i png.png -c:v libx264 -t 5 out.mp4

The problem is that cmd doesn't know the following command which is exactly what I need. This command is copy pasted from the FAQ of FFmpeg.

ffmpeg -i opening.mkv -i episode.mkv -i ending.mkv -filter_complex \ "[0:0] [0:1] [0:2] [1:0] [1:1] [1:2] [2:0] [2:1] [2:2] concat=n=3:v=1:a=2 [v] [a1] [a2]" \ -map '[v]' -map '[a1]' -map '[a2]' output.mkv

The error is: (2> output.txt isnt working for some reason)

enter image description here

2 Answers 2

6

This will overlay your png intro image over a 25 frames/second video for 5 seconds, followed by a 1-second fade into your video:

ffmpeg -itsoffset 5 -i in.mp4 -r 25 -loop 1 -i intro.png -filter_complex "[1:v] fade=out:125:25:alpha=1 [intro]; [0:v][intro] overlay [v]" -map "[v]" -map 0:a -acodec copy out.mp4

If your video is not 25 fps, change the -r value and the numbers after the fade (e.g. multiply by 30/25 if your video is 30 fps). To change the duration of the intro change the -itsoffset and the first number after the fade. If you want it show the image with audio from the beginning of the video (in place of the first few seconds of video) then you can reduce or eliminate the -itsoffset, which is the amount of time that it will shift the video forward to make room for the intro.

Of course you can use any supported video format for your input and output files, and can add any other video encoding parameters that you want to use before the output file name. If you need to re-encode the audio, change -acodec copy as needed, e.g. to -acodec libfdk_aac -vbr 3.

5
  • Will this overlay the first 5 seconds of the video instead of putting it in front of it? (which would be fine). How can this be adjusted to also add an outro? If I would like to add a waterwark to the rest of the video without the intro, is it possible to add an extra -filtercomplex to it or can I just play around with the inputs/outputs in filtercomplex to combine this?
    – Milanezi
    Jun 12, 2013 at 6:46
  • With the -itsoffset 5 it will put the intro in front and shift the video by 5 seconds, or remove that to overlay with no shifting. To add an outro you can add a 3rd input like the 2nd (-r + -loop + -i), and add more filters to alpha-fade it in at the desired frame (e.g. length of the video × frame rate) and overlay it. You can have as many filters as you like (e.g. fade in, watermark), separated by ;, within a single -filter_complex argument. See the documentation for complete details and some examples.
    – mark4o
    Jun 12, 2013 at 11:41
  • It seems that the general example of you is working. I've still got two problems though. One is: the intro has to overlay the complete videoframe. Any way on how to get the size of the frame of the video and this way match it? Second: adding an outro. I can manage the extra filters with watermark and outro except that the outro has to end the video ofcourse. And I have no idea on how to manage that with overlaying the video with the outro and not the other way around.
    – Milanezi
    Jul 11, 2013 at 16:25
  • You can use ffprobe to get the dimensions and duration first if you don't already know them. Insert scale=1280x720, before the intro fade-out if you want to scale the intro to those dimensions. If you want to fade to an outro I suggest overlaying the outro over the main video and fade it in, so that you won't need an alpha channel on your main video. Use the duration to compute the time of the fade and its -itsoffset. Or use the concat filter if you don't care about fading and just want a jump cut.
    – mark4o
    Jul 11, 2013 at 23:27
  • The output video are endless , how to make it work
    – Salem F
    Jul 15, 2020 at 19:35
0

First create your video file from your image; you want 5 seconds per image? that means 0.2 image per second:

ffmpeg -i intro.png -r 0.2 intro.mkv

Then you can mux it together with your main movie using ffmpeg (or mkvmerge if they're all Matroska).

3
  • It indeed makes a 5 seconds mkv file. But when I play it with VLC it immediatly stops playing. I tried with a jpeg and png file but both give the same error.
    – Milanezi
    Jun 11, 2013 at 14:14
  • You're right; this is probably a bad approach. ffmpeg.org/trac/ffmpeg/wiki/… with a different approach suggests encoding to h.264 and forcing the output FPS as well, but for me even mplayer in that case won't play the whole five seconds. Jun 11, 2013 at 14:36
  • ffmpeg -loop 1 -f image2 -i png.png -c:v libx264 -t 5 out.mp4 This seems to work though on the page you linked. Now I can use that created output and combine it with the main video using concate. But i'm confused how to put the made intro together with the concate function. I tried ffmpeg -loop 1 -f image2 -i png.png -c:v libx264 -t 5 [intro]. I think this saves it into the parameter [intro].
    – Milanezi
    Jun 11, 2013 at 14:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .