[Libav-user] 答复: Decoding opus
He Lei
helei0908 at hotmail.com
Wed Jan 11 17:42:44 EET 2017
Sorry, I only speak a little English;
You mean to say, the decoded frame->pkt_size is same as packet->size ?
But, the frame->pkt_size == packet->size,it is true; You need to look at annotation of AVFrame;
If you want get the Frame data size, that is frame->linesize[x];
if the decoded data of audio is plane, frame->data[n] is n th channel data of samples;
frame->nb_channels is num of channels;
frame->nb_samples is num of samples;
//can get all data length like this:
int iDataLen = 0;
for(int i=0; i< frame->nb_channels; ++i)
{
iDataLen +=frame->linesize[i];
}
uint8 * pData = frame->data[0];// it is continuous of all channel data;
may be a better way,but I do not know…..
if it is not plane, only frame->data[0], and frame->linesize[0] is the length;
________________________________
发件人: Libav-user <libav-user-bounces at ffmpeg.org> 代表 Aboobeker Sidhik Koyamparambil mammu <aboosidhik at gmail.com>
发送时间: 2017年1月11日 14:27
收件人: This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter.
主题: Re: [Libav-user] Decoding opus
No. I get the same data that I send to decoder. Not the uncompressed data (pcm) as output. In my case single frame in a single AV packet size. This I checked using a while loop that compares the packet size.
Regards
Aboo
On 11 January 2017 at 14:23, He Lei <helei0908 at hotmail.com<mailto:helei0908 at hotmail.com>> wrote:
do you say ,you write same packet to decoder, and get frame more then in packet?
look at anntation as avcodec_decode_audio4();
that is:
4643 * Some decoders may support multiple frames in a single AVPacket. Such
4644 * decoders would then just decode the first frame and the return value would be
4645 * less than the packet size. In this case, avcodec_decode_audio4 has to be
4646 * called again with an AVPacket containing the remaining data in order to
4647 * decode the second frame, etc... Even if no frames are returned, the packet
4648 * needs to be fed to the decoder with remaining data until it is completely
4649 * consumed or an error occurs.
4650 *
good luck
发自我的 iPhone
在 2017年1月11日,20:08,Aboobeker Sidhik Koyamparambil mammu <aboosidhik at gmail.com<mailto:aboosidhik at gmail.com>> 写道:
Dear All,
I am trying to decode opus. When I use both methods
avcodec_decode_audio4 and (avcodec_send_packet /avcodec_receive_frame) . I am receiving the same opus packet that I send for decoding. I got this by using the packet size of the decoded frame. Packet size is same as the input opus packet size.
I followed the decoding example given in github of ffmpeg. Please help me. Why I am receiving same packet as input?
av_register_all();
avcodec_register_all();
AVCodec *codec;
AVCodecContext *c = NULL;
AVPacket avpkt;
AVFrame *decoded_frame = NULL;
av_init_packet(&avpkt);
codec = avcodec_find_decoder(AV_CODEC_ID_OPUS);
if (!codec) {
printf("Codec not found\n");
exit(1);
}
c = avcodec_alloc_context3(codec);
if (!c) {
printf("Could not allocate audio codec context\n");
exit(1);
}
/* put sample parameters */
c->sample_rate = 48000;
c->request_sample_fmt = AV_SAMPLE_FMT_FLT;
c->channels = 2;
/* open it */
if (avcodec_open2(c, codec, NULL) < 0) {
printf("Could not open codec\n");
exit(1);
}
AVPacket avpkt;
AVFrame *decoded_frame = NULL;
av_init_packet(&avpkt);
avpkt.data = Buffer; // Buffer is packet data here
avpkt.size = len; // length of the packet
int i, ch;
if (!decoded_frame) {
if (!(decoded_frame = av_frame_alloc())) {
RELAY_SERVER_PRINT("Could not allocate audio frame\n");
exit(1);
}
}
int ret;
int got_frame = 0;
ret = avcodec_decode_audio4(client_sockt_num_1->c, decoded_frame, &got_frame, &avpkt);
if (ret < 0) {
fprintf(stderr, "Error decoding audio frame (%s)\n", av_err2str(ret));
return ret;
}
printf("length %i\n", decoded_frame->pkt_size);
--
Kind Regards
Aboobeker Sidhik
_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org<mailto:Libav-user at ffmpeg.org>
http://ffmpeg.org/mailman/listinfo/libav-user
_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org<mailto:Libav-user at ffmpeg.org>
http://ffmpeg.org/mailman/listinfo/libav-user
--
Kind Regards
Aboobeker Sidhik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20170111/fd60c5c3/attachment.html>
More information about the Libav-user
mailing list