I improved my code. But I got some errors after creating the first clip (first clip was created sucessfully):
from moviepy.video.io.VideoFileClip import VideoFileClip
input_video_path = r"C:\Users\user\Downloads\shedevry.mp4"
#output_video_path = r"C:\Users\user\Downloads\out\out1.mp4"
output_path_format = r"C:\Users\user\Downloads\out\clip_{:01d}.mp4"
video = VideoFileClip(input_video_path)
#start_time = 1 * 60 + 20
#end_time = 5 * 60 + 30
time_slices = [
(0 * 60 + 0, 1 * 60 + 30),
(1 * 60 + 30, 2 * 60 + 10)
]
for i, (start_time, end_time) in enumerate(time_slices, start=1):
print("subclipped\n")
cut_video = video.subclipped(start_time, end_time)
output_video_path = output_path_format.format(i)
print("write_videofile\n")
cut_video.write_videofile(output_video_path, codec="libx264", audio_codec="aac")
cut_video.close()
video.close()
Errors:
MoviePy - Done !
MoviePy - video ready C:\Users\user\Downloads\out\clip_1.mp4
subclipped
Proc not detected
{'video_found': True, 'audio_found': True, 'metadata': {'major_brand': 'mp42', 'minor_version': '0', 'compatible_brands': 'isommp42', 'encoder': 'Google'}, 'inputs': [{'streams': [{'input_number': 0, 'stream_number': 0, 'stream_type': 'video', 'language': None, 'default': True, 'size': [640, 360], 'bitrate': 254, 'fps': 25.0, 'codec_name': 'h264', 'profile': '(Main)', 'metadata': {'handler_name': 'ISO Media file produced by Google Inc.'}}, {'input_number': 0, 'stream_number': 1, 'stream_type': 'audio', 'language': 'eng', 'default': True, 'fps': 44100, 'bitrate': 95, 'metadata': {'handler_name': 'ISO Media file produced by Google Inc.'}}], 'input_number': 0}], 'duration': 8053.93, 'bitrate': 352, 'start': 0.0, 'default_video_input_number': 0, 'default_video_stream_number': 0, 'video_codec_name': 'h264', 'video_profile': '(Main)', 'video_size': [640, 360], 'video_bitrate': 254, 'video_fps': 25.0, 'default_audio_input_number': 0, 'default_audio_stream_number': 1, 'audio_fps': 44100, 'audio_bitrate': 95, 'video_duration': 8053.93, 'video_n_frames': 201348}
C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\imageio_ffmpeg\binaries\ffmpeg-win64-v4.2.2.exe -ss 89.000000 -i C:\Users\user\Downloads\shedevry.mp4 -ss 1.000000 -loglevel error -f image2pipe -vf scale=640:360 -sws_flags bicubic -pix_fmt rgb24 -vcodec rawvideo -
write_videofile
MoviePy - Building video C:\Users\user\Downloads\out\clip_2.mp4.
MoviePy - Writing audio in clip_2TEMP_MPY_wvf_snd.mp4
chunk: 0%| | 0/883 [00:00<?, ?it/s, now=None]
chunk: 0%| | 2/883 [00:00<01:27, 10.10it/s, now=None]Traceback (most recent call last):
File "c:\Users\user\Desktop\python\main.py", line 24, in
cut_video.write_videofile(output_video_path, codec="libx264", audio_codec="aac")
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\decorators.py", line 53, in requires_duration
return func(clip, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\decorators.py", line 143, in use_clip_fps_by_default
return func(clip, *new_args, **new_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\decorators.py", line 24, in convert_masks_to_RGB
return func(clip, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\decorators.py", line 94, in wrapper
return func(*new_args, **new_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\video\VideoClip.py", line 379, in write_videofile
self.audio.write_audiofile(
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\decorators.py", line 53, in requires_duration
return func(clip, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\decorators.py", line 94, in wrapper
return func(*new_args, **new_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\audio\AudioClip.py", line 258, in write_audiofile
return ffmpeg_audiowrite(
^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\decorators.py", line 53, in requires_duration
return func(clip, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py", line 220, in ffmpeg_audiowrite
for chunk in clip.iter_chunks(
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\audio\AudioClip.py", line 112, in iter_chunks
yield self.to_soundarray(
^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\decorators.py", line 53, in requires_duration
return func(clip, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\audio\AudioClip.py", line 160, in to_soundarray
snd_array = self.get_frame(tt)
^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\decorators.py", line 94, in wrapper
return func(*new_args, **new_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\Clip.py", line 87, in get_frame
return self.frame_function(t)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\Clip.py", line 130, in
new_clip = self.with_updated_frame_function(lambda t: func(self.get_frame, t))
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\Clip.py", line 186, in
lambda get_frame, t: get_frame(time_func(t)),
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\decorators.py", line 94, in wrapper
return func(*new_args, **new_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\Clip.py", line 87, in get_frame
return self.frame_function(t)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 78, in
self.frame_function = lambda t: self.reader.get_frame(t)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\audio\io\readers.py", line 235, in get_frame
self.buffer_around(fr_max)
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\audio\io\readers.py", line 281, in buffer_around
array = self.read_chunk(chunksize)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\audio\io\readers.py", line 155, in read_chunk
s = self.proc.stdout.read(self.nchannels * chunksize * self.nbytes)
^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'stdout'
[Done] exited with code=1 in 50.54 seconds