skip to Main Content

Using python 3.11.10 and moviepy 1.0.3 on ubuntu 24.04.1 (in a VirtualBox 7.1.3 on windows 10) I have problems to load a video clip. The test code is just

from moviepy.editor import VideoFileClip
clip = VideoFileClip("testvideo.ts")

but the error is

Traceback (most recent call last):
  File "/home/alex/.cache/pypoetry/virtualenvs/pypdzug-WqasAXAr-py3.11/lib/python3.11/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 "/home/alex/Repos/pypdzug/tester.py", line 5, in <module>
    clip = VideoFileClip("testvideo.ts")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/.cache/pypoetry/virtualenvs/pypdzug-WqasAXAr-py3.11/lib/python3.11/site-packages/moviepy/video/io/VideoFileClip.py", line 88, in __init__
    self.reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt,
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/.cache/pypoetry/virtualenvs/pypdzug-WqasAXAr-py3.11/lib/python3.11/site-packages/moviepy/video/io/ffmpeg_reader.py", line 35, in __init__
    infos = ffmpeg_parse_infos(filename, print_infos, check_duration,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/.cache/pypoetry/virtualenvs/pypdzug-WqasAXAr-py3.11/lib/python3.11/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 testvideo.ts.
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

It says it failed to read the duration of the file, but the file plays properly (with mplayer) and ffmpeg -i testvideo.ts returns

ffmpeg version 6.1.1-3ubuntu5 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 13 (Ubuntu 13.2.0-23ubuntu3)
  configuration: --prefix=/usr --extra-version=3ubuntu5 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --disable-omx --enable-gnutls --enable-libaom --enable-libass --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libglslang --enable-libgme --enable-libgsm --enable-libharfbuzz --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-openal --enable-opencl --enable-opengl --disable-sndio --enable-libvpl --disable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-ladspa --enable-libbluray --enable-libjack --enable-libpulse --enable-librabbitmq --enable-librist --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libx264 --enable-libzmq --enable-libzvbi --enable-lv2 --enable-sdl2 --enable-libplacebo --enable-librav1e --enable-pocketsphinx --enable-librsvg --enable-libjxl --enable-shared
  libavutil      58. 29.100 / 58. 29.100
  libavcodec     60. 31.102 / 60. 31.102
  libavformat    60. 16.100 / 60. 16.100
  libavdevice    60.  3.100 / 60.  3.100
  libavfilter     9. 12.100 /  9. 12.100
  libswscale      7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc    57.  3.100 / 57.  3.100
Input #0, mpegts, from 'testvideo.ts':
  Duration: 00:10:10.13, start: 0.133333, bitrate: 3256 kb/s
  Program 1 
    Metadata:
      service_name    : 2024-10-04 11:49:49.917
      service_provider: gvos-6.0
  Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080, 15 fps, 15 tbr, 90k tbn

Here the duration is clearly given to be 10 minutes and 10.13 seconds. So what could be the cause of this error/issue?

2

Answers


  1. FFMPEG_BINARY
    Normally you can leave it to its default (‘ffmpeg-imageio’) in which case imageio will download the right ffmpeg binary (on first use) and then always use that binary.
    The second option is "auto-detect". In this case ffmpeg will be whatever binary is found on the computer: generally ffmpeg (on Linux/macOS) or ffmpeg.exe (on Windows).
    Lastly, you can set it to use a binary at a specific location on your disk by specifying the exact path.

    use this code:

    import os
    os.environ["FFMPEG_BINARY"] = "/path/to/custom/ffmpeg"
    

    where path is path to ffmpeg 6.1.1-3ubuntu5 which is likely to be in your PATH which is likely to be here /usr/local/bin/bin/ffmpeg, if not just download ffmpeg 6.1.2 from https://ffmpeg.org/download.html#releases and use it

    Why:

    debugging from errors:
    moviepy uses ffmpeg version 4.2.2-static by default(stated in error), you have ffmpeg version 6.1.1-3ubuntu5(stated in output in terminal using ffmpeg -i *.ts) in your pc which is able to read time of video, also moviepy states

    "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." in the last line of a similar error here also this is the very reason for

    "The code works fine for Windows" over here ig

    Therefore using the ffmpeg which is able to deal with your .ts file in moviepy(i.e. 6.1.1) would be solution.

    FFMPEG is a fast developing library so using the latest version is best, if this solution works,also try latest 7.1.1 or any latest version of series like 6.1.2 or 4.4.5

    Login or Signup to reply.
  2. Have you tried an alternative format?

    
    ffmpeg -i testvideo.ts -c copy testvideo.mp4
    
    

    also do you have an example video that i could try to run in my environment?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search