So, I have this very basic script that concatenates two videos, and adds a background sound.
def intro():
voiceoverIntro = AudioFileClip(audio[3]) #get path for intro.mp3
introVideo = []
temp = p1vid + p2vid + p3vid
for x in temp: # add product videos to introVideo if they are longer than intro.mp3
x = VideoFileClip(x)
if x.duration >= voiceoverIntro.duration:
introVideo.append(x)
if len(introVideo) >= 1:
#Get the video and turn off its volume
introBg = introVideo[0].volumex(0).resize((1280,720))
introBg = introBg.set_audio(voiceoverIntro).set_duration(voiceoverIntro.duration)
introBg.reader.close()
introBg.audio.reader.close_proc()
return introBg
And this function creates the second clip
def productThreeOpener(productName):
opener3 = VideoFileClip("media/number3.mp4").volumex(0).resize((1280,720))
text = TextClip(productName,fontsize=60,color='white', font="Dekar")\
.set_pos(("right", "center"))\
.set_duration(3)\
.set_start(2)\
.crossfadein(1)\
.crossfadeout(1)\
.margin(right=200,opacity=0)
opener3 = CompositeVideoClip([opener3, text])
return opener3
Now we just concatenate the two outputs
final_clip = concatenate_videoclips([intro, productThreeOpener], method="compose")
final_clip.resize((1280, 720)).write_videofile("output/intro.mp4", threads=8, fps=24, progress_bar=False)
Running the code above returns this error;
Traceback (most recent call last):
[MoviePy] >>>> Building video output/intro.mp4
File "C:/Users/Akbulut/PycharmProjects/youtubeVideoEditor/vidEditor/sandbox.py", line 145, in <module>
[MoviePy] Writing audio in introTEMP_MPY_wvf_snd.mp3
final_clip.write_videofile("output/intro.mp4", threads=8, fps=24, progress_bar=False)
File "<decorator-gen-51>", line 2, in write_videofile
File "C:\Program Files\Python36\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "<decorator-gen-50>", line 2, in write_videofile
File "C:\Program Files\Python36\lib\site-packages\moviepy\decorators.py", line 137, in use_clip_fps_by_default
return f(clip, *new_a, **new_kw)
File "<decorator-gen-49>", line 2, in write_videofile
File "C:\Program Files\Python36\lib\site-packages\moviepy\decorators.py", line 22, in convert_masks_to_RGB
return f(clip, *a, **k)
File "C:\Program Files\Python36\lib\site-packages\moviepy\video\VideoClip.py", line 318, in write_videofile
progress_bar=progress_bar)
File "<decorator-gen-73>", line 2, in write_audiofile
File "C:\Program Files\Python36\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "C:\Program Files\Python36\lib\site-packages\moviepy\audio\AudioClip.py", line 213, in write_audiofile
progress_bar=progress_bar)
File "<decorator-gen-70>", line 2, in ffmpeg_audiowrite
File "C:\Program Files\Python36\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "C:\Program Files\Python36\lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py", line 165, in ffmpeg_audiowrite
ffmpeg_params=ffmpeg_params)
File "C:\Program Files\Python36\lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py", line 71, in __init__
self.proc = sp.Popen(cmd, **popen_params)
File "C:\Program Files\Python36\lib\subprocess.py", line 594, in __init__
_cleanup()
File "C:\Program Files\Python36\lib\subprocess.py", line 205, in _cleanup
res = inst._internal_poll(_deadstate=sys.maxsize)
File "C:\Program Files\Python36\lib\subprocess.py", line 1025, in _internal_poll
if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
OSError: [WinError 6] İşleyici geçersiz
Exception ignored in: <bound method FFMPEG_AudioWriter.__del__ of <moviepy.audio.io.ffmpeg_audiowriter.FFMPEG_AudioWriter object at 0x0000000A885019B0>>
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py", line 134, in __del__
self.close()
File "C:\Program Files\Python36\lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py", line 122, in close
if self.proc:
AttributeError: 'FFMPEG_AudioWriter' object has no attribute 'proc'
Process finished with exit code 1
I strictly followed MoviePY installation guide, installed it and all of its dependencies about 2 days ago. I work on a 64b Windows machine. Python version 3.6.1
I've been stuck with this error for over a day now, and I don't know what to try.. Any help/advice is highly appreciated.
Thanks.
Related
I was running a script to get data from excel for over a year using the Xlwings range command like so...
list=Range('A1:D10').value
Suddenly, it stopper working. I had changed nothing in the code nor the system, other than maybe installing another network card.
This is the error when trying to use the Range assignment now.
Traceback (most recent call last):
File "G:\python32\fetcher.py", line 61, in <module>
listFull = getComData()
File "G:\python32\fetcher.py", line 38, in getComData
listFull=Range('A4:H184').value
File "G:\python32\lib\site-packages\xlwings\main.py", line 1490, in __init__
impl = apps.active.range(cell1).impl
File "G:\python32\lib\site-packages\xlwings\main.py", line 439, in range
return Range(impl=self.impl.range(cell1, cell2))
File "G:\python32\lib\site-packages\xlwings\_xlwindows.py", line 457, in range
xl1 = self.xl.Range(arg1)
File "G:\python32\lib\site-packages\xlwings\_xlwindows.py", line 341, in xl
self._xl = get_xl_app_from_hwnd(self._hwnd)
File "G:\python32\lib\site-packages\xlwings\_xlwindows.py", line 251, in get_xl_app_from_hwnd
disp = COMRetryObjectWrapper(Dispatch(p))
File "G:\python32\lib\site-packages\win32com\client\__init__.py", line 96, in Dispatch
return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx)
File "G:\python32\lib\site-packages\win32com\client\__init__.py", line 37, in __WrapDispatch
klass = gencache.GetClassForCLSID(resultCLSID)
File "G:\python32\lib\site-packages\win32com\client\gencache.py", line 180, in GetClassForCLSID
mod = GetModuleForCLSID(clsid)
File "G:\python32\lib\site-packages\win32com\client\gencache.py", line 223, in GetModuleForCLSID
mod = GetModuleForTypelib(typelibCLSID, lcid, major, minor)
File "G:\python32\lib\site-packages\win32com\client\gencache.py", line 259, in GetModuleForTypelib
mod = _GetModule(modName)
File "G:\python32\lib\site-packages\win32com\client\gencache.py", line 622, in _GetModule
mod = __import__(mod_name)
ValueError: source code string cannot contain null bytes
I recorded a movie with my celphone and I want to increase the movie duration n times. Ex.: If the duration of the movie is 5 seconds, the output movie should have n x 5 seconds of duration, it should be repeated. My goal is to get a 5 seconds movie and repeat n times for 3 hours. I tried with moviepy but it points an error related to the file. I'm trying with moviepy but I'm open to cv2 or any other ideia. This is my code and the error:
from moviepy.editor import *
videoclip = VideoFileClip('VID_20201207_022713542.mp4')
audio = afx.audio_loop(videoclip, nloops=3)
and the error:
runfile('C:/Users/felip/Google Drive/Musica/music1.py', wdir='C:/Users/felip/Google Drive/Musica')
Traceback (most recent call last):
File "C:\Users\felip\Google Drive\Musica\music1.py", line 11, in
audio = afx.audio_loop(videoclip, nloops=3)
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\audio\fx\audio_loop.py", line 28, in audio_loop
return concatenate_audioclips(nloops*[audioclip])
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\audio\AudioClip.py", line 319, in concatenate_audioclips
result = CompositeAudioClip(newclips).set_duration(tt[-1])
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\audio\AudioClip.py", line 287, in init
self.nchannels = max([c.nchannels for c in self.clips])
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\audio\AudioClip.py", line 287, in
self.nchannels = max([c.nchannels for c in self.clips])
AttributeError: 'VideoFileClip' object has no attribute 'nchannels'
EDIT: I tried:
from moviepy.editor import *
clip = VideoFileClip('VID_20201207_022713542.mp4').fx(vfx.loop, n = 2)
clip.write_videofile("output.mp4")```
and received the error message:
runfile('C:/Users/felip/Google Drive/Musica/music1.py', wdir='C:/Users/felip/Google Drive/Musica')
chunk: 0%| | 0/3044 [00:00<?, ?it/s, now=None]Moviepy - Building video output.mp4.
MoviePy - Writing audio in outputTEMP_MPY_wvf_snd.mp3
chunk: 23%|██▎ | 714/3044 [00:02<00:26, 88.42it/s, now=None]Traceback (most recent call last):
File "C:\Users\felip\Google Drive\Musica\music1.py", line 11, in
clip.write_videofile("output.mp4")
File "", line 2, in write_videofile
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "", line 2, in write_videofile
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\decorators.py", line 135, in use_clip_fps_by_default
return f(clip, *new_a, **new_kw)
File "", line 2, in write_videofile
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\decorators.py", line 22, in convert_masks_to_RGB
return f(clip, *a, **k)
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\video\VideoClip.py", line 298, in write_videofile
logger=logger)
File "", line 2, in write_audiofile
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\audio\AudioClip.py", line 210, in write_audiofile
logger=logger)
File "", line 2, in ffmpeg_audiowrite
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py", line 169, in ffmpeg_audiowrite
logger=logger):
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\audio\AudioClip.py", line 86, in iter_chunks
fps=fps, buffersize=chunksize)
File "", line 2, in to_soundarray
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\audio\AudioClip.py", line 127, in to_soundarray
snd_array = self.get_frame(tt)
File "", line 2, in get_frame
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\Clip.py", line 93, in get_frame
return self.make_frame(t)
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\Clip.py", line 136, in
newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\Clip.py", line 187, in
return self.fl(lambda gf, t: gf(t_func(t)), apply_to,
File "", line 2, in get_frame
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\Clip.py", line 93, in get_frame
return self.make_frame(t)
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 77, in
self.make_frame = lambda t: self.reader.get_frame(t)
File "C:\Users\felip\Anaconda3\lib\site-packages\moviepy\audio\io\readers.py", line 172, in get_frame
"with clip duration=%d seconds, "%self.duration)
OSError: Error in file VID_20201207_022713542.mp4, Accessing time t=34.51-34.56 seconds, with clip duration=34 seconds,
chunk: 25%|██▌ | 762/3044 [00:19<00:25, 88.42it/s, now=None]
I am using openCV with C++ so I can't give you a python or moviepy code, but here's a idea for your own implementation.
step 1) read target video and save every frame to an image array(Mat class array).
step 2) make a VideoWriter class for save video and write saved frames n times in it.
I have no experience about audio processing, but I guess the same approach would work.
to slow down you can use
ffmpeg -i YOUR_INPUT_MOVIE.mp4 -vf "setpts=5*PTS" YOUR_OUTPUT_MOVIE.mp4
I am using the following:
from moviepy.editor import *
ukulele = VideoFileClip("./clips/513732763.mp4")
txt = TextClip("some text", color='white').set_duration(3)
final = CompositeVideoClip([ukulele,txt])
final.write_videofile("video.mp4",codec="libx264")
What I am trying to do is to add text over a video file clip. Writing normally with
VideoFileClip is working, however, when using CompositeVideoClip it doesn't.
However, when running with Python 3.6.9 I get the following errors:
Moviepy - Building video video.mp4.
MoviePy - Writing audio in videoTEMP_MPY_wvf_snd.mp3
chunk: 12% 52/447 [00:00<00:00, 518.22it/s, now=None]Traceback (most recent call last):
File "main.py", line 8, in <module>
final.write_videofile("video.mp4",codec="libx264")
File "</usr/lib/python3.6/site-packages/decorator.py:decorator-gen-51>", line 2, in write_videofile
File "/usr/lib/python3.6/site-packages/moviepy/decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "</usr/lib/python3.6/site-packages/decorator.py:decorator-gen-50>", line 2, in write_videofile
File "/usr/lib/python3.6/site-packages/moviepy/decorators.py", line 137, in use_clip_fps_by_default
return f(clip, *new_a, **new_kw)
File "</usr/lib/python3.6/site-packages/decorator.py:decorator-gen-49>", line 2, in write_videofile
File "/usr/lib/python3.6/site-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
return f(clip, *a, **k)
File "/usr/lib/python3.6/site-packages/moviepy/video/VideoClip.py", line 317, in write_videofile
logger=logger)
File "</usr/lib/python3.6/site-packages/decorator.py:decorator-gen-73>", line 2, in write_audiofile
File "/usr/lib/python3.6/site-packages/moviepy/decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "/usr/lib/python3.6/site-packages/moviepy/audio/AudioClip.py", line 209, in write_audiofile
logger=logger)
File "</usr/lib/python3.6/site-packages/decorator.py:decorator-gen-70>", line 2, in ffmpeg_audiowrite
File "/usr/lib/python3.6/site-packages/moviepy/decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "/usr/lib/python3.6/site-packages/moviepy/audio/io/ffmpeg_audiowriter.py", line 169, in ffmpeg_audiowrite
logger=logger):
File "/usr/lib/python3.6/site-packages/moviepy/audio/AudioClip.py", line 85, in iter_chunks
fps=fps, buffersize=chunksize)
File "</usr/lib/python3.6/site-packages/decorator.py:decorator-gen-72>", line 2, in to_soundarray
File "/usr/lib/python3.6/site-packages/moviepy/decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "/usr/lib/python3.6/site-packages/moviepy/audio/AudioClip.py", line 126, in to_soundarray
snd_array = self.get_frame(tt)
File "</usr/lib/python3.6/site-packages/decorator.py:decorator-gen-10>", line 2, in get_frame
File "/usr/lib/python3.6/site-packages/moviepy/decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "/usr/lib/python3.6/site-packages/moviepy/Clip.py", line 95, in get_frame
return self.make_frame(t)
File "/usr/lib/python3.6/site-packages/moviepy/audio/AudioClip.py", line 296, in make_frame
for c, part in zip(self.clips, played_parts)
File "/usr/lib/python3.6/site-packages/moviepy/audio/AudioClip.py", line 297, in <listcomp>
if (part is not False)]
File "</usr/lib/python3.6/site-packages/decorator.py:decorator-gen-10>", line 2, in get_frame
File "/usr/lib/python3.6/site-packages/moviepy/decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "/usr/lib/python3.6/site-packages/moviepy/Clip.py", line 95, in get_frame
return self.make_frame(t)
File "/usr/lib/python3.6/site-packages/moviepy/audio/io/AudioFileClip.py", line 78, in <lambda>
self.make_frame = lambda t: self.reader.get_frame(t)
File "/usr/lib/python3.6/site-packages/moviepy/audio/io/readers.py", line 184, in get_frame
self.buffer_around(fr_max)
File "/usr/lib/python3.6/site-packages/moviepy/audio/io/readers.py", line 238, in buffer_around
array = self.read_chunk(chunksize)
File "/usr/lib/python3.6/site-packages/moviepy/audio/io/readers.py", line 112, in read_chunk
s = self.proc.stdout.read(L)
AttributeError: 'NoneType' object has no attribute 'stdout'
Everything is correct and is working except for writing the CompositeVideoClip. How would I
go about fixing this?
This is a known issue with moveipy 1.0.1 that has an open github issue here https://github.com/Zulko/moviepy/issues/938
For now the best course of action seems to be reverting to version 1.0.0 which has helped a few people on that thread and myself also.
You can do this using pip install moviepy==1.0.0(note the double "=")
I am trying to add text to a clip generated by concatenate_videoclips, but I keep getting an error. I have tried to add the text to each clip individually and then concatenate, but I got the same error.
Here is my code:
clip_list = []
for file in movie_maker_directory:
clip = VideoFileClip('C:\dev\movie_maker\{}'.format(file))
if clip.rotation != 0:
clip = clip.rotate(-clip.rotation)
clip = clip.resize(height=1080)
clip_list.append(clip)
final_clip = concatenate_videoclips(clip_list, method="compose")
text = TextClip('Documentary Title', fontsize=5).set_position(('top', 'left'))
final_clip = CompositeVideoClip([text, clip])
final_clip.write_videofile("C:\dev\movie_maker\my_concatenation.mp4")
And here is the error message:
File "C:/dev/movie_compilator.py", line 58, in <module>
final_clip.write_videofile("C:\dev\movie_maker\my_concatenation.mp4")
File "<decorator-gen-51>", line 2, in write_videofile
File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "<decorator-gen-50>", line 2, in write_videofile
File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\decorators.py", line 137, in use_clip_fps_by_default
return f(clip, *new_a, **new_kw)
File "<decorator-gen-49>", line 2, in write_videofile
File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\decorators.py", line 22, in convert_masks_to_RGB
return f(clip, *a, **k)
File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\video\VideoClip.py", line 349, in write_videofile
progress_bar=progress_bar)
File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 209, in ffmpeg_write_video
fps=fps, dtype="uint8"):
File "C:\Local\Programs\Python\Python35\lib\site-packages\tqdm\_tqdm.py", line 833, in __iter__
for obj in iterable:
File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\Clip.py", line 475, in generator
frame = self.get_frame(t)
File "<decorator-gen-14>", line 2, in get_frame
File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\Clip.py", line 95, in get_frame
return self.make_frame(t)
File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\video\compositing\CompositeVideoClip.py", line 110, in make_frame
f = c.blit_on(f, t)
File "C:\Local\Programs\Python\Python35\lib\site-packages\moviepy\video\VideoClip.py", line 603, in blit_on
pos[0] = D[pos[0]]
KeyError: 'top'
I think you have your positioning reversed. Try this instead:
text = TextClip('Documentary Title', fontsize=5).set_position(('left', 'top'))
I use the following code to read two images, set their duration and concatenate them into one animation.
from moviepy.editor import *
ic_1 = ImageClip('pg_0.png')
ic_1 = ic_1.set_duration(2.0)
ic_2 = ImageClip('pg_1.png')
ic_2 = ic_2.set_duration(2.0)
video = concatenate([ic_1, ic_2], method="compose")
video.write_videofile('test.avi', fps=24, codec='mpeg4')
It works as expected for pg_0.png and pg_1.png. But f I replace these two images by another two images I get an error message:
ValueError: operands could not be broadcast together with shapes (272,363,3) (272,363)
If more details are needed, here is the complete message:
[MoviePy] >>>> Building video test.avi
[MoviePy] Writing video test.avi
|----------| 0/97 0% [elapsed: 00:00 left: ?, ? iters/sec]Traceback (most recent call last):
File "test2.py", line 12, in <module>
video.write_videofile('test.avi', fps=24, codec='mpeg4')
File "<string>", line 2, in write_videofile
File "/usr/local/lib/python2.7/dist-packages/moviepy/decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "<string>", line 2, in write_videofile
File "/usr/local/lib/python2.7/dist-packages/moviepy/decorators.py", line 137, in use_clip_fps_by_default
return f(clip, *new_a, **new_kw)
File "<string>", line 2, in write_videofile
File "/usr/local/lib/python2.7/dist-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
return f(clip, *a, **k)
File "/usr/local/lib/python2.7/dist-packages/moviepy/video/VideoClip.py", line 339, in write_videofile
ffmpeg_params=ffmpeg_params)
File "/usr/local/lib/python2.7/dist-packages/moviepy/video/io/ffmpeg_writer.py", line 204, in ffmpeg_write_video
fps=fps, dtype="uint8"):
File "/usr/local/lib/python2.7/dist-packages/tqdm.py", line 78, in tqdm
for obj in iterable:
File "/usr/local/lib/python2.7/dist-packages/moviepy/Clip.py", line 473, in generator
frame = self.get_frame(t)
File "<string>", line 2, in get_frame
File "/usr/local/lib/python2.7/dist-packages/moviepy/decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "/usr/local/lib/python2.7/dist-packages/moviepy/Clip.py", line 95, in get_frame
return self.make_frame(t)
File "/usr/local/lib/python2.7/dist-packages/moviepy/video/compositing/CompositeVideoClip.py", line 110, in make_frame
f = c.blit_on(f, t)
File "/usr/local/lib/python2.7/dist-packages/moviepy/video/VideoClip.py", line 571, in blit_on
return blit(img, picture, pos, mask=mask, ismask=self.ismask)
File "/usr/local/lib/python2.7/dist-packages/moviepy/video/tools/drawing.py", line 45, in blit
new_im2[yp1:yp2, xp1:xp2] = blitted
ValueError: operands could not be broadcast together with shapes (272,363,3) (272,363)
Why shapes are different? All images that I use look to me as normal png images. How can I resolve this problem?