Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading video on Ubuntu 13.10 does not work #8

Closed
almarklein opened this issue Jan 29, 2014 · 15 comments
Closed

Reading video on Ubuntu 13.10 does not work #8

almarklein opened this issue Jan 29, 2014 · 15 comments

Comments

@almarklein
Copy link

Thanks for the nice library. However, I cannot get it to work on any of the video files that I try. I took the ffmpeg_reader.py and ripped out a few small parts to make it standalone.

Tried with Python 2.7 and Python 3.3. Reinstalled ffmpeg to be sure.

I executed:

filename = '/path/to/my/video/file'
vf = FFMPEG_VideoReader(filename)
vf.close()

In all cases the line in read_frame() reads not enough bytes:

s = self.proc.stdout.read(self.depth_w_h)

Now, note that read() returns at most the given number of bytes, but any subsequent call to read that I make does not yield any more bytes.

Related: Is there a perhaps an example movie on the web which is known to work?

@Zulko
Copy link
Owner

Zulko commented Jan 29, 2014

Thanks for the feedback. When you say you reinstalled ffmpeg, did you use the binary of the last version on the FFMPEG website ? What format are you video in ? Have you tried different video formats ? Could you try FFMPEG_VideoReader(filename, print_infos=True) and paste the output ?

Edit: I don't think the package is Python3 compatible, this is next in my todo list (should not be problematic).

@almarklein
Copy link
Author

Output of one example file:

ffmpeg version 0.8.9-6:0.8.9-0ubuntu0.13.10.1, Copyright (c) 2000-2013 the Libav developers
built on Nov  9 2013 19:09:46 with gcc 4.8.1
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Input #0, avi, from '/home/almar/data/movs/MVI_1006.AVI':
Metadata:
    creation_time   : 2008-08-15 11:56:25
    encoder         : CanonMVI02
Duration: 00:00:10.59, start: 0.000000, bitrate: 7590 kb/s
    Stream #0.0: Video: mjpeg, yuvj422p, 640x480, 15 tbr, 15 tbn, 15 tbc
    Stream #0.1: Audio: pcm_u8, 11024 Hz, 1 channels, u8, 88 kb/s
Unable to find a suitable output format for 'pipe:'

I have tried a few different videos of different formats (.mpg. mp4, .wmv .AVI).

@almarklein
Copy link
Author

As you see in last comment, the version that comes with Ubuntu 13.10 is quite old. When I try the latest version from the website it does work. woohoo!

Also, when I use -vcodec png or bmp, it works with my system version as well. Although you need a second library to convert the images to raw RGB values.

@Zulko Zulko closed this as completed Jan 29, 2014
@Zulko
Copy link
Owner

Zulko commented Jan 29, 2014

Maybe I should really stress in the docs the importance of downloading FFMPEG from the site (all the Ubuntu/Debian users have this problem). I didn't get you last sentence, what did you mean exactly ?

@almarklein
Copy link
Author

In the initialize() method, when I set '-vcodec', 'png' (instead of rawvideo) and then in read_frame() convert the bytes to raw RGB data, it works ok too. This would mean, that it could work with native Linux ffmpeg.

This could perhaps be a nice fallback, since many Linuxes come with ffmpeg (albeit an old version).

@Zulko
Copy link
Owner

Zulko commented Jan 29, 2014

Ah, I get it. And then convert to raw RBG using PIL for instance. Yes that would be a workaround, but with some inconveniences:

  • It would make PIL (or other) mandatory, while here only numpy is required.
  • It would make 'silently' the program be slower for these users.
  • I am not sure if there are other commands in MoviePy that break with the former FFMPEG.
  • Really the FFMPEG on Debian/Ubuntu is buggy (in many videos it adds a black stripe on the side of the video). See this video, on the right: http://www.youtube.com/watch?v=aC5CifkacSI

@almarklein
Copy link
Author

Yes, you are right on these points.

Also, the png trick now only works for the first frame. Kind of makes sense, since you cannot know beforehand how large the file would be that ffmpeg will stream over the Pipe... it would need some extra work to split the returned bytes and use the remainder for the next image :( would add to code complexity.

Perhaps a check on ffmpeg version and give a warning if its < 1?

@Zulko
Copy link
Owner

Zulko commented Jan 29, 2014

That is a good Idea. I don't know how to do that exactly (my version number of FFMPEG is N-58039-gda9d360, it's strange) but I could at least spot the deprecated version of Debuntu and send a warning. Thanks !

@almarklein
Copy link
Author

ffmpeg -v gives you that?

@Zulko
Copy link
Owner

Zulko commented Jan 29, 2014

Yup (ffmpeg -version, to be precise). And this is a perfectly
functional version (it's a binary I took from the website). I don't know
if I am the only one around with a crypted version number...

Le 29/01/2014 23:03, Almar Klein a écrit :

|ffmpeg -v| gives you /that/?


Reply to this email directly or view it on GitHub
#8 (comment).

@rainerfritz
Copy link

when I use it like this: image = ffmpeg_read_image(filename)
then I get an error from ffmpeg:
Unable to find a suitable output format for 'pipe:'
where my inputfile is an mp4 with h264

@Zulko
Copy link
Owner

Zulko commented Aug 13, 2014

@rainerfritz Can you paste the entire error message and the entire code you used ?

@rainerfritz
Copy link

Code is here: http://dcs.co.at/files/ffmpeg_read_rgb.py
Error MSG is:
[NULL @ 0x342be60] Unable to find a suitable output format for 'pipe:'
pipe:: Invalid argument
ffmpeg is giving this error...
finaly I want to to read rgb values of the frames and putting them in a numpy array to work
with them...

@Zulko
Copy link
Owner

Zulko commented Aug 14, 2014

This isn't clear in the documentation, but ffmpeg_read_image is for image files (PNG, BMP etc.). It should work for movies too, but it can only get the first frame. It is strange that it doesn't work on your computer, it works on mine (Ubuntu). What is your version of FFMPEG ? Did you download it directly from the website ?

To get frames with the FFMPEG reader you do this:

reader = FFMPEG_VideoReader('v/f1.mp4')
for i in range(reader.nframes):
    frame = reader.read_frame() # a WxHx3 numpy RGB array
    # do stuff with the frame

You can also directly import MoviePy:

from moviepy.video.io.VideoFileClip import VideoFileClip
clip = VideoFileClip("myfile.mp4")
clip.get_frame(t) # gets the numpy array of the frame at time t
for frame in clip.iter_frames():
    # do whatever you want with the numpy frame

@rainerfritz
Copy link

FFMPEG is V2.2 and compiled from the ffmpeg source. OS is Ubuntu 14.04
I'm thinking on applying a 3D LUT after reading the frames and writing the converted picture out to compress it then... that is the reason why I came to your module, because I want to read frame by frame a video file...
If I want to plot a frame with matplotlib I get also an error:
File "moviepy_test.py", line 6, in
clip.get_frame(t) # gets the numpy array of the frame at time t
File "/usr/local/lib/python2.7/dist-packages/moviepy-0.2.1.7.21-py2.7.egg/moviepy/video/io/VideoFileClip.py", line 66, in
self.get_frame = lambda t: self.reader.get_frame(t)
File "/usr/local/lib/python2.7/dist-packages/moviepy-0.2.1.7.21-py2.7.egg/moviepy/video/io/ffmpeg_reader.py", line 134, in get_frame
result = self.read_frame()
File "/usr/local/lib/python2.7/dist-packages/moviepy-0.2.1.7.21-py2.7.egg/moviepy/video/io/ffmpeg_reader.py", line 89, in read_frame
assert len(s) == nbytes
AssertionError

Code:
from moviepy.video.io.VideoFileClip import VideoFileClip
import matplotlib.pyplot as plt

t = '00:00:00:01'
clip = VideoFileClip("/media/rainer/LinuxData/GOPR1678.MP4")
clip.get_frame(t) # gets the numpy array of the frame at time t
for frame in clip.iter_frames():
# do whatever you want with the numpy frame
imgplot = plt.imshow(frame)

ghost pushed a commit that referenced this issue Feb 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants