大家论坛

 找回密码
 注册
查看: 2642|回复: 0

[讨论] FFmpeg move overlay from one pixel coordinate to another

[复制链接]

1295

主题

1308

帖子

1310

金币

大家网研究生四年级

Rank: 25Rank: 25Rank: 25Rank: 25Rank: 25

积分
5457
发表于 2018-8-5 16:25 | 显示全部楼层 |阅读模式

FFmpeg move overlay from one pixel coordinate to another


 Answers

Overlay Image on moving object in Video (Argumented Reality / OpenCv)

Based on overlay specification: https://ffmpeg.org/ffmpeg-filters.html#overlay-1

when you specify time interval it will happen only at that time interval:

For example, to enable a blur filter (smartblur) from 10 seconds to 3 minutes:

smartblur = enable='between(t,10,3*60)'

What you need to do is to overlay an image at specific coordinates, for example the following at fixed x and y:

ffmpeg -i rtsp://[host]:[port] -i x.png -filter_complex 'overlay=10:main_h-overlay_h-10' http://[host]:[post]/output.ogg

Now the idea is to calculate those coordinates based on the current frame of the video and force filter to use changed coordinates on every frame. For example based on time: FFmpeg move overlay from one pixel coordinate to another

ffmpeg -i bg.mp4 -i fg.mkv -filter_complex \
"[0:v][1:v]overlay=enable='between=(t,10,20)':x=720+t*28:y=t*10[out]" \
-map "[out]" output.mkv

Or using some other expressions: http://ffmpeg.org/ffmpeg-utils.html#Expression-Evaluation

Unfortunately this will require to find a formula before using those limited expressions of cat moving his head or drawing a pen for x and y. It can be linear, trigonometric or other dependency from time:

x=sin(t)

With the free move it is not always possible.

To be more precise of finding an object coordinates to overlay something it should be possible to provide your own filter(ffmpeg is open sourced) similar to overlay:https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/vf_overlay.c

Calculating x and y either based on external file(where you can dump all x and y for all times if it is a static video) or do some image processing to find specific region.

Hopefully it will give you an idea and direction to move to. It's very interesting feature.

 Question

I'm trying to write a command within FFmpeg that will first overlay one video stream on top of another one. Then I want the overlayed video to move from one pixel coordinate at a known time, and end at another pixel coordinate at a later time.

I'm comfortable with the basics of the -filter_complex, but I cannot figure out how to apply any arithmetic expressions - like the one's referenced here: https://www.ffmpeg.org/ffmpeg-utils.html#Expression-Evaluation

Here's an example of something I'd like to accomplish.

ffmpeg -i [INPUT1] -i [INPUT2] -filter_complex "[0:v][1:v]overlay=shortest=1:x=720:y=0:enable='between(t,10,20)'[overlay];...

In this example the overlay is stationary at pixel coordinate 720x0 from the 10th second to the 20th second.

However, Id like to have it move to a new location in a linear fashion and end at a different pixel coordinate.

For example, during that 10 second overlay, I'd like to have it start at 720x0, but then end at 1000x100.

Is this possible?

本人工科计算机专业程序媛一枚,感谢大家论坛并奉献本人收集的计算机资料,若本贴不能下载请回复,其他事由请点击这里
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则



诚聘英才|移动端|Archiver|版权声明|大家论坛 ( 京ICP备06071611号,京公网安备11010802018363号 )

GMT+8, 2020-4-2 07:28 , Processed in 0.077831 second(s), 10 queries , Redis On.

Powered by Discuz!

© Comsenz Inc.

快速回复 返回顶部 返回列表