Tuesday, August 4, 2020

Video Transition Effects w/FFmpeg




Whether it be Instagram, Twitter, Snapchat, a vlog or YouTube, unless your uploading a uncut unedited video you're likely to incorporate some form of video transition(s). Scene changes, representing passage of time, representation of ambiguity can all be represented by common forms of video transitions. Investing a little effort in post production can transform a good video into a great one, a lengthy story into a shorter one and a long-winded story into a compelling quicker one.

FFMpeg can readily support some of the most common video transitions, and in this post we'll touch on some common transitions and how they can be done effectively with FFMpeg.

I hesitate referring to myself as an amateur videoographer, but over the years I've spent a good deal of time toying with videos. Recently, I've been researching the art/science to choosing the 'right' video transition, rather than simply arbitrarily choosing one from a hat. Recently I came upon this post which spends a bit of time explaining when/why to use particular video transitions. I'll touch on some of the key points and demonstrate simple examples on how to perform them with FFMpeg.

Fade

A fade-in consists of starting with a solid color (e.g. white, black) and smoothly morphing into the video shot.  Similarly, a fade-out smoothly morphs from the vido shot to a solid color.  Often, a fade-in and fade-out are coupled, fading out of the current scene followed by fading-in to the new scene.

This post focuses on providing overviews, more details for this form of transition can be found in this previous post.

Fade In

Often, a video will begin with a fade-in, much like most common movies.  This technique allows to slowly introduce the viewer into a new environment or scene.  Most often, fading in from black, which can be demonstrated by the following example;

Given a 24fps video, we can slowly fade in on the first 5 seconds like this:

$ ffmpeg -y -i video.mp4 -vf fade=in:0:120 -acodec copy fadeIn-5sec.mp4

The fade filter takes in frames, rather than time, so it requires knowledge of the video frame rate to convert time to frame range.

Fade Out

Fading out can signify the passing of time, a sense of completion, or represent ambiguity.  Let's look into an example.

Given a 24fps video, we can slowly fade out on the last 5 seconds of the video.  A 10 minute video at 24 fps (24*60*10 = 14400), 5 seconds (5*24=120) would be accomplished by the following;
$ ffmpeg -y -i video.mp4 -vf fade=out:14280:14400 -acodec copy fadeOut-5sec.mp4

Dissolve

Given two disjoint scenes, another common technique is to slowly transform directly from one scene into another.  This can represent the passage of time, bur more commonly represents moving from one location to another.  Consider an interview taking place in an office environment followed by continuing the interview in the street.  A rapid jump from office to street can be abrupt to the viewer, often remedied by dissolving from the first scene into the other.  Quick dissolves can represent a quick passage of time, while slower dissolves can represent the passage of months or years.

This effect is sometimes referred to as a crossfade, given two source videos we can dissolve or crossfade from the first to the second as follows:

$ ffmpeg -i image01.mp4 -i image02.mp4  -filter_complex "[0:v][1:v]blend=all_expr='A*(1-min(T/1,1))+B*(min(T/1,1))'" blend.mp4

A more comprehensive discussion with examples can be found here.



Wipes

Wipes can convey the existence of concurrent story lines, swapping one for another.  These can take on a variety of forms, left-to-right, right-to-left, upward, downward or any form of diagonals. 

An example of a wipe-right can take the form:
$ ffmpeg -i image01.mp4 -i image02.mp4 -filter_complex "[0:v][1:v]overlay=x='min(0,-W+(t/1)*W)':y=0[out]" -map "[out]" -y wipeRight.mp4

Like the fade-in, this filter doesn't use time, rather the units are pixels so authoring a 1 sec wipe will take some math, but if you're flexible in the wipe duration you can simply play with the filter arguments.

This past post describes a variety of wipes in more detail.

Zoom

Zooming in/out can communicate to the viewer 'pay attention to this', zooming in focuses the viewers attention to the subject of the zoom.  Zooming out can communicate attention from a particular subject out to the world at large, often done to represent an ending of the film....attention from a particular person out to the world a means of fading away from the subject.

Zooming is a bit more complicated than some of the other transitions, a simple example takes the form:
$ ffmpeg -y -i target.mp4 -vf "scale=iw*2.0:ih*2.0,zoompan=z='min(max(zoom,pzoom)+0.05,5.0)':d=1:x='560*2.0-(560*2.0/zoom)':y='400*2.0-(400*2.0/zoom)'" -an output.mp4

A more detailed explanation can be found here.



These are a few examples of common video transitions, I may spend some time on more sophisticated ones in the future. 

Now, go make your good videos great.

No comments:

Post a Comment