How to preserve audio when transcoding

This transcodes video only passing through the original audio.

Original ffmpeg goes to ffmpeg.org. Here is the new ffmpeg

#!/usr/bin/python3
import sys
import os
FFMPEG = '../latest/ffmpeg.org'
old = '-c:a aac -ac 2 -b:a 192k -filter:a aresample=async=1'
new = '-c:a copy'
args = list(sys.argv)
oldl = old.split()
newl = new.split()
idx = 0
while idx + len(oldl) <= len(args):
    if args[idx:idx+len(oldl)] == oldl:
        args[idx:idx+len(oldl)] = newl
        break
    idx += 1

os.execv(FFMPEG, args)

Do not forget to:

chmod +x ffmpeg

Take 2:
This avoids not only transcoding audio but also transcoding SD videos with horizontal resolution of 480

#!/usr/bin/python3
import sys
import os

def idx(l, e):
    return l.count(e) and l.index(e)

FFMPEG = '{}.org'.format(sys.argv[0])
args = list(sys.argv)
idxv = idx(args, '-c:v')
idxf = idx(args, '-filter:v')
idxa = idx(args, '-c:a')
idxs = idx(args, '-c:s')
if 0 < idxv < idxf < idxa < idxs:
    args[idxa+1:idxs] = ['copy']
    hres = args[idxf+1][-4:-1]
    if hres == '480':
        args[idxv+1:idxa] = ['copy']

os.execv(FFMPEG, args)

Please Note for others trying this

Using this will cause browser-based and app-based playback to fail in some situations.

This is quite possible. I am testing on Apple TV and Amazon Firestick. Works fine on these two.

The second version doesn't affect web based playback since web based playback doesn't include subtitles :wink:
I guess all's well.