audio - 如何使用 ffmpeg 中的 libavcodec 将 opus 文件解码为 pcm 文件?
问题描述
我正在尝试使用 libavcodec 将 opus 解码为 pcm 文件。所以,我使用https://ffmpeg.org/doxygen/trunk/decode_audio_8c-example.html中的 ffmpeg 示例。我将 AV_CODEC_ID_MP2 更改为 AV_CODEC_ID_OPUS。但我收到错误消息。
codec = avcodec_find_decoder((AV_CODEC_ID_MP2);
codec = avcodec_find_decoder(AV_CODEC_ID_OPUS);
错误:
codec ./decode_audio ./out.opus ./out.pcm
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
所以我尝试将作品 AV_CODEC_ID_OPUS 更改为 AV_CODEC_ID_MP3 并重试。
codec ./decode_audio ./out.mp3 ./out.pcm
[mp3float @ 0x7fe564002000] Header missing
Error submitting the packet to the decoder
为什么 ffmpeg 中的示例会出错?我该怎么办?
解决方案
你不能用这种方式解码作品。Mp3 数据包是自定界的,opus 不是。这意味着 opus 需要一个容器(通常是 ogg)。必须解析该容器以确定您可以解码的 opus 数据包的开始和结束。libavformat
可用于从文件中读取 AVPackets。
推荐阅读
- stored-procedures - 为什么 sp_executesql 给出错误消息说必须声明标量变量?
- rest - Jenkinsfile/Groovy:为什么 curl 命令会导致“错误请求”
- ios - 成员“粗体()”需要“字体”类型的参数
- c# - 通过 SQL Server 数据库在 WPF 列表框中获取 System.NullReferenceException
- python - UDPClient.Send 到特定的 IP/Port 没有发送,也没有抛出异常
- ruby-on-rails - 想知道我做错了什么以及从这里去哪里
- java - 给定 Java 中输入请求的单词数,打印一个随机单词数组
- kubernetes - helm_release.teleport:等待状态变为“正在运行”时超时
- java - 向无效主题发送消息时,Spring Kafka 生产者中的无限循环
- javascript - IntelliJ IDEA 中类地图对象的 JSDoc 类型