moviepy
moviepy copied to clipboard
OSError: MoviePy error: failed to read the duration of file
Problem : Reading video in local and docker-compose file works fine but in minikube below issue occured
Expected Behavior
>>> from moviepy.editor import *
>>> clip=VideoFileClip("https://videorenderingbucket.s3.ap-south-1.amazonaws.com/video_file/Pranali_Shukan_Wedding_Invite.mp4_video_2023-06-19_10%3A25%3A13.685572.mp4")
>>> clip
<moviepy.video.io.VideoFileClip.VideoFileClip object at 0x7f175c97ac40>
Actual Behavior
From moviepy. Editor import *
clip=videofileclip("https: //videorenderingbucket. S3. Ap-south-1. Amazonaws. Com/video_file/the+breathtaking+beauty+of+nature+-+hd. Mp4")`
### Logs
traceback (most recent call last):
file "/usr/local/lib/python3.8/site-packages/moviepy/video/io/ffmpeg_reader. Py", line 285, in ffmpeg_parse_infos
line = [l for l in lines if keyword in l][index]
indexerror: list index out of range
during handling of the above exception, another exception occurred:
traceback (most recent call last):
file "<stdin>", line 1, in <module>
file "/usr/local/lib/python3.8/site-packages/moviepy/video/io/videofileclip. Py", line 88, in __init__
self. Reader = ffmpeg_videoreader(filename, pix_fmt=pix_fmt,
file "/usr/local/lib/python3.8/site-packages/moviepy/video/io/ffmpeg_reader. Py", line 35, in __init__
infos = ffmpeg_parse_infos(filename, print_infos, check_duration,
file "/usr/local/lib/python3.8/site-packages/moviepy/video/io/ffmpeg_reader. Py", line 289, in ffmpeg_parse_infos
raise ioerror(("moviepy error: failed to read the duration of file %s. \n"
oserror: moviepy error: failed to read the duration of file https: //videorenderingbucket. S3. Ap-south-1. Amazonaws. Com/video_file/the+breathtaking+beauty+of+nature+-+hd. Mp4.
Here are the file infos returned by ffmpeg:
ffmpeg version 4.2.2-static https: //johnvansickle. Com/ffmpeg/ copyright (c) 2000-2019 the ffmpeg developers
built with gcc 8 (debian 8.3.0-6)
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100`
Specifications
- Python Version: 3.8.10
- MoviePy Version:1.0.3
- Platform Name: Minikube
- Platform Version: v1.30.1
Requirement.txt
- aiofiles==23.1.0
- autopep8==2.0.2
- bcrypt==4.0.1
- boto3==1.26.144
- chill==0.9.0
- cloudpickle==2.2.1
- cryptography==41.0.1
- fastapi==0.95.0
- ffmpeg-python==0.2.0
- ffpyplayer==4.4.0
- flower==1.2.0
- httpx==0.23.3
- ipykernel==6.22.0
- moviepy==1.0.3
- mysql-connector-python==8.0.33
- opencv-python==4.7.0.72
- pandas==1.5.3
- pip-chill==1.0.1
- pyjwt==2.7.0
- pymysql==1.0.3
- python-decouple==3.8
- python-dotenv==1.0.0
- python-multipart==0.0.6
- rabbitmq==0.2.0
- redis==4.5.4
- sqlalchemy==2.0.12
- uvicorn==0.21.1
Closing this issue as it's missing information for reproducability, like useful code samples or properly formatted error logs. Please use code-formatted text for code and logs, not screenshots.
We can reopen the issue once you've updated it. Please be aware you should always try to work with the latest master of MoviePy where possible, not the last PyPI release, which is quite old.
thanks i will update in proper format
please open my issue again i did formating stuff
I am also having a similar issue.
snippet that causes error:
import moviepy.video.fx.all as vfx
from moviepy.editor import VideoFileClip, concatenate_videoclips
video_length = 20
video_file = "Primary\\Videos\\3.mp4"
Evideo = VideoFileClip(video_file)
x = vfx.time_mirror(Evideo)
Evideo = concatenate_videoclips([Evideo, x])
Evideo.write_videofile('output.mp4')
Expected output:
to write a video file plays normally first half and plays in reverse in second in 2nd half
Actual behavior:
Traceback (most recent call last):
File "d:\Video_generator\5_Facts\t.py", line 7, in <module>
x = vfx.time_mirror(Evideo)
^^^^^^^^^^^^^^^^^^^^^^^
File "<decorator-gen-89>", line 2, in time_mirror
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
^^^^^^^^^^^^^^^^
File "<decorator-gen-88>", line 2, in time_mirror
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\decorators.py", line 29, in apply_to_mask
newclip = f(clip, *a, **k)
^^^^^^^^^^^^^^^^
File "<decorator-gen-87>", line 2, in time_mirror
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\decorators.py", line 41, in apply_to_audio
newclip = f(clip, *a, **k)
^^^^^^^^^^^^^^^^
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\video\fx\time_mirror.py", line 13, in time_mirror
return self.fl_time(lambda t: self.duration - t, keep_duration=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\Clip.py", line 187, in fl_time
return self.fl(lambda gf, t: gf(t_func(t)), apply_to,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\Clip.py", line 136, in fl
newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<decorator-gen-63>", line 2, in set_make_frame
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\decorators.py", line 14, in outplace
f(newclip, *a, **k)
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\video\VideoClip.py", line 644, in set_make_frame
self.size = self.get_frame(0).shape[:2][::-1]
^^^^^^^^^^^^^^^^^
File "<decorator-gen-13>", line 2, in get_frame
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\Clip.py", line 93, in get_frame
return self.make_frame(t)
^^^^^^^^^^^^^^^^^^
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\Clip.py", line 136, in <lambda>
newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\Clip.py", line 187, in <lambda>
return self.fl(lambda gf, t: gf(t_func(t)), apply_to,
^^^^^^^^^^^^^
File "<decorator-gen-13>", line 2, in get_frame
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\Clip.py", line 93, in get_frame
return self.make_frame(t)
^^^^^^^^^^^^^^^^^^
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\video\io\VideoFileClip.py", line 113, in <lambda>
self.make_frame = lambda t: self.reader.get_frame(t)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\video\io\ffmpeg_reader.py", line 184, in get_frame
result = self.read_frame()
^^^^^^^^^^^^^^^^^
File "C:\Users\devan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\moviepy\video\io\ffmpeg_reader.py", line 133, in read_frame
raise IOError(("MoviePy error: failed to read the first frame of "
OSError: MoviePy error: failed to read the first frame of video file Primary\Videos\3.mp4. That might mean that the file is corrupted. That may also mean that you are using a deprecated version of FFMPEG. On Ubuntu/Debian for instance the version in the repos is deprecated. Please update to a recent version from the website.
Specifications:
- Python Version: 3.11.4
- MoviePy Version:1.0.3
Hello, @keikoro did u get any solution for that ?
Hello, @keikoro did u get any solution for that ?
Sorry, I didn't look into the issue, I only went through our tickets to tag them and pointed out missing info in the process.
@nikhiltree Pass the file path, not the URL of the video in VideoFileClip
.
if we want to pass the local path then we need to download the video from s3 bucket and we have kubernets so if we download it then it will create too much load in our instance
please here any body run this code on minkube and help me out to solve this error @keikoro
But in order to run this code you need to pass file path, it won’t work if you pass url of the video, you can download your video using requests
module or try a video from your local computer.
Additionally if you’re hosting your videos on s3 bucket and downloading videos will increase load, so why are you using s3 bucket when you can’t even download a video?
suppose if i have one user and user have the 1 video xyz.mp4 and i am creating 500 video from this xyz.mp4. Now imagine 500 users if i download this much video template in cluster that would be very costly time as well as resource so better options is whenever process required the video just call the url. we are using celery for maintaining task which is create the 500 videos that 500 videos user can download via s3 link
our concerns is why this library can't load video from s3 link that's right direction to think i guess
@nikhiltree I am facing same issue while working with EC2 (Ubuntu). The code works fine for Windows but I am not able to read video from URL in EC2. Any suggestions?
@nikhiltree, @qaixerabbas I am also facing a similar issue. What's stranger for me is that in my dev environment, I can create the VideoClip from an S3 URL. But in my production environment, I see the following error:
raise IOError(("MoviePy error: failed to read the duration of file %s.\n"
OSError: MoviePy error: failed to read the duration of file {url_here}.
Does anyone have any workarounds for this?
Firstly Sorry For Late Reply.
- Make sure moviepy can find this enviroment variable
- IMAGEMAGICK_BINARY="/usr/bin/convert"
- The issue with ffmpeg package please installed properly
- ffmpeg package parse the url for reading the durations of video
- Run the below script for verify the video durations is parse properly or not
`from future import division
import logging import os import re import subprocess as sp import warnings
import numpy as np
from moviepy.compat import DEVNULL, PY3 from moviepy.config import get_setting # ffmpeg, ffmpeg.exe, etc... from moviepy.tools import cvsecs
is_GIF = False cmd = [get_setting("FFMPEG_BINARY", "-i", "link_s3"]
if is_GIF: cmd += ["-f", "null", "/dev/null"]
popen_params = {"bufsize": 10**5,"stdout": sp.PIPE,"stderr": sp.PIPE,"stdin": DEVNULL} if os.name == "nt": popen_params["creationflags"] = 0x08000000
proc = sp.Popen(cmd, **popen_params) (output, error) = proc.communicate() infos = error.decode('utf8') print(infos) `
Hi, thank you for the response! I tried running the script on my prod environment in Heroku. I ensured ffmpeg was installed via build pack. However, the duration doesn't show up in production. The duration DOES appear in my local dev environment. I tried setting the environment variable as well. Any other tips as to what could be going on here?
I see am currently you are facing an issue with a piece of code. If it's convenient for you, could we possibly arrange a meeting to discuss the problem in more detail? My availability is flexible, and I believe that a brief collaboration session would greatly expedite the resolution process.
If sharing the actual code poses any confidentiality concerns, you can certainly describe the relevant code snippets to provide context. Your insights would be valuable in helping me identify and rectify the issue.
hey @ashankv I downloaded the video and then use MoviePy for further processing. I used pythons's wget module to temporarily download video on server and then do processing. In my case I wrote a backend service on Linux so downloading the video was better option for me which is working perfectly fine. In my previous task I was writing a FastAPI application so I tried to read file from URL and I was not successful in production environment on Linux (EC2 Ubuntu).
Hi all, did anyone get any further with this?
I am experiencing the same or a similar issue. When I run moviepy code locally in my virtual environment, it will happily create an AudioFileClip
with a url as the file source, not a local file path. If I run in docker however it will not. I have a small example in this repo to demonstrate.
Does anyone know why this could be happening? Thanks
Repo: https://github.com/alifhughes/moviepy-example
EDIT: I believe it is soemthing to do with the different compiled versions of ffmpeg from Apple to Debian on the docker image. The easier way around it is to do, like everyone else, download the video and then process it. Curious to see if anyone can resolve it though
I have faced same issue. @alifhughes said downloading the video and then processing it can solve this issue and I am using firebase functions How can I download In that environment?
Any update on this, facing the same issue @alifhughes @ashankv @nikhiltree @qaixerabbas
@missionfission https://github.com/Zulko/moviepy/issues/1993#issuecomment-1678688684
It is still not working for us