Sometimes it's useful to slow, or extend the introduction of a video. For example, suppose you're utilizing a slow video transition (like a fade out/in effect) but don't want to miss the beginning frames of the second video. By extracting the first frame of the video, elongating it to X seconds we can preserve the transition effect without losing video content.
Let's take a peek at how to accomplish this;
$ cat -n Makefile
1 all: postVideo.mp4
2
3 video.mp4: BigBuckBunny.mp4
4 ${SH} ffmpeg -i $< -codec copy -strict -2 -t 10 $@
5
6 image.jpg: video.mp4
7 ${SH} ffmpeg -i $< -vf "select=eq(n\,0)" -q:v 3 $@
8 ${SH} display $@
9
10 preVid.mp4: image.jpg
11 ${SH} ffmpeg -loop 1 -i $< -f lavfi -i aevalsrc=0 -t 3 $@
12
13 postVideo.mp4: preVid.mp4 video.mp4
14 # ${SH} ffmpeg -i preVid.mp4 -i video.mp4 -filter_complex "[0:v] [0:a] [1:v] [1:a] concat=n=2:v=1:a=1 [vv] [aa]" -map "[vv]" -map "[aa]" $@
15 ${SH} ffmpeg -i preVid.mp4 -i video.mp4 -filter_complex "[0:v] [0:a] [1:v] [1:a] concat=n=2:v=1:a=1 [vo] [ao]" -map "[vo]" -map "[ao]" $@
16
17 clean:
18 ${RM} *.jpg
19 ${SH} find . -name "*.mp4" -not -name "BigBuckBunny.mp4" -delete
The input video (video.mp4) is generated by grabbing the first 10 seconds of BigBuckBunny.mp4; refer lines 3-4
Then, the first frame of the input video (video.mp4) is extracted and saved as image.jpg (ref lines 6-8)
Then, a new introduction video clip is generated by converting the image into a video clip of X seconds; ref lines 10-11). Note, a null audio track is created to preserve the audio in the outgoing video.
Lastly, a new video is created by concatenating the intro clip with the original clip, the result as a video with extended first frame.
One other trick worth mentioning with this makefile, I frequently want a clean target to clobber any video files created along the way. However, you don't want to delete the original source file, this can be accomplished by utilizing a find+not condition; ref line 19. This proves useful for many projects.
And, just like that, you've got a video with an elongated intro.
No comments:
Post a Comment