开发者

Using FFMPEG Audio conversion in the iPhone

开发者 https://www.devze.com 2023-01-04 20:32 出处:网络
I\'m using ffmpeg in the iPhone, reading an wma stream from an mms server, but I want to save the stream to an m4a file using the ALAC encoder in ffmpeg, the problem is that trying to save the raw str

I'm using ffmpeg in the iPhone, reading an wma stream from an mms server, but I want to save the stream to an m4a file using the ALAC encoder in ffmpeg, the problem is that trying to save the raw stream, the stream processed using avcodec_decode_audio2 , the file is not even recognized with the wma format, and obviously, not played, so before convert the stream to m4a (using avcodec_encode_audio) I want to be sure that the streaming is being processed and saved correctly. Anyone had experiencie doing this kind of stuff ? thanks

P.S. I'm writing the bytes buffer using CFWriteStreamWrite, and everything seems to be ok.

My code :

while (av_read_frame(mms_IOCtx, &_packet) >= 0) {
 if (_packet.stream_index == audioStreamIdx) {
     uint8_t *_packetData = _packet.data;
     int _packetSize = _packet.size;

     // Align output buffer
     uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2 + 16];
     int16_t *aligned_buffer;
     size_t buffer_size;
     int audio_size, len;
     buffer_size = sizeof(audio_buf);
     aligne开发者_JS百科d_buffer = align16(audio_buf, &buffer_size);

     while (currentState != STATE_CLOSED && (_packetSize > 0)) {
         audio_size = buffer_size;
         len = avcodec_decode_audio2(mms_CodecCtx, aligned_buffer, &audio_size, _packetData, _packetSize);
         // call to the method that write the bytes ....
     }
 }

}


After decoding, it is no longer a WMA stream, it's a raw audio stream. If you want to write the WMA stream, you'd write out the data before decoding.

0

精彩评论

暂无评论...
验证码 换一张
取 消