Output video has no sound

后端 未结 2 1818
忘了有多久
忘了有多久 2021-01-14 09:23

When I concatenate videos in Moviepy I get no sound in the output file, I try using various parameters but no clue.

This is my code:

import moviepy.         


        
相关标签:
2条回答
  • 2021-01-14 09:53

    I solved this by adding a temporary audio file path. Just change your final line of code to this:

    final_clip.write_videofile(output_movie, temp_audiofile='temp-audio.m4a', remove_temp=True, codec="libx264", audio_codec="aac")
    

    You're specifying where MoviePy can store its temp audio file. Also, change the parameter remove_temp to True so the temp file will be cleaned up automatically.

    0 讨论(0)
  • 2021-01-14 09:58

    I solved this through a workaround using ffmpeg directly. It uses the temp audio file and video file from moviepy to create a final file. I found that moviepy 1.0.1 does not call ffmpeg with the right arguments to combine the video and audio for mp4 video. This link helped me with ffmpeg:https://superuser.com/questions/277642/how-to-merge-audio-and-video-file-in-ffmpeg

    final_clip.write_videofile(moviepy_outfile, temp_audiofile=temp_audiofile,codec="libx264",remove_temp=False,audio_codec='aac')
    
    import subprocess as sp
    
    command = ['ffmpeg',
               '-y', #approve output file overwite
               '-i', str(moviepy_outfile),
               '-i', str(temp_audiofile),
               '-c:v', 'copy',
               '-c:a', 'copy',
               '-shortest', 
               str(output_movie) ]
    
    with open(ffmpeg_log, 'w') as f:
        process = sp.Popen(command, stderr=f)
    
    0 讨论(0)
提交回复
热议问题