Support
Quality
Security
License
Reuse
kandi has reviewed python-soundfile and discovered the below as its top functions. This is intended to give you an instant insight into python-soundfile implemented functionality, and help decide if they suit your requirements.
SoundFile is an audio library based on libsndfile, CFFI, and NumPy
Convert from opus to ogg file using ffmpeg [python soundfile]
# converting opus to ogg files for reading audio files with python soundfile
from glob import glob
from tqdm import tqdm
import soundfile as sf
import librosa
import os
for f in tqdm(glob("/Data/AUDIO_DATA/mls_dutch_opus/*/audio/*/*/*.opus") + glob("/Data/AUDIO_DATA/mls_german_opus/*/audio/*/*/*.opus")):
audio, sr = librosa.load(f, res_type='kaiser_fast', sr = 16000)
sf.write(f.replace(".opus", ".ogg"), audio, sr, format='ogg', subtype='vorbis')
os.remove(f)
-----------------------
ffmpeg -i input.opus -c:a vorbis -strict experimental output.ogg
ffmpeg -i input.opus -f wav - | oggenc -o output.ogg -
-----------------------
ffmpeg -i input.opus -c:a vorbis -strict experimental output.ogg
ffmpeg -i input.opus -f wav - | oggenc -o output.ogg -
QUESTION
Convert from opus to ogg file using ffmpeg [python soundfile]
Asked 2021-Sep-27 at 16:16I'm using python soundfile
to audio files in one of my projects. I have a dataset that contains opus
files.
python soundfile
can not read opus files directly but can read ogg files. (https://github.com/bastibe/python-soundfile/issues/252)
How can I convert all the opus files to ogg files with ffmpeg?
I have tried the following command,
ffmpeg -i test_file_2.opus -c:a libvorbis -b:a 16k test_file_2.ogg
But I get an error,
ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7.3.0 (crosstool-NG 1.23.0.449-a04d0)
configuration: --prefix=/opt/conda --cc=/opt/conda/conda-bld/ffmpeg_1597178665428/_build_env/bin/x86_64-conda_cos6-linux-gnu-cc --disable-doc --disable-openssl --enable-avresample --enable-gnutls --enable-hardcoded-tables --enable-libfreetype --enable-libopenh264 --enable-pic --enable-pthreads --enable-shared --disable-static --enable-version3 --enable-zlib --enable-libmp3lame
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
[ogg @ 0x55bad6b9cbc0] 543 bytes of comment header remain
Input #0, ogg, from 'test_file_2.opus':
Duration: 00:00:14.10, start: 0.000000, bitrate: 34 kb/s
Stream #0:0: Audio: opus, 48000 Hz, mono, fltp
Metadata:
album : Onder Moeders Vleugels
ENCODER_OPTIONS : --quiet
artist : Louisa May Alcott
title : 02 - Een vroolijk kerstfeest
encoder : opusenc from opus-tools 0.1.10;Lavf57.83.100
Unknown encoder 'libvorbis'
ANSWER
Answered 2021-Sep-27 at 11:13I'm using librosa right now for conversion, but this is extremely slow:
# converting opus to ogg files for reading audio files with python soundfile
from glob import glob
from tqdm import tqdm
import soundfile as sf
import librosa
import os
for f in tqdm(glob("/Data/AUDIO_DATA/mls_dutch_opus/*/audio/*/*/*.opus") + glob("/Data/AUDIO_DATA/mls_german_opus/*/audio/*/*/*.opus")):
audio, sr = librosa.load(f, res_type='kaiser_fast', sr = 16000)
sf.write(f.replace(".opus", ".ogg"), audio, sr, format='ogg', subtype='vorbis')
os.remove(f)
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Explore Related Topics