• ffmpeg 调节视频声音大小


    1、查看视频声音信息

      ffmpeg -nostats -i D:OTT est.mp4 -filter_complex ebur128 -f null -

      

    def get_video_audio():
        command = 'ffmpeg -nostats -i D:/OTT/test.mp4 -filter_complex ebur128 -f null -'
        result = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        info = result.stdout.read()
        print(info.decode('utf-8'))

    2、调节声音大小:

      降低音量是输入音量的一半:

      ffmpeg -i input.wav -filter:a "volume=0.5" output.wav

      当前音量的 150%:

      ffmpeg -i input.wav -filter:a "volume=1.5" output.wav

      降低test.mp4文件声音10分贝, volume=-10dB   ; volume=10dB:增大10分贝

      ffmpeg -i D:OTT est.mp4 -af volume=-10dB -y D:OTTout.mp4 

     降低视频样本声音
    def down_video_audio(videodir,outdir,downvalue=10):
        file_list = os.listdir(videodir)
        os.makedirs(outdir, exist_ok=True)
        count = len(file_list)
        for line_index, file in enumerate(file_list):
            print('当前进度: {}/{}'.format(line_index + 1, count))
            fileName = os.path.join(videodir, file)
            outfile = os.path.join(outdir, file)
            down_audio(fileName, outfile, downvalue)
    
        print(file_list)
    
    
    # 调节视频声音大小
    def down_audio(sourcfile, outfile,downvalue):
        '''
        使用ffmpeg进行视频的声音大小调节
        :param sourcfile: 源文件
        :param outfile:输出文件
        :param downvalue:增加或减少的分贝值,10 增加10分贝,-10:减少10分贝
        :return:
        '''
        # 把视频的声音降低10分贝
        # 应用命令: ffmpeg -i D:OTT	est.mp4 -af volume=-10dB -y D:OTTout.mp4
        cmd = 'ffmpeg -i {} -af volume={}dB -y {}'.format(sourcfile, downvalue, outfile)
        flag = os.system(cmd)
    
        if flag == 0:
            return True
        return False
    
    if __name__ == '__main__':
        # control_process()
        videodir='D:/OTT/5秒钟样本/20210301'
        outdir='D:/OTT/5秒钟样本修改声音/20210301'
        down_video_audio(videodir, outdir)
  • 相关阅读:
    C语言学习019:函数指针
    C语言学习018:strdup复制字符串数组
    C语言学习017:malloc和free
    C语言学习016:单链表
    C语言学习015:联合(union)与枚举(enum)
    C语言学习014:结构化数据类型
    C语言学习013:通过make编译C源代码
    C语言学习012:将代码文件分成多个文件
    C语言学习011:带参数的main函数
    C语言学习010:fopen读写文件
  • 原文地址:https://www.cnblogs.com/shaosks/p/15010686.html
Copyright © 2020-2023  润新知