views:

64

answers:

1

Hi to everybody,

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);
     aligned_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 ....
     }
 }

}

A: 

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.

Elfred
Yeap, I know, but I even try to save the stream "As-Is" t a file and isn't recognized as WMA, also using the raw audio to convert it to m4a something goes wrong because isn't recognized also as an m4a file.
c4r1o5
a WMA file is more than just a stream. There's headers and other things that are external to the string itself.
Elfred
That's right, I thing that the call to the av_write_header(mms_IOCtx); method, thanks
c4r1o5