简体   繁体   中英

How to flip an mp4 video horizontally in python?

我已经在moviepy和ffmpeg中进行了研究,但是只能找到如何旋转视频,而不能水平翻转视频。

Since the question is tagged moviepy :

from moviepy.editor import VideoFileClip, vfx
clip = VideoFileClip('video.mp4')
reversed_clip = clip.fx(vfx.mirror_x)
reversed_clip.write_videofile('new_video.mp4')

See this page for a general list of predefined effects.

In ffmpeg, its easy to flip a video horizontally:

import ffmpeg
stream = ffmpeg.input('input.mp4')
stream = ffmpeg.hflip(stream)
stream = ffmpeg.output(stream, 'output.mp4')
ffmpeg.run(stream)

Reference: ffmpeg-python Github

Well, you haven't mentioned that you need to preserve the audio as well. But, if you want to preserve audio in your clip you can do the following. Note, I have used moviepy library.

from moviepy.editor import VideoFileClip, vfx
video = VideoFileClip('sample.mp4')
out = video.fx(vfx.mirror_x)
out.write_videofile('out.mp4')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM