Embedding Audio File to Video

Viewed 25

I had a special .wav file with some encodings in it and i want to insert this into video file. I tried this with moviepy using the following method but it doesn't helped me as the audio get distorted.

import moviepy
from moviepy.editor import VideoFileClip, AudioFileClip, CompositeAudioClip, concatenate_audioclips


if __name__ == "__main__":
audio_file = f'audios/a1.wav'
    video_file = f'videos/v1.mp4'
    audio_clip = AudioFileClip(audio_file)
    video_clip = VideoFileClip(video_file)

    final_audio = CompositeAudioClip([video_clip.audio, audio_clip])
    video_clip.write_videofile(f'results/out.mp4')
    video_clip.close()
    audio_clip.close()

nothing with ffmpeg as:

import ffmpeg

if __name__ == "__main__":
    video = ffmpeg.input(f'videos/v1.mp4').video  # get only video channel
    audio = ffmpeg.input(f'audios/a1.wav').audio  # get only audio channel
    output = ffmpeg.output(video, audio, f'results/output.mp4', vcodec='copy', acodec='aac', strict='experimental')
    ffmpeg.run(output)

although I can extract the perfect mp3 file using pydub, but again inserting this into video distort the audio. it may due to miss match of fps or something else. The pydub stuff is as follows:

import pydub
from pydub import AudioSegment

audio_file = f'audios/a1.wav'
sound = pydub.AudioSegment.from_mp3(audio_file)
sound.export("results/apple.mp3", format="wav")

can anyone here to guide me with the correct method.

Thanks in advance.

0 Answers
Related