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

CompositeVideoClip has no audio #876

Closed
marceloandriolli opened this issue Nov 27, 2018 · 19 comments
Closed

CompositeVideoClip has no audio #876

marceloandriolli opened this issue Nov 27, 2018 · 19 comments
Labels
audio Related to AudioClip, or handling of audio in general.

Comments

@marceloandriolli
Copy link

marceloandriolli commented Nov 27, 2018

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)
@marceloandriolli
Copy link
Author

I was looking at the ffmpeg_writer.py class of the FFMPEG_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?

@Zulko
Copy link
Owner

Zulko commented Nov 29, 2018

  • 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 ?

@Julian-O
Copy link
Contributor

@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.

@Julian-O
Copy link
Contributor

Julian-O commented Nov 29, 2018

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.

@marceloandriolli
Copy link
Author

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?

@keikoro keikoro added the audio Related to AudioClip, or handling of audio in general. label Dec 16, 2018
@haigendong
Copy link

i remove the '-an' and it did work

@Sv3n
Copy link

Sv3n commented Feb 9, 2019

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.

@Baronsindo
Copy link

i remove the '-an' and it did work

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

Sv3n added a commit to Sv3n/moviepy that referenced this issue Feb 25, 2019
The old order binds the `-an` flag to the next stream, which is the audio
file (which is subsequently ignored).
@russellyi
Copy link

russellyi commented Feb 28, 2019

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

@russellyi
Copy link

I found the solution in other issue #820

@marceloandriolli
Copy link
Author

I found the solution in other issue #820

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

@amantiwari1
Copy link

Same Here But Where is Solution?

@Jiangfeng-Xiong
Copy link

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

@amantiwari1
Copy link

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?

@jpinela
Copy link

jpinela commented Feb 14, 2020

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

@tburrows13
Copy link
Collaborator

Linking #968 here as a fix.

@tburrows13
Copy link
Collaborator

Should be fixed in #968.

@alessio-signorini
Copy link

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')

@rtfmanual
Copy link

  • 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.

VLC still the way to go in 2022!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audio Related to AudioClip, or handling of audio in general.
Projects
None yet
Development

No branches or pull requests