Moviepy: Moviepy is producing garbled videos

Created on 29 Nov 2016  路  7Comments  路  Source: Zulko/moviepy

I have recently upgraded from Mac OS El Capitan to Sierra and in the process to Python 3.5 from 2.7. Since making those changes moviepy produces garbled videos which can't be played.

I copied the painting_effect.py tutorial and that too produces a video which cannot play. The simplest approach I have tried is to load a video clip and to write it out. This still produces a garbled video on my system, however directly calling ffmpeg works fine.

Here's my Python script:

from moviepy.editor import *
import os

import tkinter.filedialog as filedialog
from tkinter import * 

root = Tk()
root.withdraw()
path = filedialog.askopenfilename()

desktop=os.path.join(os.path.expanduser('~'),"Desktop")

clip = VideoFileClip(path)
clip.write_videofile("test.mp4",write_logfile=True,verbose=False,ffmpeg_params=["-profile:v","baseline", "-level","3.0"])

And this is ffmpeg call that works correctly:
ffmpeg -i test.mov -profile:v baseline -level 3.0 test.mp4

Here's what pip lists as installed:

dask (0.12.0)
decorator (4.0.10)
imageio (1.6)
moviepy (0.2.2.11)
networkx (1.11)
numpy (1.11.2)
Pillow (3.4.2)
pip (9.0.1)
pyflakes (1.3.0)
pygame (1.9.2b6)
readline (6.2.4.1)
scikit-image (0.12.3)
scipy (0.18.1)
setuptools (28.8.0)
six (1.10.0)
tkinter (0.0.0)
toolz (0.8.0)
tqdm (4.10.0)
wheel (0.29.0)

Here's my ffmpeg configuration

ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-avresample --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libtheora --enable-libschroedinger --enable-libopenjpeg --enable-libmodplug --enable-libvpx --enable-libsoxr --enable-libspeex --enable-libass --enable-libbluray --enable-lzma --enable-gnutls --enable-fontconfig --enable-libfreetype --enable-libfribidi --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --disable-indev=jack --disable-outdev=xv --enable-audiotoolbox --enable-sdl2 --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/clang --enable-vda --enable-videotoolbox --arch=x86_64 --enable-yasm --enable-gpl --enable-postproc --enable-libx264 --enable-libxvid --enable-nonfree --enable-libfdk-aac

I am at a loss as to how to proceed. Could there be an issue with my version of numpy?

Most helpful comment

Sorry, it's been too long to recall. I believe it was something to do with the temporary audio file. The command I wound up using was:
file="movie.mp4" file_path=os.path.join(desktop,file) video.write_videofile(file_path, verbose=True, codec="libx264", audio_codec='aac', temp_audiofile='temp-audio.m4a', remove_temp=True, preset="medium", ffmpeg_params=["-profile:v","baseline", "-level","3.0","-pix_fmt", "yuv420p"])

See if the above works for you.

Edit: so I just ran the script and it worked fine. I load .mov files, edit them and write them out as .mp4 files as I needed them to run on Android and iOS.

All 7 comments

As a quick update, it appears the issue is not with the writing of video files, but with the loading. Using the preview function I was able to confirm that the issue is on load or how moviepy handles the data once loaded

We're having the same problem (using python 3.4), but only affects videos in portrait mode (e.g. landscape videos work fine). The video is grainy and replicated four times -- it playing the contents in portrait mode but the video has the landscape dimensions.

You're right. Are you using .mov files? I've noticed that .mov files extracted from my iPad in portrait mode produce garbled videos, but the .m4v files of the same videos exported through the Photos app are not affected.

None of the generated videos will play in Quicktime, but that seems to be a separate issue

Has there been any progress on this? I am using .mov files and having the exact same issue as @matthewng (portrait mode is producing garbled videos). Any ideas on how to fix this? @personalnadir if you translate your .mov files into .m4v do they end up working? Thanks for the help everyone!

Sorry, it's been too long to recall. I believe it was something to do with the temporary audio file. The command I wound up using was:
file="movie.mp4" file_path=os.path.join(desktop,file) video.write_videofile(file_path, verbose=True, codec="libx264", audio_codec='aac', temp_audiofile='temp-audio.m4a', remove_temp=True, preset="medium", ffmpeg_params=["-profile:v","baseline", "-level","3.0","-pix_fmt", "yuv420p"])

See if the above works for you.

Edit: so I just ran the script and it worked fine. I load .mov files, edit them and write them out as .mp4 files as I needed them to run on Android and iOS.

Thanks for the response! 馃憤

I did find a solution for this issue. Basically I had to strip the meta-data from the vertical videos in a sneaky way and now it works. In my script, before I start using the video, I do run this on it and then everything works perfectly:

os.system("ffmpeg -y -i {0} -vf \"transpose=1,transpose=2\" {1}".format(origional_video_path, stripped_of_meta_data_video_path))

Sounds like this was somewhat resolved.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wayn picture wayn  路  4Comments

bobozar picture bobozar  路  4Comments

Gicehajunior picture Gicehajunior  路  3Comments

Netherdrake picture Netherdrake  路  5Comments

Netherdrake picture Netherdrake  路  4Comments