68115

How do I decode opus file to pcm file using libavcodec from ffmpeg?

<h3>Question</h3>

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);

error:

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.

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

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


<h3>Answer1:</h3>

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.

来源:https://stackoverflow.com/questions/62155671/how-do-i-decode-opus-file-to-pcm-file-using-libavcodec-from-ffmpeg

Recommend

  • How do I decode opus file to pcm file using libavcodec from ffmpeg?
  • Arduino Iot Project parseObject() failed
  • zero length variadic expansion of ill-formed call
  • Scala: how to make a Hash(Trie)Map from a Map (via Anorm in Play)
  • Strange behaviour of regex in R
  • Making ModelAttribute optional in Spring Controller method
  • Intellij IDEA Breakpoints stop in JARs instead of source code of my project
  • phpunit - Help needed about risky tests
  • RxJS Angular2 handling 404 in Observable.forkjoin
  • Vim cannot save to temporary files created by python
  • How to deserialize a dictionary using DataContractJsonSerializer?
  • Discover latest versions of Composer packages when dependencies are locked
  • Fetching CloudWatch metrics using the AWS Java SDK?
  • .NET constant for number of seconds in a day?
  • Is there any way to test my conversions to avoid using exceptions?
  • The Url of dialog box does not work with angular.bootstrap (infinite $digest Loop)
  • how to get selected index of dropdownbutton in flutter
  • How to use (primitive) autoboxing/widening with Hamcrest?
  • How does Simulink simulation engine work?
  • C++ Initialize array pointer
  • Python - Print Each Sentence On New Line
  • Google Maps V3 - Resizing Map and Sporadic Map Tile Loading
  • Building Ruby 1.9.3 on Lion with Xcode 4.2 using ./configure --with-gcc=clang
  • Using QThread and QTimer to run a methode
  • How to create a graph and its schema without using Datastax Studio but through Java?
  • Auto-incrementation with HSQLDB (2.2.8) + DDLUtils
  • ARKit – Rendering a 3D object under an invisible plane
  • Two instances of blur.js possible?
  • Spring Cloud Config - Multiple Composite Repositories?
  • Excel Reverse Match
  • Java .policy file - how to prevent java.util.Date() from being accessible
  • Possible to set default CloudKit container not based on application name?
  • using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was ma
  • concise way of flattening multiindex columns
  • gnuplot - How to make zmin equal to zmax keeeping autoscale on z axis
  • Change cell value based on cell color in google spreadsheet
  • How do I add a mouse over tooltip to an Image using .DrawImage()
  • Google App Engine Datastore: Dealing with eventual consistency
  • ssh remote server login script
  • How to call different template for different category archive page in woocommerce