Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.49k stars 1.56k forks source link

IOError: MoviePy error. Failed to read duration of file #203

Closed NareshPrabhu closed 4 years ago

NareshPrabhu commented 9 years ago

I'm using RapberryPi and downloaded MoviePy. Wrote a small sample code (sample.py) below

# !/usr/bin/env python

from moviepy.editor import *
video = VideoFileClip("sampleVideo.mp4")

Is there any issue with my installation? Getting below error. ffmpeg installation was fine.

pi@raspberrypi ~/pyv $ python sample.py
/home/pi/.imageio/ffmpeg/ffmpeg.linux32: 1: /home/pi/.imageio/ffmpeg/ffmpeg.linux32: Syntax error: "(" unexpected

Traceback (most recent call last):
  File "sample.py", line 3, in <module>
    video = VideoFileClip("sampleVideo.mp4")
  File "/usr/local/lib/python2.7/dist-packages/moviepy/video/io/VideoFileClip.py", line 55, in **init**
    reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt)
  File "/usr/local/lib/python2.7/dist-packages/moviepy/video/io/ffmpeg_reader.py", line 32, in **init**
    infos = ffmpeg_parse_infos(filename, print_infos, check_duration)
  File "/usr/local/lib/python2.7/dist-packages/moviepy/video/io/ffmpeg_reader.py", line 270, in ffmpeg_parse_infos
    filename, infos))
IOError: MoviePy error: failed to read the duration of file sampleVideo.mp4.
Here are the file infos returned by ffmpeg:

/home/pi/.imageio/ffmpeg/ffmpeg.linux32: 1: /home/pi/.imageio/ffmpeg/ffmpeg.linux32: Syntax error: "(" unexpected

Exception AttributeError: "VideoFileClip instance has no attribute 'reader'" in <bound method VideoFileClip.__del__ of <moviepy.video.io.VideoFileClip.VideoFileClip instance at 0xb6c74058>> ignored
GonzaloZiadi commented 7 years ago

Have this same issue. Referenced in #116

malcx95 commented 7 years ago

I got this error when trying to use MoviePy to edit video produced by the picamera library for recording from a Raspberry Pi. It produced a video in h.264 which didn't contain any duration information, which caused MoviePy and other video converters to crash. I was able to solve the problem using MP4Box to convert the video to mp4:

sudo apt-get install -y gpac
MP4Box -add video.h264 video.mp4

This created an mp4 file with the duration information so MoviePy could process it. I followed this guide: https://www.raspberrypi.org/documentation/usage/camera/raspicam/raspivid.md

tburrows13 commented 4 years ago

This is likely long out-of-date. If the problem reoccurs, please create a new issue.

wugoukanle commented 2 years ago

I use opencv to resave video:

def opencv_video_save_as(video_path, save_path):
    """
    video save as video
    :param video_path:
    :param save_path:
    :return:
    """
    input_movie = cv2.VideoCapture(video_path)
    width = int(input_movie.get(cv2.CAP_PROP_FRAME_WIDTH))
    height = int(input_movie.get(cv2.CAP_PROP_FRAME_HEIGHT))
    fps = input_movie.get(5)

    fourcc = cv2.VideoWriter_fourcc(*'MP4V')
    out = cv2.VideoWriter(save_path, fourcc, fps, (width, height))

    while (input_movie.isOpened()):
        ret, frame = input_movie.read()
        if (ret != True):
            break
        out.write(frame)
    out.release()