Ffmpeg:移动滑块“图像”在“背景”从0%到100%与音频同步 [英] Ffmpeg: Move a slider "image" over a "background" from 0% to 100% in sync with the audio

查看:224
本文介绍了Ffmpeg:移动滑块“图像”在“背景”从0%到100%与音频同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码创建一个视频:

 `$`ffmpeg -loop 1 -r 5 -i video.png -r 5 -i progress.png -filter_complexoverlay = x ='if(gte(t,0),-W +(t)* 5,NAN)':y = Hh-i video。 mp3 -acodec copy video.mp4 

我有以下文件




  • video.png


    • 这是一个1280x720像素的静态帧,只是一个带有video.mp3文件波形的背景


  • progress.png

    • 这只是一个1280x100像素的半透明图像,它应该模拟一个动画(从0到100%的视频.png文件的宽度,以模拟填满动画。




我的问题如下:




  • Th e视频与音频不同步。进度条是离开的,而不是在歌曲结束时完成,它只是一直在继续下去...

  • 另外...它只是继续上下!我留下它创建一个1小时的视频,它从未停止。



我知道我在过滤器中缺少一些东西,但我有



有人可以帮我一些帮助吗?

解决方案

div>

正如Pranav所说,在流的末尾使用 -shortest 来排序持续时间问题。



现在要同步你的框架的进度,你必须弄清楚你的覆盖图片每秒需要移动多少。这很简单:您需要通过视频的宽度/视频的持续时间移动您的照片



例如,如果您有3分钟的歌曲和视频宽度为1280:




  • 3分钟= 3x60 = 180秒

  • 视频/视频的持续时间= 1280/180 = 7.11像素/秒。



7.11 -W +(t)* 5,中使用的值而不是 5 p>

我希望这个很清楚。


I'm trying to create a video using the follwing code:

`$`ffmpeg -loop 1 -r 5 -i video.png -r 5 -i progress.png -filter_complex "overlay=x='if(gte(t,0), -W+(t)*5, NAN)':y=H-h" -i video.mp3 -acodec copy video.mp4

I have the following files

  • video.png
    • this is a 1280x720 px still frame that is simply a background with a waveform of the video.mp3 file
  • progress.png
    • this is simply a 1280x100 px semi-transparent image that should simulate an animation (from from 0 to 100% of the width of the video.png file, in order to simulate "fill up" animation.

My issues are as following:

  • The video is not in sync with the audio. The progress bar is way off, instead of finishing at the end of the song, it just keeps going on and on and on and on...
  • Also... it just keeps going on and on! I left it create a 1 hour video and it never stopped.

I know I'm missing something in the filter, but I have no idea how I could fix it.

Could someone lend me some help?

解决方案

As Pranav said, use -shortest at the end of the stream to sort the duration issue.

Now to sync the progress of your frame you've got to figure out how much your overlayed picture needs to move per second. This is simple: you need to move your picture by "Width of your video / Duration of your video"

For instance if you've got a 3 minutes song and a video width of 1280:

  • 3 minutes = 3x60 = 180 seconds.
  • "Width of your video / Duration of your video" = 1280 / 180 = 7.11 pixels / second.

7.11 is the value to use instead of 5 in -W+(t)*5,.

I hope this is clear enough.

这篇关于Ffmpeg:移动滑块“图像”在“背景”从0%到100%与音频同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆