Tom
Tom

Reputation: 31

Unable to overwrite FFMPEG's encoder tag

I'm writing a small script in python that calls ffmpeg, the script works fine but I'm unable to prevent FFMPEG from overwriting the encoder tag with it's own 'Lavf58.29.100' encoder.

I tried capturing the input attributes as a varible using FFPROBE and explicitly writing the source encoder to the encoder tag, but it still transcodes with 'Lavf58.29.100' on the output file.

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'])

Here is the ffmpeg command outside of python:

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

From MediaInfo:

Souce file - "Encoded_Application": "WaveLab Pro 10.0.10"

Output file - "Encoded_Application": "Lavf58.29.100"

Maintaining file provenace is very important so I can't have the source metadata changed. Does anyone know a way around this? FFMPEG seems to accept other attributes but not the encoder tag.

Upvotes: 0

Views: 819

Answers (1)

Tom
Tom

Reputation: 31

From what I found this default behaviour can't be changed in ffmpeg - the only way around it is to use BWF MetaEdit to re-write the input encoder, after ffmpeg has finished processing.

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()

Also here - https://github.com/realgoodegg/FFMPEG-batch-reverse

Upvotes: 1

Related Questions