如何使用ffmpeg的libavcodec将opus文件解码为pcm文件? [英] How do I decode opus file to pcm file using libavcodec from ffmpeg?

查看:263
本文介绍了如何使用ffmpeg的libavcodec将opus文件解码为pcm文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用libavcodec将opus解码为pcm文件.因此,我使用来自

I am trying to decode opus to pcm file using libavcodec.So,I use ffmpeg example from https://ffmpeg.org/doxygen/trunk/decode_audio_8c-example.html .And I change AV_CODEC_ID_MP2 to AV_CODEC_ID_OPUS.But I get an error.

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,然后重试.

So I try to change opus AV_CODEC_ID_OPUS to AV_CODEC_ID_MP3 and try again.

    codec ./decode_audio ./out.mp3 ./out.pcm            
    [mp3float @ 0x7fe564002000] Header missing
    Error submitting the packet to the decoder

为什么ffmpeg的示例出现错误?我该怎么办?

Why does the example from ffmpeg get error?What should I do ?

推荐答案

您不能以这种方式解码作品. mp3数据包是自定界的,opus不是.这意味着作品需要一个容器(通常是ogg).必须对该容器进行解析,以确定可以解码的opus数据包的开始和结束. libavformat可用于从文件读取AVPackets.

You can't decode opus this way. Mp3 packets are self-delimiting, opus is not. Which means that opus requires a container (usually ogg). That container must be parsed to determine the start and end of an opus packet that you can then decode. libavformat can be used to read AVPackets from the file.

这篇关于如何使用ffmpeg的libavcodec将opus文件解码为pcm文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆