【问题标题】:Unable to overwrite FFMPEG's encoder tag无法覆盖 FFMPEG 的编码器标签
【发布时间】:2020-05-20 11:36:59
【问题描述】:

我正在用 python 编写一个调用 ffmpeg 的小脚本,该脚本运行良好,但我无法阻止 FFMPEG 用它自己的“Lavf58.29.100”编码器覆盖编码器标签。

我尝试使用 FFPROBE 将输入属性捕获为变量并将源编码器显式写入编码器标签,但它仍然在输出文件上使用“Lavf58.29.100”进行转码。

import subprocess

file = 'File_in.wav'

attributes = subprocess.Popen(['ffprobe', file], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)

for x in attributes.stdout.readlines():
    x = x.decode(encoding='utf-8')
    if 'Stream' in x:
        bit_depth = x[24:33]

    if 'encoder' in x:
        encoder = x[22:-1]

subprocess.call(['ffmpeg', '-i', file, '-af', 'areverse', '-c:a', bit_depth, '-metadata:s:a', 'encoder=' + encoder, 'File_out.wav'])

这是python之外的ffmpeg命令:

ffmpeg -i 'File_in.wav' -af areverse -c:a pcm_s24le -metadata:s:a encoder='WaveLab Pro 10.0.10' 'File_out.wav'

来自 MediaInfo:

源文件 - “Encoded_Application”:“WaveLab Pro 10.0.10”

输出文件 - “Encoded_Application”:“Lavf58.29.100”

维护文件出处非常重要,因此我不能更改源元数据。有谁知道解决这个问题的方法? FFMPEG 似乎接受其他属性,但不接受编码器标签。

【问题讨论】:

    标签: python ffmpeg metadata


    【解决方案1】:

    据我发现,在 ffmpeg 中无法更改此默认行为 - 解决此问题的唯一方法是在 ffmpeg 完成处理后使用 BWF MetaEdit 重新编写输入编码器。

    import os
    import glob
    import subprocess
    
    dir = os.getcwd()
    os.makedirs(f'{dir}/_reversed', exist_ok=True)
    rev_out = dir + r'/_reversed'
    
    get_files = glob.glob(dir + '/*.wav')
    
    def reverse_file():
        for i in get_files:
            file = i
            get_filename = os.path.splitext(str(i))[0]
            filename_only = os.path.basename(get_filename)
    
            attributes = subprocess.Popen(['ffprobe', file], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
    
        for x in attributes.stdout.readlines():
            x = x.decode(encoding='utf-8')
            if 'encoder' in x:
                encoder = x[22:-1]
    
            if 'Stream' in x:
                bit_depth = x[24:33]
    
        subprocess.call(['ffmpeg', '-i', file, '-af', 'areverse', '-c:a', bit_depth, rev_out + '/' + filename_only + '.wav'])
    
        subprocess.call(['bwfmetaedit', rev_out + '/' + filename_only + '.wav', '-a', '--ISFT=' + encoder])
    
    reverse_file()
    

    也在这里 - https://github.com/realgoodegg/FFMPEG-batch-reverse

    【讨论】:

      猜你喜欢
      • 2013-11-09
      • 2017-09-19
      • 2019-07-30
      • 2015-01-29
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多