moviepy icon indicating copy to clipboard operation
moviepy copied to clipboard

Vertical MOV video to MP4

Open Duizhant opened this issue 1 year ago • 3 comments

To convert a vertical MOV video took by iPhone to MP4, first try the following code:

from moviepy.editor import VideoFileClip

def convert_mov_to_mp4(input_file, output_file): try: # Load the MOV file video_clip = VideoFileClip(input_file)

         # Write the video to the output MP4 file
         video_clip.write_videofile(output_file, codec='libx264', audio_codec='aac')

         print(f"Successfully converted {input_file} to {output_file}")
   except Exception as e:
        print(f"Error occurred: {e}")

but the original video is 1080(W)x1920(H) vertical video, the output video turns to be 1930(W)x1080(W), the video ratio is distorted.

Anyway to keep the output MP4 video in vertical with same ratio?

Duizhant avatar Jun 23 '24 20:06 Duizhant

Based on your function, it seems like you're not trying to change anything about the video. Consider looking at using ffmpeg (which you have installed already) if all you want to do is just convert the container from MOV to MP4. I've also heard good things about handbrake. This doesn't change anything about the video and maintains the size and quality.

Links for help: https://askubuntu.com/questions/396883/how-to-simply-convert-video-files-i-e-mkv-to-mp4 https://askubuntu.com/questions/50433/how-to-convert-mkv-file-into-mp4-file-losslessly https://superuser.com/questions/1155186/convert-mov-video-to-mp4-with-ffmpeg.

harroopsra avatar Jun 24 '24 04:06 harroopsra

I also got this issue too. Finally I chose FFMPEG command to address it instead of MoviePy.

Command: ffmpeg -an -i IMG_6859.MOV -stream_loop -1 -i res/audio/audio.wav -c:v copy -t 60 -y out.mp4

Here is my code : import subprocess

ffmpeg_command = [ 'ffmpeg', '-an', # 禁用音频输入 '-i', 'IMG_6859.MOV', # 输入视频文件 '-stream_loop', '-1', # 无限循环音频输入 '-i', 'res/audio/music.mp3', # 输入音频文件 '-c:v', 'copy', # 复制视频流,不进行重新编码 '-t', '60', # 设置输出时长为60秒 '-y', # 如果输出文件已存在,则覆盖它 'out.mp4' # 输出文件 ]

result = subprocess.run(ffmpeg_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)

if result.returncode != 0: print("Error executing command:") print(result.stderr) else: print("Command executed successfully.") # print(result.stdout)

zengqiang24 avatar Jun 30 '24 12:06 zengqiang24

It seems that your video has the rotate param but moviepy doesn't support it very well, I guess...:)

byscut avatar Jul 01 '24 02:07 byscut

Thank you for your contributions and for reporting issues in this repository. With the release of v2, which introduces significant changes to the codebase and API, we’ve reviewed the backlog of open PRs and issues. Due to the length of the backlog and the likelihood that many of these are either fixed or no longer applicable, we’ve made the decision to close all previous PRs and issues.

If you believe that any of these are still relevant to the current version or if you'd like to reopen a related discussion, please feel free to create a new issue or pull request, referencing the old one.

Thank you for your understanding and continued support!

OsaAjani avatar Jan 10 '25 21:01 OsaAjani