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

Inconsistent duration for composite output #2148

Open
ncugit-sec opened this issue Mar 30, 2024 · 1 comment
Open

Inconsistent duration for composite output #2148

ncugit-sec opened this issue Mar 30, 2024 · 1 comment
Labels
bug Issues that report (apparent) bugs.

Comments

@ncugit-sec
Copy link

The generated audio appears to be padded with the last few points of the source audio, even if no operations are performed on it.

Expected Behavior

CompositeAudioClip or CompositeVideoClip should generate output with consistent duration if no operation related to duration editting is made.

Actual Behavior

The duration of CompositeAudioClip generate a longer duration than input file.

Steps to Reproduce the Problem

random.mp4
# using above audio file
from moviepy.editor import *

audio = AudioFileClip('random.mp4')
audio.write_audiofile('tmp.mp3')

Generated duration are longer than source audio.

$ ffprobe random.mp3 
Input #0, mp3, from 'random.mp3':
  Metadata:
    encoder         : Lavf58.76.100
  Duration: 00:00:05.07, start: 0.025057, bitrate: 128 kb/s
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc58.13
$ ffprobe tmp.mp3 
Input #0, mp3, from 'tmp.mp3':
  Metadata:
    encoder         : Lavf58.29.100
  Duration: 00:00:05.12, start: 0.025057, bitrate: 128 kb/s
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc58.54

Specifications

  • Python Version: 3.11.4
  • MoviePy Version: 1.0.3
  • Platform Name: Ubuntu
  • Platform Version: 22.04
@ncugit-sec ncugit-sec added the bug Issues that report (apparent) bugs. label Mar 30, 2024
@Cyberghost999
Copy link

It is due to incorrect reporting of audio length by ffmpeg. This causes moviepy to read frame outside of the audio which results in artifact being added towards the end of the audio. I fixed this issue by taking subclip of the audio file by audio_clip = audio_clip.subclip(0, audio_clip.duration - 0.05) or you can define the audio path while writing the final clip. You can also refer #1936 for alternate solutions.

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