ffmpeg-python使用总结

ffmpeg是视频编解码处理工具,python接口的文档不完善,我也是边用边看,有问题的可以留言讨论。参考文档:

ffmpeg-python/examples at master · kkroening/ffmpeg-python · GitHub

(1)获取视频信息:

import ffmpeg
video1 = "012.mp4"
probe = ffmpeg.probe(video1)
video_info = next(s for s in probe['streams'] if s['codec_type'] == 'video'
width = int(video_info['width'])
height = int(video_info['height']) 

(2)视频拼接

video1 = "888.mp4"
video2 = "777.mp4"
v1 = ffmpeg.input(video1)
v2 = ffmpeg.input(video2)
(    ffmpeg.concat(v1,v2)
    .output('out.mp4')
    .run()
)

(3)视频叠加

(    ffmpeg.concat(v1,v2)
    .overlay(overlay_file.hflip(),x=int(width/2),y=int(height/2))##x,y为overlay在视频中的位置
    .output('out.mp4')
    .run()
)

猜你喜欢

转载自blog.csdn.net/SecretGirl/article/details/122491831