首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用ffmpeg [python原文件]从opus转换为ogg文件

使用ffmpeg [python原文件]从opus转换为ogg文件
EN

Stack Overflow用户
提问于 2021-09-27 07:03:18
回答 2查看 2.7K关注 0票数 2

我正在使用python soundfile在我的一个项目中使用音频文件。我有一个包含opus文件的数据集。

python不能直接读取soundfile文件,但可以读取ogg文件。(https://github.com/bastibe/python-soundfile/issues/252)

如何用ffmpeg将所有的opus文件转换为ogg文件?

我试过以下命令,

代码语言:javascript
复制
 ffmpeg -i test_file_2.opus -c:a libvorbis -b:a 16k test_file_2.ogg

但我犯了个错误

代码语言:javascript
复制
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'
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-09-27 16:16:27

未知编码器'libvorbis‘

您的ffmpeg没有libvorbis的支持。它在--enable-libvorbis行中缺少了configure。libvorbis是输出Vorbis音频格式的音频编码器。Vorbis是OGG/OGA容器中通常使用的音频格式。libvorbis是推荐的Vorbis音频编码器。

找到一个具有--enable-libvorbis或重新编译ffmpeg的新版本/包,并包括以下内容。

实验vorbis编码器

FFmpeg有一个名为vorbis的内置编码器,但它被认为是实验性的,不能与libvorbis相比。如果你关心质量,就用利沃比来代替。如果你想试试vorbis:

代码语言:javascript
复制
ffmpeg -i input.opus -c:a vorbis -strict experimental output.ogg

或者给oggenc的烟斗

代码语言:javascript
复制
ffmpeg -i input.opus -f wav - | oggenc -o output.ogg -
票数 1
EN

Stack Overflow用户

发布于 2021-09-27 11:13:35

我现在正在使用librosa进行转换,但是这非常慢:

代码语言:javascript
复制
# 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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69342452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档