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

How to remove original audio from the video file ? #504

Closed
batmanrising opened this issue Mar 22, 2017 · 5 comments
Closed

How to remove original audio from the video file ? #504

batmanrising opened this issue Mar 22, 2017 · 5 comments

Comments

@batmanrising
Copy link

Hi, currently I'm working on a hobby project.

I extracted small clips from a video and then concatenate them to create a new video file. Can we remove the audio from the original video file and add/merge any new audio/song file ?

@Zulko
Copy link
Owner

Zulko commented Mar 22, 2017

Yes, with set_audio:

import moviepy.editor as mpe

# ... create some concatenated clip
background_music = mpe.AudioFileClip("some_file.mp3")
new_clip = my_original_clip.set_audio(background_music)
new_clip.write_videofile("final_cut.mp4")

Audio clips could also be composed so you could add music on top of your video's sounds:

mixed_audio = mpe.CompositeAudioClip([background_music, my_original_clip.audio])
new_clip = my_original_clip.set_audio(mixed_audio)

@batmanrising
Copy link
Author

Hi, thanks for replying. I found it on your documentations page, but I didn't find anything related to masking or removing the original sound/audio from the video.

what I'm doing is, extracting few clips from videos and then concatenating them to make a new video, but as the concatenated video has clips, the sound/audio is not uniform, so now I want to remove that sound/audio from concatenated video and superimposing a new music.

@Zulko
Copy link
Owner

Zulko commented Mar 23, 2017

I don't understand, did you try the code I give in my answer and did it work ?
You just have to apply this code to your final clip (the concatenated clip).

@batmanrising
Copy link
Author

batmanrising commented Mar 23, 2017

Thanks a lot, it worked.
I tried this code just to check if it's working or not.

from moviepy.editor import VideoFileClip, AudioFileClip
import moviepy.editor as mpe
	
videoclip = VideoFileClip("testVideo.mp4")
background_music = mpe.AudioFileClip("testAudio.mp3")
new_clip = videoclip.set_audio(background_music)
new_clip.write_videofile("final_cut.mp4")

And I guess, I can do extra effects on audio using audio.fx (moviepy documentation)

@Zulko Zulko closed this as completed Mar 23, 2017
@batmanrising
Copy link
Author

Now, in the previous code, I was trying to add some audio effects. But I'm getting an error.

from moviepy.editor import VideoFileClip, AudioFileClip, concatenate_videoclips
import moviepy.editor as mpe
import moviepy.audio.fx.all as afx

videoClip = VideoFileClip("testVideo.mp4")
audioClip = mpe.AudioFileClip("testAudio.mp3")
newAudio = (audioClip.afx( vfx.volumex, 0.5).afx( vfx.audio_fadein, 3.0).afx( vfx.audio_fadeout, 3.0))
new_clip = videoclip.set_audio(newAudio)
new_clip.write_videofile("final_cut.mp4")

And the error is

Traceback (most recent call last):
File "tempVidAud1.py", line 9, in
newAudio = (audioClip.afx( vfx.volumex, 0.5).afx( vfx.audio_fadein, 3.0).afx( vfx.audio_fadeout, 3.0))
AttributeError: AudioFileClip instance has no attribute 'afx'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@Zulko @batmanrising and others