I\'ve succesfully used ffmpeg in Python to convert mp3-files into wav so I can post them to Google Speech-To-Text. Now I have same situation with webm files and the old function
No need to convert to WAV then do a separate command to segment. Just remove -c copy
and do it all in one command:
def convert_and_split(filename):
command = ['ffmpeg', '-i', filename, '-f', 'segment', '-segment_time', '15', 'out%09d.wav']
subprocess.run(command,stdout=subprocess.PIPE,stdin=subprocess.PIPE)
-c copy
enables stream copy mode. It is like a copy and paste, but you can't put Opus audio into WAV. Removing -c copy
will allow ffmpeg to convert Opus to WAV.
You need to convert to pcm data:
ffmpeg -i ./big-buck-bunny_trailer.webm -c:a pcm_f32le ./out.wav
Output:
ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 11.0.3 (clang-1103.0.32.59)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.3 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags=-fno-stack-check --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, matroska,webm, from './big-buck-bunny_trailer.webm':
Metadata:
encoder : http://sourceforge.net/projects/yamka
creation_time : 2010-05-20T08:21:12.000000Z
Duration: 00:00:32.48, start: 0.000000, bitrate: 533 kb/s
Stream #0:0(eng): Video: vp8, yuv420p(progressive), 640x360, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
Stream #0:1(eng): Audio: vorbis, 44100 Hz, mono, fltp (default)
Stream mapping:
Stream #0:1 -> #0:0 (vorbis (native) -> pcm_f32le (native))
Press [q] to stop, [?] for help
Output #0, wav, to './out.wav':
Metadata:
ISFT : Lavf58.29.100
Stream #0:0(eng): Audio: pcm_f32le ([3][0][0][0] / 0x0003), 44100 Hz, mono, flt, 1411 kb/s (default)
Metadata:
encoder : Lavc58.54.100 pcm_f32le
size= 5597kB time=00:00:32.50 bitrate=1410.7kbits/s speed= 625x
video:0kB audio:5597kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.001989%