当前位置: 首页> 文旅> 旅游 > 上海外贸网站开发_个人简历怎么写_seo搜索优化服务_百度搜索引擎营销

上海外贸网站开发_个人简历怎么写_seo搜索优化服务_百度搜索引擎营销

时间:2025/7/11 0:24:39来源:https://blog.csdn.net/shelutai/article/details/142390577 浏览次数:0次
上海外贸网站开发_个人简历怎么写_seo搜索优化服务_百度搜索引擎营销

I’m currently working on a video editor and there is a feature where you can select a gif from Giphy and overlay it on top of your video after a header transition.

With FFmpeg you can manipulate, combine, add effects with filters. There is a filter called overlay - that we can use.

This did not work as I expected:
To apply a filter after a certain amount of time we’ll use the option enable (this option allows for timeline editing).

The below script overlays the gif.mp4 on top of main_video.mp4 during the 1 - 3 seconds duration.
ffmpeg -i main_video.mp4 -i gif.mp4 -filter_complex
“[0:v][1:v]overlay=enable=‘between(t,1,3)’[out]”
-map [out] complete.mp4
** [0:v] --> first video (main_video.mp4)
** [1:v] --> the second video (gif.mp4)
** [out] --> first and second video combined into one after the overlay.

Problem: gif.mp4 will start playing from the beginning so after 1 second has passed the gif video will be 1 second in already.

Solution:
Use the setpts filter to delay the overlay video (gif.mp4) start with x seconds.
ffmpeg -i main_video.mp4 -i gif.mp4 -filter_complex
“[1:v]setpts=PTS-STARTPTS+1/TB[delayedGif];
[0:v][delayedGif]overlay=enable=‘between(t,1,3)’[out]”
-map [out] complete.mp4
The setpts filter evaluates its expression and assigns the value as the timestamp for the current frame it is processing. For a detailed explanation check out this awesome post.

For setpts=PTS-STARTPTS+1/TB:
** +1 is the time in seconds we want to delay our offset
** TB is the timebase.

Too see the gif-overlay in action check out Glitterly - a web based video editor I’ve been working on.

import ffmpeg  # 输入文件  
main_video = 'main_video.mp4'  
gif_video = 'gif.mp4'  # 注意:这里假设gif.mp4是一个有效的视频文件,尽管其扩展名可能误导人认为是GIF图像  
output_video = 'complete.mp4'  # 创建ffmpeg流  
# 加载两个输入文件  
stream_main = ffmpeg.input(main_video)  
stream_gif = ffmpeg.input(gif_video)  # 应用filter_complex  
# 设置gif视频的时间戳,使其相对于自身起始点延迟  
# 注意:ffmpeg-python中不需要显式地指定流索引(如[1:v]),因为你可以直接通过ffmpeg.input()返回的流对象来引用  delayed_gif = ffmpeg.filter_(stream_gif.video, 'setpts', 'PTS-STARTPTS+1/TB')  # 将主视频和延迟后的gif视频进行叠加  
# 只在时间1秒到3秒之间启用overlay  overlay_filter = ffmpeg.filter_([stream_main.video, delayed_gif], 'overlay',  enable='between(t,1,3)',  x='(main_w-overlay_w)/2',  # 可选:居中gif  y='(main_h-overlay_h)/2')  # 可选:居中gif  # 创建输出流,仅包含处理后的视频  
output_stream = ffmpeg.output(overlay_filter, output_video)  # 运行ffmpeg命令  
ffmpeg.run(output_stream)
关键字:上海外贸网站开发_个人简历怎么写_seo搜索优化服务_百度搜索引擎营销

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: