Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

video artifacts and audio mismatch #1134

Closed
maikeeb opened this issue Apr 5, 2020 · 8 comments
Closed

video artifacts and audio mismatch #1134

maikeeb opened this issue Apr 5, 2020 · 8 comments
Labels
bug Issues that report (apparent) bugs.

Comments

@maikeeb
Copy link

maikeeb commented Apr 5, 2020

The following code opens a folder of videos with a naming convention of: order# videoname transition(1)/video(0)

ex. 100surfing1

then concatenates them all together into one video.

This also only keeps adding them until the videos add up to 10 minutes.

from moviepy.editor import *
import os
from natsort import natsorted
from datetime import date

def compile(name):
    L = []

    for root, dirs, files in os.walk("../currentVideos"):

        # files.sort()
        files = natsorted(files)
        for file in files:
            print(file)
            if os.path.splitext(file)[1] == '.mp4':
                filePath = os.path.join(root, file)
                video = VideoFileClip(filePath)
                L.append(video)
    L.reverse()
    currentVideo = []
    currentVideoLength = 0
    while currentVideoLength <= 600:
        print("Clips left from the collection grabbed: " + str(len(L)/2), "Current video length from clips currently selected: ", currentVideoLength)
        currentVideo.append(L[0])
        currentVideo.append(L[1])
        L.remove(L[0])
        L.remove(L[0])
        currentVideoLength = 0
        for videoo in currentVideo:
            currentVideoLength += videoo.duration
    final_clip = concatenate_videoclips(currentVideo)
    final_clip.to_videofile(
        "/home/maiku/Desktop/montage maker/fullVideos/%s.mp4" % name,
        fps=60, remove_temp=True)


if __name__ == '__main__':
    compile(str(date.today()))

Expected Behavior

One big video which is 10 minutes which is made out of transition, video, transition, video....

Actual Behavior

It does make this video but there are video artifacts halfway through and audio is mismatched halfway through.

Steps to Reproduce the Problem

You need to have a folder full of videos that at least add up to 10 minutes. And an output folder which stores finished videos.

Im using mp4's as the videos, if that means anything.

Specifications

  • Python Version: 3.7.4
  • Moviepy Version: 1.0.2
  • Platform Name: linux ubuntu
  • Platform Version: 19.10
@maikeeb maikeeb changed the title video artifacts and audio artifacts video artifacts and audio mismatch Apr 5, 2020
@tburrows13
Copy link
Collaborator

Presumably the transition is just another video file, nothing special about it?

Your code looks fine, I can't see an obvious reason as to why you'd be getting this behaviour.

Are all input files the same width and height? If they are not then you might want to use method="compose" in concatenate_videoclips().

Since you are not doing any fancy movie editing techniques, you could try doing it directly using method 2 in this Stack Overflow answer. This avoids re-encoding the videos as well so there should not be a drop in quality. You could use python to call the command with a specific list of input files.

Sticking with moviepy, I'd suggest not concatenating all the files together at once. Try making smaller clips, and then concatenating them together at the end. Or you could write the smaller ones to a file, then read them back in and concatenate them together and write out the full one at the end. This shouldn't be necessary but it might work.

Does the artefacts and audio mismatch occur on the same video every time, or is it solely based on the time from the start? Providing an example of the output video (and the inputs) would help.

@tburrows13 tburrows13 added the bug Issues that report (apparent) bugs. label Apr 5, 2020
@maikeeb
Copy link
Author

maikeeb commented Apr 5, 2020

Compilation of twitch clips

here is a video I posted on youtube

the artifacts happen at random intervals but if I redownload the clips and then re-concatenating them together I get the same artifacts but if I use different clips the artifacts can be different or not there at all.

For method 2 in the example given is shown how to do it with a console, how would do this python. I am trying to automate the proccess.

@maikeeb
Copy link
Author

maikeeb commented Apr 5, 2020

All the clips are 1080p 60 fps.

@tburrows13
Copy link
Collaborator

I'd suggest trying concatenating them with method="compose". It shouldn't matter if they are actually all 1920x1080, but I think that the results are consistent with what I remember forgetting method="compose" looks like.

@maikeeb
Copy link
Author

maikeeb commented Apr 6, 2020

When using final_clip = concatenate_videoclips(currentVideo,method='compose') it gives me this error

Moviepy - Building video /home/maiku/Desktop/offlinetvv montage maker/fullVideos/offlinetv2020-04-06.mp4.
MoviePy - Writing audio in offlinetv2020-04-06TEMP_MPY_wvf_snd.mp3
chunk:   1%|▏                   | 124/13517 [00:00<00:10, 1238.92it/s, now=None]Traceback (most recent call last):
  File "oneVideo.py", line 39, in <module>
    compile('offlinetv' + str(date.today()))
  File "oneVideo.py", line 35, in compile
    fps=60, remove_temp=True)
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/tools.py", line 137, in fdepr
    return f(*a, **kw)
  File "<decorator-gen-55>", line 2, in write_videofile
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "<decorator-gen-54>", line 2, in write_videofile
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/decorators.py", line 135, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "<decorator-gen-53>", line 2, in write_videofile
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/video/VideoClip.py", line 298, in write_videofile
    logger=logger)
  File "<decorator-gen-45>", line 2, in write_audiofile
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 210, in write_audiofile
    logger=logger)
  File "<decorator-gen-9>", line 2, in ffmpeg_audiowrite
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/audio/io/ffmpeg_audiowriter.py", line 169, in ffmpeg_audiowrite
    logger=logger):
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 86, in iter_chunks
    fps=fps, buffersize=chunksize)
  File "<decorator-gen-44>", line 2, in to_soundarray
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 127, in to_soundarray
    snd_array = self.get_frame(tt)
  File "<decorator-gen-11>", line 2, in get_frame
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 297, in make_frame
    for c, part in zip(self.clips, played_parts)
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/audio/AudioClip.py", line 298, in <listcomp>
    if (part is not False)]
  File "<decorator-gen-11>", line 2, in get_frame
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/audio/io/AudioFileClip.py", line 77, in <lambda>
    self.make_frame = lambda t: self.reader.get_frame(t)
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/audio/io/readers.py", line 185, in get_frame
    self.buffer_around(fr_max)
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/audio/io/readers.py", line 239, in buffer_around
    array = self.read_chunk(chunksize)
  File "/home/maiku/.local/lib/python3.7/site-packages/moviepy/audio/io/readers.py", line 113, in read_chunk
    s = self.proc.stdout.read(L)
AttributeError: 'NoneType' object has no attribute 'stdout'

@maikeeb
Copy link
Author

maikeeb commented Apr 6, 2020

I found the same issue here:
#938

I am trying this solution:

pip install moviepy==1.0.0

bug fixed!

@tburrows13
Copy link
Collaborator

Ok, if everything is working now can we close this issue?

That is definitely a bug that will be fixed in the next version, as it seems to be affecting a lot of users.

@maikeeb
Copy link
Author

maikeeb commented Apr 6, 2020

Yea the code works now and I get the proper output, thank you.

@maikeeb maikeeb closed this as completed Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs.
Projects
None yet
Development

No branches or pull requests

2 participants