Moviepy: CompositeVideoClip has no audio

Created on 27 Nov 2018  路  18Comments  路  Source: Zulko/moviepy

Expected Behavior

The video file generated at end of the process with orignal audio.

Actual Behavior

The video file generated at end of the process has no audio.

Steps to Reproduce the Problem

def add_watermark_logo(video_filename):
    """
    Adds the logo as watermark to the video, given its filename.
    :param video_url: String containing the video filename.
    :return:
    """

    video = mp.VideoFileClip(video_filename)
    logo = (mp.ImageClip("logo.png")
              .set_duration(video.duration)
              .resize(height=50)
              .margin(right=10, bottom=10, opacity=0)
              .set_pos(("right", "bottom")))

    final = mp.CompositeVideoClip([video, logo])
    final.write_videofile("{}".format(video_filename), progress_bar=False)

Specifications

  • Python Version: 3.6
  • Moviepy Version: 0.2.3.5
  • Platform Name: Docker on MacOs 10.13.6
  • Platform Version: 18.06.1-ce-mac73 (26764)
audio

Most helpful comment

i remove the '-an' and it did work

All 18 comments

I was looking at the ffmpeg_writer.py class of theFFMPEG_VideoWriter class and found -an option here. Following the ffmpeg documentation, this option disables audio even if I set audio as True in write_videofile method of VideoClip class.

Is a bug or I'm completely wrong?

  • It seems that your script is writing over the video it is reading. You shouldn't do that, I'm not even sure how it can work. use final.write_videofile("MODIFIED_" + video_filename). It could be a source of the problem, not sure.

  • Have you tried reading the video with different readers, like VLC ? One possibility is that there is sound, but the audio codec used by default is incompatible with your reader.

  • Regarding -an, I won't have time to look into it soon, but that would be worrying. @Julian-O you added this line, do you know if -an could cause no audio ?

@Zulko: I was the last to edit, but I didn't add this line. (I did review my changes to double-check this.)

The last-edit of that part of the code was four years ago, but the "-an" option has existed since at least 2013, when ffmpeg_writer.py was spun-off from writers.py.

I haven't tested, but, it sounds completely plausible that passing -an would cause no audio.
I wouldn't have expected a codec change. [Edit after next comment: I stand corrected!]
Testing with a different filename sounds like the first step though.

Thank you @Zulko!

I did a test reading the output video into VLC and audio works. Do you know what is an audio codec works to QuickTime?

i remove the '-an' and it did work

Thanks for the hints: I'm fairly certain I ran into the same issue today (after running moviepy without issues in the past). I recently updated my python version, most packages and ffmpeg, so I cannot pinpoint where the change came from, but the -an flag seems to be the problem.

I suspect the idea is to block potential audio from the video input (and to explicitly attach audio as a separate input file). However, to achieve that, the argument order should have been: '-an', '-i', '-',, not '-i', '-', '-an',. The latter binds the -an flag to the next stream, which is the audio file (which is subsequently ignored).

I'm also not sure if it is even possible for audio to be accidentally fed into ffmpeg through the raw video input from moviepy...it seems unlikely.

i remove the '-an' and it did work

Thank you, i'v been having that issue since for ever until i read ur reply

Thank you @Zulko!

I did a test reading the output video into VLC and audio works. Do you know what is an audio codec works to QuickTime?

I also have this problem. When i changed '-i', '-', '-an' to '-an', '-i', '-', the output video into VLC and audio works, but no audio in QuickTime.

Python: 3.6.3
Moviepy: 0.2.3.5
OS: MacOS 10.14.3

I found the solution in other issue #820

I found the solution in other issue #820

Thank you @russellyi , it works here!!
Great!!

Same Here But Where is Solution?

edit file moviepy/video/io/ffmpeg_writer.py and remove the '-an' here
you can have a try @amantiwari1

import moviepy.editor as mp

for i in range(1,666):
videov = "D:/instavideo/comdy/Part" + str(i) + ".mp4"
text = "Instagram -@videoeverything"
edit = "D:/instavideo/comdyedit/Edit"+ str(i) + ".mp4"
logopic = "V1.png"
music = "D:/instavideo/comdyeditmusic/Part1 .mp3"

clip = mp.VideoFileClip(videov)
time = clip.duration
logo = (mp.ImageClip(logopic)
      .set_duration(time)
      .resize(height=75) # if you need to resize...
      .margin(right=8, top=8, opacity=0) # (optional) logo-border padding
      .set_pos(("right","top")))

txt_clip = mp.TextClip(text, fontsize = 30, color = "white")
txt_clip = txt_clip.set_pos('bottom').set_duration(time)
clip_resized = clip.resize(height=720)
video = mp.CompositeVideoClip([clip_resized,txt_clip,logo])
video.write_videofile(edit)

write_videofile has no Sound.. What should i add?

i remove the '-an' and it did work

changing to this order
'-an','-i', '-',
worked for me. sound is back.
issue #820 didn't fix the problem.

thank you

Linking #968 here as a fix.

Should be fixed in #968.

Specifying an audio_codec while writing the file was sufficient to make it work for me, e.g.,

video.write_videofile(edit, audio_codec='aac')
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bilel picture bilel  路  4Comments

Gicehajunior picture Gicehajunior  路  3Comments

LaoYuanPython picture LaoYuanPython  路  3Comments

arianaa30 picture arianaa30  路  4Comments

bobozar picture bobozar  路  4Comments