lmmx / tap

dex ⠶ tap – an audio transcriber for web radio
MIT License
1 stars 0 forks source link

Use ffmpeg-python #1

Closed lmmx closed 3 years ago

lmmx commented 3 years ago

After pulling the MP4 stream from its URLs, the M4S files are concatenated into a single output and convert to WAV at 16 kHz:

for x in assets/*.dash assets/*.m4s; do cat $x >> output.mp4; done
ffmpeg -i output.mp4 -ar 16000 -ac 2 -f wav output.wav

Currently this must be done on the command line manually, but I’d like to use ffmpeg-python

It’s not clear whether the first step can be done with FFMPEG (this Q&A suggests there are problems).

You could just wrap it in subprocess.call

for x in assets/*.dash assets/*.m4s; do cat $x >> output.mp4; done

becomes

import subprocess
subprocess.call([
    'for x in assets/*.dash assets/*.m4s; do cat $x >> output.mp4; done'.split()
])

The second step (converting to WAV) can be done as:

import ffmpeg
mp4, wav = 'output.mp4', 'output.wav'
ffmpeg.input(mp4).output(wav, ac=2, ar='16k', format='wav').run()
lmmx commented 3 years ago

https://github.com/lmmx/tap/blob/9532ba7c93a83b7b2e3c42c228c66d396ea9d16f/src/tap/preproc/merge.py#L5-L36

https://github.com/lmmx/tap/blob/9532ba7c93a83b7b2e3c42c228c66d396ea9d16f/src/tap/preproc/format_conversion.py#L3-L12