0

relatively new python user here. I'm trying to use moviepy to splice up 5 min long videos into 8-second bits. I used the code in this thread to extract subclips and it works. I did the following to make it a loop that covers the whole video, but I only get one 8-sec video as an output:

from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
videopath = '../img/videos/Mopac+Cesarchavez-1.m4v'

for sec in videopath:
    sec = 0
    ffmpeg_extract_subclip(videopath, sec, sec+8.00, "../img/videos/subclips/testclip.mp4")
    if sec == 327:
        break

Do I need to specify a naming convention so that my output isn't just one video? How would I do that?

  • Was the 8-second choice something you have any control over? It would mean less quality loss if you found the frequency of keyframes your original movie was encoded with and split along those positions, letting you reuse the original encoding work instead of doing another lossy encoding pass and losing quality in the process. – Charles Duffy Sep 18 '20 at 20:03
  • (of course, assuming you _actually do_ the work of reusing the original bitstream) – Charles Duffy Sep 18 '20 at 20:07
  • 1
    anyhow, as for the code you posted... how is `for sec in videopath` supposed to work at all? `videopath` is a string; when you iterate over it you get the characters in that string. So right now, _for each character_ in the name of the file, you're splitting out the first 8 seconds, then repeating it again for the next character (again extracting only those same 8 seconds!) – Charles Duffy Sep 18 '20 at 20:08
  • 1
    Consider `for sec in range(0, 327, 8):`, and getting rid of the `sec=0`. – Charles Duffy Sep 18 '20 at 20:10

0 Answers0