Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.07k stars 1.51k forks source link

Calibrate nchunks of iter_chunks function #2092

Open yyz561 opened 5 months ago

yyz561 commented 5 months ago

Suppose I have an audio file containing 100 frames, fps is 10, and I want to split it into 10 chunks evenly using iter_chunks function:

def iter_chunks(self, chunksize=None, chunk_duration=None, fps=None,
                    quantize=False, nbytes=2, logger=None):

Intuitively, I would set chunksize as 10, then what I will get currently?

chunk 0, tt [0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8] chunk 1, tt [0.9 1. 1.1 1.2 1.3 1.4 1.5 1.6 1.7] chunk 2, tt [1.8 1.9 2. 2.1 2.2 2.3 2.4 2.5 2.6] chunk 3, tt [2.7 2.8 2.9 3. 3.1 3.2 3.3 3.4 3.5] chunk 4, tt [3.6 3.7 3.8 3.9 4. 4.1 4.2 4.3 4.4] chunk 5, tt [4.5 4.6 4.7 4.8 4.9 5. 5.1 5.2 5.3] chunk 6, tt [5.4 5.5 5.6 5.7 5.8 5.9 6. 6.1 6.2] chunk 7, tt [6.3 6.4 6.5 6.6 6.7 6.8 6.9 7. 7.1] chunk 8, tt [7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8. ] chunk 9, tt [8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9] chunk 10, tt [9. 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9]

Apparently it is not what I want, by simply changing one line of code: from nchunks = totalsize // chunksize + 1 to nchunks = (totalsize + chunksize - 1) // chunksize, we get:

chunk 0, tt [0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9] chunk 1, tt [1. 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9] chunk 2, tt [2. 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9] chunk 3, tt [3. 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9] chunk 4, tt [4. 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9] chunk 5, tt [5. 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9] chunk 6, tt [6. 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9] chunk 7, tt [7. 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9] chunk 8, tt [8. 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9] chunk 9, tt [9. 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9]

Can you fix this issue?