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

error: string: When trying to import from moviepy #9

Closed
codelucas opened this issue Jan 31, 2014 · 24 comments
Closed

error: string: When trying to import from moviepy #9

codelucas opened this issue Jan 31, 2014 · 24 comments
Labels
bug Issues that report (apparent) bugs.

Comments

@codelucas
Copy link

Refer to this line of code:

print "error: string: %s, stderr: %s"%(s,serr)

I successfully installed moviepy and every dependency, for example: import moviepy and from moviepy.editor import * works, along with import pygame, etc. I also did sudo apt-get install libav-tools for the ffmpeg library.

However, the line clip = VideoFileClip("some_video.mp4").subclip(0, 60) causes my terminal to blank into a new, unusual terminal console with one line of error: error: string:

I am using Ubunu 12.04.3 Server.

@codelucas
Copy link
Author

Update, I tried this again on a different console and got some text output:

/local/lib/python2.7/site-packages/moviepy/video/io/ffmpeg_reader.py", line 94, in read_frame
 ... dtype='uint8').reshape((h,w,len(s)/(w*h)))
ValueError: total size of new array must be unchanged

@Zulko
Copy link
Owner

Zulko commented Jan 31, 2014

Ok, you have the same problem as the other Ubuntu users: FFMPEG is unmaintained on Ubuntu. Install the last FFMPEG version (this means go to the FFMPEG site, download the binary put it in your usr/bin folder). This should work.

@codelucas
Copy link
Author

Thanks for the fast reply, will try it now and close if it works!

@codelucas
Copy link
Author

I installed the ffmpeg binary from the site as you said:

Here is my current ffmpeg version:

$ ffmpeg
ffmpeg version 0.10.9-7:0.10.9-1~precise1 Copyright (c) 2000-2013 the FFmpeg developers
built on Oct  4 2013 06:37:30 with gcc 4.6.3

Unfortunately, I am getting new errors when writing to video: final_clip.to_videofile("solution.avi", fps=25, codec='mpeg4')

>>>
Making file solution.avi ...
Rendering audio TEMP_MPY_to_videofile_SOUND.ogg
        =Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/local/lib/python2.7/site-packages/moviepy/video/VideoClip.py", line 254, in to_videofile audio_bufsize, audio_codec, audio_bitrate, verbose)

File "/local/lib/python2.7/site-packages/moviepy/audio/AudioClip.py", line 86, in to_audiofile                                                                                                                      codec, bitrate, verbose)

File "<string>", line 2, in ffmpeg_audiowrite File "/local/lib/python2.7/site-packages/moviepy/decorators.py", line 43, in requires_duration
 return f(clip, *a, **k) File "/local/lib/python2.7/site-packages/moviepy/audio/io/ffmpeg_audiowriter.py", line 89, in ffmpeg_audiowrite
                                                                                    writer.write_frames(sndarray)

File "/local/lib/python2.7/site-packages/moviepy/audio/io/ffmpeg_audiowriter.py", line 58, in write_frames
                                                                                                                         frames_array.tofile(self.proc.stdin)
              ValueError: 80000 requested and 49152 written

Perhaps I am installing the wrong binary from the ffmpeg website? May I have an exact version & url?

Thank you!

@Zulko
Copy link
Owner

Zulko commented Feb 1, 2014

I don't know. If you were able to open a video, your FFMPEG version should be perfectly valid. Maybe it is a codec thing. Does it work if you try other codecs ? like

final_clip.to_videofile("solution.mp4") # uses codec libx264
final_clip.to_videofile("solution.ogv", fps=25, codec=libtheora')

@codelucas
Copy link
Author

Hm, both fail and with the same error as above, something to do with ffmpeg_audiowriter.py.

/local/lib/python2.7/site-packages/moviepy/audio/io/ffmpeg_audiowriter.py", line 58, in write_frames frames_array.tofile(self.proc.stdin)
ValueError: 80000 requested and 49152 written
/local/lib/python2.7/site-packages/moviepy/audio/io/ffmpeg_audiowriter.py", line 58, in write_frames
frames_array.tofile(self.proc.stdin)
ValueError: 80000 requested and 49152 written

@Zulko
Copy link
Owner

Zulko commented Feb 1, 2014

Ok, sorry, I misread your previous message... Seems like a real bug to me. The audio support is not a part of the code that I am proud of. However I have made a lot of videos with audio and never had this problem, that's interesting. Could you give me more details on what you are trying to do ? Like, is your video very short or something ? Did you mix different videos ?

could you try this (it will use another codec for the audio):

final_clip.audio.to_audiofile("test.mp3", codec='libmp3lame')

Just to be sure: I don't think this could be the problem, but your ffmpeg version seems a little old, you have much more recent versions at the bottom of this page:

http://ffmpeg.gusari.org/static/32bit/

And last hope, try reducing the audio buffering, that may be the issue:

final_clip.to_videofile("test.mp4",  audio_bufsize=5000)

@codelucas
Copy link
Author

No worries! I switched to the latest 64bit ffmpeg and now the video.avi files are being generated properly!

However, I have 2 more (smaller) issues. When I save the video in .mp4 format (I know .avi is recommended), the audio is lost. How should I go about try to get a resulting .mp4 video?

Also, if I run the txt_clip = TextClip("sample txt", fontsize=20, color='white') command, (not even compositing it yet) I get an error for:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/local/lib/python2.7/site-packages/moviepy/video/VideoClip.py", line 837, in __init__
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
 File "/usr/lib/python2.7/subprocess.py", line 679, in __init__ errread, errwrite)
 File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

Also, I notice a temp.txt file laying in the current directory with my set overlay text inside it. Maybe that is a clue.

Thanks for your fast responses so far man!

@Zulko
Copy link
Owner

Zulko commented Feb 1, 2014

For TextClip, I guess it is because you don't have ImageMagick installed on your computer. You need it to generate texts. It is very easy to install on ubuntu through the software manager, and there are less issues than with ffmpeg. You can check if you have ImageMagick installed with

convert -version

For your other point (no audio), once again it is strange. Could you copy the whole output of the .to_videofile ?

@codelucas
Copy link
Author

Here is the full output of .to_videofile(..):

>>> Making file solution.mp4 ...
Rendering audio TEMP_MPY_to_videofile_SOUND.ogg
============audio done !Rendering video TEMP_MPY_to_videofile.mp4
==========video done ! Now merging video and audio...
Running:
>>> ffmpeg -y -i TEMP_MPY_to_videofile_SOUND.ogg -i TEMP_MPY_to_videofile.mp4 -vcodec copy -acodec copy solution.mp4
... ffmpeg command successful.
Your video is ready ! Fingers crossed for the Oscars !
>>> 

@Zulko
Copy link
Owner

Zulko commented Feb 2, 2014

This is strange, it looks like everything is run smoothly: apparently the sound file is correctly generated and incorporated into the movie. But I have heard that some media cannot read the sound of the videofile when it is .ogg ...
Could you try to_videofile('solution.mp4', remove_temp=False), this should keep a file called TEMP_MPY_to_videofile_SOUND.ogg in your directory. Is this file normal ? Can it play ?
Else you can change the audio codec (the choice of the codec was buggy, you would need to redownload moviepy from github for it to work), and run for instance to_videofile('test.mp4', audio_codec='mp3').

@codelucas
Copy link
Author

Hmm, i went with your second suggestion.

I re-downloaded moviepy from Github and manually installed via setup.py. Then, attmped to use
to_videofile('test.mp4', audio_codec='mp3'). No errors occurred but the video was completely black with no sound.

@Zulko
Copy link
Owner

Zulko commented Feb 2, 2014

Even stranger. can you paste the output ? And when you just do to_videofile('test.mp4'), you have normal video (without sound) right ?

@codelucas
Copy link
Author

For your first suggestion, when I set remove_temp=False the ogg file plays perfectly fine! Let me paste u the output now.

And yes, 'test.mp4' gives me a fine video but no sound.

@codelucas
Copy link
Author

WAIT NO. ^ I was wrong. If I dont include fps=25, codec='mpeg4', then the video is black.

@codelucas
Copy link
Author

Output for to_videofile('test.mp4', audio_codec='mp3')

Making file test.mp4 ...
Rendering audio TEMP_MPY_to_videofile_SOUND.mp3                                                                                                          ============audio done !Rendering video TEMP_MPY_to_videofile.mp4
==========video done !
Now merging video and audio...
Running:
>>> ffmpeg -y -i TEMP_MPY_to_videofile_SOUND.mp3 -i TEMP_MPY_to_videofile.mp4 -vcodec copy -acodec copy test.mp4
... ffmpeg command successful.

Your video is ready ! Fingers crossed for the Oscars !>>> 

@codelucas
Copy link
Author

If I include codec='mpeg4' in the to_videofile('test.mp4', audio_codec='mp3') command, the video is present, but still no audio.

@Zulko
Copy link
Owner

Zulko commented Feb 2, 2014

Ok, I am lost, sorry. I may think of a solution later, but this really looks like an ffmpeg problem of some sort. Maybe we can see if someone else has the same problems.

@codelucas
Copy link
Author

No worries! Ill install different versions of ffmpeg or try this on a different machine!

@Zulko Zulko added the bug label Feb 8, 2014
@Zulko
Copy link
Owner

Zulko commented Feb 20, 2014

Hey ! If you are still interested I made lots of change and there are good chances that the problem you described is solved (I would guess it was an incompatibility in the multiprocessing module, something like that). I would be very grateful if you gave it a try :)

@codelucas
Copy link
Author

Awesome! THANK YOU for making all these changes. Will try tonight and report what happens.

@Zulko
Copy link
Owner

Zulko commented Feb 20, 2014

I can't promise anything :)

Le 21/02/2014 00:48, Lucas Ou-Yang a écrit :

Awesome! THANK YOU for making all these changes. Will try tonight and
report what happens.


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

@codelucas
Copy link
Author

.avi works.. but .mp4 results still contain no audio :(

I seriously think this is an ffmpeg issue where i'm probably installing the wrong thing.
Sorry haha

@Zulko
Copy link
Owner

Zulko commented Aug 16, 2014

Hey there. I'm closing this issue as old. The program is a lot better now I you want to give it another try :)

@Zulko Zulko closed this as completed Aug 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs.
Projects
None yet
Development

No branches or pull requests

2 participants