0

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]

figura
  • 9
  • 2
  • You are using an audio effect on a video, hence why it isn’t working. Try vfx.loop (although I seem to remember that it was a bit broken... there are open PRs on GitHub to fix it). – Tom Burrows Dec 08 '20 at 09:17
  • @TomBurrows I tried: `from moviepy.editor import * clip = VideoFileClip('VID_20201207_022713542.mp4').fx(vfx.loop, n = 2) clip.write_videofile("output.mp4")` and received an error message that I'll update in the question – figura Dec 09 '20 at 01:20
  • ok that is a known bug with a fix: https://github.com/Zulko/moviepy/pull/1373 – Tom Burrows Dec 09 '20 at 08:24
  • @TomBurrows, so moviepy is not able to do this at this point? I should try another way – figura Dec 09 '20 at 13:56
  • you can just copy the fixed version from that pull request and use it directly – Tom Burrows Dec 11 '20 at 12:45
  • Thanks, I'll make a try! – figura Dec 13 '20 at 22:17
  • Did not worked, the file was bigger but something was not correct. I'm not sure if I could not place things on the correct places, also the resolution of the output file changed. – figura Jan 04 '21 at 22:41

2 Answers2

0

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.

HansLee
  • 43
  • 6
-1

to slow down you can use

ffmpeg -i YOUR_INPUT_MOVIE.mp4 -vf  "setpts=5*PTS" YOUR_OUTPUT_MOVIE.mp4
Akshay Sehgal
  • 18,741
  • 3
  • 21
  • 51
Ecstashar
  • 31
  • 6
  • 2
    This question is tagged [tag:python] and [tag:moviepy], I'm not sure a solution with [tag:ffmpeg] will help the question asker or really be appropriate. – Ian Campbell Dec 08 '20 at 04:52
  • 1
    I think ffmpeg is appropriate, as you can easily call it from inside python (that’s how moviepy works under the hood anyway!). However, the question is asking for looping, not slowing down. – Tom Burrows Dec 08 '20 at 09:16