"Ffmpeg basics" Chinese version - 9. cover: picture picture

9. covering: picture screen

Life, we often use the cover of video technology, such examples are many, such as the upper left corner on the TV screen, television logo always appears to indicate the current channel which provinces. Another example is in the main display window will be embedded in a small window used to display other images, such as video chat will often use this technique. This picture screens are very useful in many situations, such as to wait for a specific point in time or wait for the current video advertising in the past, you can put them in a small window, that both the current situation, You can also view other content main display window to avoid boredom.

In this section, only a simple example is included to cover, more complex example would be "color correction (Color Corrections)" "Advanced Technology (Advanced Techniques)" described in the section.

Note: The so-called complex example is actually a filter and other mixed use only.

Covering description

The so-called overlay technology, is a small video or picture displayed on large video or other images. We use the overlay filter cover to complete, a detailed description is as follows:
Here Insert Picture Description
Here Insert Picture Description

overlay command structure

The command line overlay filter structure is shown below, input1 background is input, input2 foreground is input:

ffmpeg -i input1 -i input2 -filter_complex overlay=x:y output

Note that due to the now must have two inputs (video or pictures), so we want to use when specifying filtergraphs -filter_complex options for multiple input without using -vf option. Of course, when the need has two inputs, we can use the movie filter, specified by its second input, so that we can use -vf option, this time to use the concept of filtergraphs and link label are:

ffmpeg -i input1 -vf movie=input2[logo];[in][logo]overlay=x:y output

The following command, we will enter a split into multiple outputs, then use the pad filter will fill one of the video to a larger size, it will serve as a background as an input in the overlay. This command has been introduced in the first chapter of "Filter, filterchains and filtergraphs" section, we will re-write it out:

ffplay -i i.mpg -vf split[a][b];[a]pad=2*iw[A];[b]hqdn3d[B];[A][B]overlay=w

Place the logo in the corner

​ 为了不阻挡视频的正式内容,logo一般会放在屏幕的任一角落中。接下来的四个例子,就是将 pair.mp4 作为输入的背景视频,然后将logo分别放在四个角落中。其中logo的尺寸为 150x140 ,我们不需要知道 pair.mp4的大小(只要远大于logo就行),我们可以使用 overlay 中提供的参数来完成对位置的指定:

Here Insert Picture Description

Here Insert Picture Description

Here Insert Picture Description

Here Insert Picture Description

在特定时刻显示logo

​ 有些情况下,我们可能需要在视频播放一段时间之后,再去显示一些内容。我们可以使用 -itsoffset 选型来指定显示的时间点。例如,我们在视频播放5秒之后,再去显示红色的logo:

ffmpeg -i video_with_timer.mp4 -itsoffset 5 -i logo.png -filter_complex overlay timer_with_logo.mp4

Here Insert Picture Description

​ 我们注意到,-itsoffset 是放在第二个输入之前的,如果位置不对,那么覆盖的效果可能会从视频一开始就执行。关于 -itsoffset 选型的更多示例可以在《时间操作(Time Opreations)》一节中查看。另一种延迟logo显示的方法是使用movie filter,它在《高级技术(Advanced Techniques)》一节中描述。

在视频中使用计时器

​ 我们在《视频裁剪(Cropping Video)》一节中,讲解了如何获得计时器。这一节讲述如何将获取到的计时器覆盖在其他的视频上。我们使用一个来自1973年阿波罗17卫星的视频来演示如何覆盖计时器,由于这个视频的长度是29.93秒,因此,我们先获取两个数字的计时器;

ffmpeg -f lavfi -i testsrc -vf crop:61:52:224:94 -t 30 timer.ogg

​ 这样我们就获得了一个小视频,尺寸为61x52,时长为30秒。我们将这个计时器视频放到视频的右上角,视频宽度为512,因此计时器的 x 坐标为 512 - 61 = 451, y 坐标为 0 ,命令如下:

ffmpeg -i start.mp4 -i timer.ogg -filter_complex overlay=451 start1.mp4

Here Insert Picture Description

​ 我们将计时器的尺寸缩小一半,并放置在视频正下方的中心处:

ffmpeg -i start.mp4 -vf movie=timer.ogg,scale=15:14[tm];[in][tm]overlay=248:371 overlay.mp4

Here Insert Picture Description

​ 现在,计时器就不显眼了。

其他overlay示例

列举了本书中其他覆盖操作示例的位置。

略。

H&A
Released seven original articles · won praise 4 · Views 824

Guess you like

Origin blog.csdn.net/qq_34305316/article/details/103935796