<div><br></div><div><div><br></div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ 原始邮件 ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>发件人:</b> "坚定前行";<powerpan@qq.com>;</div><div><b>发送时间:</b> 2017年5月19日(星期五) 上午9:13</div><div><b>收件人:</b> "libav-user"<libav-user@ffmpeg.org>; <wbr></div><div></div><div><b>主题:</b> [Libav-user] 回复: 回复: 回复: 回复: just wanna get a decode demo for libav</div></div><div><br></div><div><br></div><div><div><br></div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ 原始邮件 ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>发件人:</b> "坚定前行";<powerpan@qq.com>;</div><div><b>发送时间:</b> 2017年5月13日(星期六) 下午5:30</div><div><b>收件人:</b> "libav-user"<libav-user@ffmpeg.org>; <wbr></div><div></div><div><b>主题:</b> [Libav-user] 回复: 回复: 回复: just wanna get a decode demo for libav</div></div><div><br></div><div><br></div><div><div><br></div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ 原始邮件 ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>发件人:</b> "lingjiujianke";<lingjiujianke@gmail.com>;</div><div><b>发送时间:</b> 2017年5月13日(星期六) 上午6:44</div><div><b>收件人:</b> "This list is about using libavcodec, libavformat, libavutil,libavdevice and libavfilter."<libav-user@ffmpeg.org>; <wbr></div><div><b>抄送:</b> "ggarra13"<ggarra13@gmail.com>; <wbr></div><div><b>主题:</b> Re: [Libav-user]回复: 回复: just wanna get a decode demo for libav</div></div><div><br></div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2017-05-13 0:05 GMT+08:00 Steven Liu <span dir="ltr"><<a href="mailto:lingjiujianke@gmail.com" target="_blank">lingjiujianke@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="gmail-">2017-05-12 21:53 GMT+08:00 坚定前行 <span dir="ltr"><<a href="mailto:powerpan@qq.com" target="_blank">powerpan@qq.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Hi, </div><div><br></div><div>thanks for the reply but your answer didn't help. first of all, i need to register a codec and open it automatically, but decode_audio.c did not show the right way.</div><div>second, I copied a third party demo, it works well but still have some warning for the OLD API and decode_audio.c did not use the latest API to demostrate what ffmpeg suggest to do. I need a perfect demo, anybody could help?</div></blockquote></span><div>1. 别在邮件的最上面回复内容,最好在最下面回复</div><div>2. 你是怎么跑的demo代码,全部过程能否详细描述一下</div><div>3. decode_audio.<wbr>c里面是用的最新的API做音频解码的,不包含demux操作,<wbr>仅仅是解码,而且是音频解码</div><div>4. 最好还是把你的全部过程和你的代码贴出来,大伙才好确认问题</div><div><br></div><div>除了1,  另外三点应该能得到你想要的答复,这个是api使用的列表,<wbr>估计能得到你想要的答复的可能性不大,<wbr>因为大伙不知道你怎么做的,不知道你代码实现,<wbr>如果能够按照我说的三点做一下,也许有结果。</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-"><div><br></div><div>Best regards,</div><div>pp</div><div><br></div><div><br></div><div><div><br></div><div><br></div><div style=" font-size:12px ; ;;padding:2px 0px ">------------------ 原始邮件 ------<wbr>------------</div><div style="font-size:12px;background:rgb(239,239,239);padding:8px"><div><b>发件人:</b> "Gonzalo Garramuño";<<a href="mailto:ggarra13@gmail.com" target="_blank">ggarra13@gmail.com</a><wbr>>;</div><div><b>发送时间:</b> 2017年5月12日(星期五) 晚上9:15</div><div><b>收件人:</b> "This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter."<<a href="mailto:libav-user@ffmpeg.org" target="_blank">libav-user@ffmpe<wbr>g.org</a>>; </div><div></div><div><b>主题:</b> Re: [Libav-user]回复: just wanna get a decode demo for libav</div></div><div><div class="gmail-m_7620127003235985566h5"><div><br></div>
  
    
  
  
    <p><br>
    </p>
    <br>
    <div class="gmail-m_7620127003235985566m_-2695723922228370470moz-cite-prefix">El 12/05/17 a las 07:25, 坚定前行 escribió:<br>
    </div>
    <blockquote type="cite">
      <div>Hi, </div>
      <div>
        <div><br>
        </div>
        <div>that's the demo I tried </div>
        <div>
          <div style="line-height:21px">with warning 'avcodec_decode_audio4<wbr>'
            is deprecated.</div>
          <div style="line-height:21px">and that demo could not work
            with : Codec not found.</div>
        </div>
        <div style="line-height:21px"><br>
        </div>
        <div style="line-height:21px">Best regards,</div>
        <div style="line-height:21px">pp<br>
        </div>
      </div>
    </blockquote>
    Usually, if you get "codec not found" it means your ffmpeg
    compilation was lacking a certain codec.  The audio example uses
    mpeg2 audio, so you need to have ffmpeg compiled with mpeg2.<br>
    You can check the codecs you have by doing:<br>
    <br>
    $ ffmpeg -codecs<br>
    <br>
    For it to work, you should have a line like:<br>
    <br>
     DEA.L. mp2                  MP2 (MPEG audio layer 2) (decoders: mp2
    mp2float ) (encoders: mp2 mp2fixed )<br>
    <br>
    <br></div></div></div><br></span><span class="gmail-">______________________________<wbr>_________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/list<wbr>info/libav-user</a><br>
<br></span></blockquote></div><br></div></div>
</blockquote></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">给你一段diff 参考一下:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">diff --git a/doc/examples/demuxing_decoding.c b/doc/examples/demuxing_decoding.c</div><div class="gmail_extra">index b1a216abb4..3c5190c28b 100644</div><div class="gmail_extra">--- a/doc/examples/demuxing_decoding.c</div><div class="gmail_extra">+++ b/doc/examples/demuxing_decoding.c</div><div class="gmail_extra">@@ -60,6 +60,84 @@ static int audio_frame_count = 0;</div><div class="gmail_extra">  * needs. Look for the use of refcount in this example to see what are the</div><div class="gmail_extra">  * differences of API usage between them. */</div><div class="gmail_extra"> static int refcount = 0;</div><div class="gmail_extra">+static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize,</div><div class="gmail_extra">+                     char *filename)</div><div class="gmail_extra">+{</div><div class="gmail_extra">+    FILE *f;</div><div class="gmail_extra">+    int i;</div><div class="gmail_extra">+</div><div class="gmail_extra">+    f = fopen(filename,"w");</div><div class="gmail_extra">+    fprintf(f, "P5\n%d %d\n%d\n", xsize, ysize, 255);</div><div class="gmail_extra">+    for (i = 0; i < ysize; i++)</div><div class="gmail_extra">+        fwrite(buf + i * wrap, 1, xsize, f);</div><div class="gmail_extra">+    fclose(f);</div><div class="gmail_extra">+}</div><div class="gmail_extra">+</div><div class="gmail_extra">+static void decode_video(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame,</div><div class="gmail_extra">+                   const char *filename)</div><div class="gmail_extra">+{</div><div class="gmail_extra">+    char buf[1024];</div><div class="gmail_extra">+    int ret;</div><div class="gmail_extra">+</div><div class="gmail_extra">+    ret = avcodec_send_packet(dec_ctx, pkt);</div><div class="gmail_extra">+    if (ret < 0) {</div><div class="gmail_extra">+        fprintf(stderr, "Error sending a packet for decoding\n");</div><div class="gmail_extra">+        exit(1);</div><div class="gmail_extra">+    }</div><div class="gmail_extra">+</div><div class="gmail_extra">+    while (ret >= 0) {</div><div class="gmail_extra">+        ret = avcodec_receive_frame(dec_ctx, frame);</div><div class="gmail_extra">+        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)</div><div class="gmail_extra">+            return;</div><div class="gmail_extra">+        else if (ret < 0) {</div><div class="gmail_extra">+            fprintf(stderr, "Error during decoding\n");</div><div class="gmail_extra">+            exit(1);</div><div class="gmail_extra">+        }</div><div class="gmail_extra">+</div><div class="gmail_extra">+        printf("saving frame %3d\n", dec_ctx->frame_number);</div><div class="gmail_extra">+        fflush(stdout);</div><div class="gmail_extra">+</div><div class="gmail_extra">+        /* the picture is allocated by the decoder. no need to</div><div class="gmail_extra">+           free it */</div><div class="gmail_extra">+        snprintf(buf, sizeof(buf), "%s-%d", filename, dec_ctx->frame_number);</div><div class="gmail_extra">+        pgm_save(frame->data[0], frame->linesize[0],</div><div class="gmail_extra">+                 frame->width, frame->height, buf);</div><div class="gmail_extra">+    }</div><div class="gmail_extra">+}</div><div class="gmail_extra">+</div><div class="gmail_extra">+</div><div class="gmail_extra">+static void decode_audio(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)</div><div class="gmail_extra">+{</div><div class="gmail_extra">+    int i, ch;</div><div class="gmail_extra">+    int ret, data_size;</div><div class="gmail_extra">+</div><div class="gmail_extra">+    /* send the packet with the compressed data to the decoder */</div><div class="gmail_extra">+    ret = avcodec_send_packet(dec_ctx, pkt);</div><div class="gmail_extra">+    if (ret < 0) {</div><div class="gmail_extra">+        fprintf(stderr, "Error submitting the packet to the decoder\n");</div><div class="gmail_extra">+        exit(1);</div><div class="gmail_extra">+    }</div><div class="gmail_extra">+</div><div class="gmail_extra">+    /* read all the output frames (in general there may be any number of them */</div><div class="gmail_extra">+    while (ret >= 0) {</div><div class="gmail_extra">+        ret = avcodec_receive_frame(dec_ctx, frame);</div><div class="gmail_extra">+        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)</div><div class="gmail_extra">+            return;</div><div class="gmail_extra">+        else if (ret < 0) {</div><div class="gmail_extra">+            fprintf(stderr, "Error during decoding\n");</div><div class="gmail_extra">+            exit(1);</div><div class="gmail_extra">+        }</div><div class="gmail_extra">+        data_size = av_get_bytes_per_sample(dec_ctx->sample_fmt);</div><div class="gmail_extra">+        if (data_size < 0) {</div><div class="gmail_extra">+            /* This should not occur, checking just for paranoia */</div><div class="gmail_extra">+            fprintf(stderr, "Failed to calculate data size\n");</div><div class="gmail_extra">+            exit(1);</div><div class="gmail_extra">+        }</div><div class="gmail_extra">+        for (i = 0; i < frame->nb_samples; i++)</div><div class="gmail_extra">+            for (ch = 0; ch < dec_ctx->channels; ch++)</div><div class="gmail_extra">+                fwrite(frame->data[ch] + data_size*i, 1, data_size, outfile);</div><div class="gmail_extra">+    }</div><div class="gmail_extra">+}</div><div class="gmail_extra"><br></div><div class="gmail_extra"> static int decode_packet(int *got_frame, int cached)</div><div class="gmail_extra"> {</div><div class="gmail_extra">@@ -69,73 +147,9 @@ static int decode_packet(int *got_frame, int cached)</div><div class="gmail_extra">     *got_frame = 0;</div><div class="gmail_extra"><br></div><div class="gmail_extra">     if (pkt.stream_index == video_stream_idx) {</div><div class="gmail_extra">-        /* decode video frame */</div><div class="gmail_extra">-        ret = avcodec_decode_video2(video_dec_ctx, frame, got_frame, &pkt);</div><div class="gmail_extra">-        if (ret < 0) {</div><div class="gmail_extra">-            fprintf(stderr, "Error decoding video frame (%s)\n", av_err2str(ret));</div><div class="gmail_extra">-            return ret;</div><div class="gmail_extra">-        }</div><div class="gmail_extra">-</div><div class="gmail_extra">-        if (*got_frame) {</div><div class="gmail_extra">-</div><div class="gmail_extra">-            if (frame->width != width || frame->height != height ||</div><div class="gmail_extra">-                frame->format != pix_fmt) {</div><div class="gmail_extra">-                /* To handle this change, one could call av_image_alloc again and</div><div class="gmail_extra">-                 * decode the following frames into another rawvideo file. */</div><div class="gmail_extra">-                fprintf(stderr, "Error: Width, height and pixel format have to be "</div><div class="gmail_extra">-                        "constant in a rawvideo file, but the width, height or "</div><div class="gmail_extra">-                        "pixel format of the input video changed:\n"</div><div class="gmail_extra">-                        "old: width = %d, height = %d, format = %s\n"</div><div class="gmail_extra">-                        "new: width = %d, height = %d, format = %s\n",</div><div class="gmail_extra">-                        width, height, av_get_pix_fmt_name(pix_fmt),</div><div class="gmail_extra">-                        frame->width, frame->height,</div><div class="gmail_extra">-                        av_get_pix_fmt_name(frame->format));</div><div class="gmail_extra">-                return -1;</div><div class="gmail_extra">-            }</div><div class="gmail_extra">-</div><div class="gmail_extra">-            printf("video_frame%s n:%d coded_n:%d\n",</div><div class="gmail_extra">-                   cached ? "(cached)" : "",</div><div class="gmail_extra">-                   video_frame_count++, frame->coded_picture_number);</div><div class="gmail_extra">-</div><div class="gmail_extra">-            /* copy decoded frame to destination buffer:</div><div class="gmail_extra">-             * this is required since rawvideo expects non aligned data */</div><div class="gmail_extra">-            av_image_copy(video_dst_data, video_dst_linesize,</div><div class="gmail_extra">-                          (const uint8_t **)(frame->data), frame->linesize,</div><div class="gmail_extra">-                          pix_fmt, width, height);</div><div class="gmail_extra">-</div><div class="gmail_extra">-            /* write to rawvideo file */</div><div class="gmail_extra">-            fwrite(video_dst_data[0], 1, video_dst_bufsize, video_dst_file);</div><div class="gmail_extra">-        }</div><div class="gmail_extra">+        decode_video(video_dec_ctx, &pkt, frame, video_dst_filename);</div><div class="gmail_extra">     } else if (pkt.stream_index == audio_stream_idx) {</div><div class="gmail_extra">-        /* decode audio frame */</div><div class="gmail_extra">-        ret = avcodec_decode_audio4(audio_dec_ctx, frame, got_frame, &pkt);</div><div class="gmail_extra">-        if (ret < 0) {</div><div class="gmail_extra">-            fprintf(stderr, "Error decoding audio frame (%s)\n", av_err2str(ret));</div><div class="gmail_extra">-            return ret;</div><div class="gmail_extra">-        }</div><div class="gmail_extra">-        /* Some audio decoders decode only part of the packet, and have to be</div><div class="gmail_extra">-         * called again with the remainder of the packet data.</div><div class="gmail_extra">-         * Sample: fate-suite/lossless-audio/luckynight-partial.shn</div><div class="gmail_extra">-         * Also, some decoders might over-read the packet. */</div><div class="gmail_extra">-        decoded = FFMIN(ret, pkt.size);</div><div class="gmail_extra">-</div><div class="gmail_extra">-        if (*got_frame) {</div><div class="gmail_extra">-            size_t unpadded_linesize = frame->nb_samples * av_get_bytes_per_sample(frame->format);</div><div class="gmail_extra">-            printf("audio_frame%s n:%d nb_samples:%d pts:%s\n",</div><div class="gmail_extra">-                   cached ? "(cached)" : "",</div><div class="gmail_extra">-                   audio_frame_count++, frame->nb_samples,</div><div class="gmail_extra">-                   av_ts2timestr(frame->pts, &audio_dec_ctx->time_base));</div><div class="gmail_extra">-</div><div class="gmail_extra">-            /* Write the raw audio data samples of the first plane. This works</div><div class="gmail_extra">-             * fine for packed formats (e.g. AV_SAMPLE_FMT_S16). However,</div><div class="gmail_extra">-             * most audio decoders output planar audio, which uses a separate</div><div class="gmail_extra">-             * plane of audio samples for each channel (e.g. AV_SAMPLE_FMT_S16P).</div><div class="gmail_extra">-             * In other words, this code will write only the first audio channel</div><div class="gmail_extra">-             * in these cases.</div><div class="gmail_extra">-             * You should use libswresample or libavfilter to convert the frame</div><div class="gmail_extra">-             * to packed data. */</div><div class="gmail_extra">-            fwrite(frame->extended_data[0], 1, unpadded_linesize, audio_dst_file);</div><div class="gmail_extra">-        }</div><div class="gmail_extra">+        decode_audio(audio_dec_ctx, &pkt, frame, audio_dst_file);</div><div class="gmail_extra">     }</div><div class="gmail_extra"><br></div><div class="gmail_extra">     /* If we use frame reference counting, we own the data and need</div><div class="gmail_extra"><br></div><div class="gmail_extra">code tested and found that's not fully implemented. cause FFMPEG could decode all the codecs but our new code couldn't, "codec not found" is the biggest problem. had to use old function like what FFMPEG.c did.</div><div class="gmail_extra"><br></div><div class="gmail_extra">seem that still there is a long way to go to fully migrate old API to new one. will keep my eye open on that. or I could provide a music sample dir by cloud.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">and while decoding mp4/avi files:</div><div class="gmail_extra"><div class="gmail_extra">[mp3 @ 0x21911c0] Header missing</div><div class="gmail_extra">Error submitting the packet to the decoder</div><div class="gmail_extra">pkt->size=418</div><div class="gmail_extra">pkt->size=16830</div><div class="gmail_extra">[mp3 @ 0x21911c0] Header missing</div><div class="gmail_extra">Error submitting the packet to the decoder</div><div class="gmail_extra">pkt->size=418</div><div class="gmail_extra">pkt->size=418</div><div class="gmail_extra">pkt->size=5709</div><div class="gmail_extra">[mp3 @ 0x21911c0] Header missing</div><div class="gmail_extra">Error submitting the packet to the decoder</div><div class="gmail_extra">pkt->size=418</div><div class="gmail_extra">pkt->size=418</div><div class="gmail_extra">pkt->size=5674</div><div><br></div><div><br></div><div><div>pkt->size=523</div><div>pkt->size=12011</div><div>[aac @ 0x25acdc0] Number of bands (18) exceeds limit (3).</div><div>Error submitting the packet to the decoder</div><div>pkt->size=10188</div><div>[aac @ 0x25acdc0] Number of bands (18) exceeds limit (3).</div><div>Error submitting the packet to the decoder</div><div>pkt->size=12088</div><div>[aac @ 0x25acdc0] Number of bands (18) exceeds limit (3).</div><div>Error submitting the packet to the decoder</div><div>pkt->size=6528</div><div>[aac @ 0x25acdc0] Number of bands (18) exceeds limit (3).</div><div>Error submitting the packet to the decoder</div><div>pkt->size=5970</div><div>[aac @ 0x25acdc0] Number of bands (18) exceeds limit (3).</div><div>Error submitting the packet to the decoder</div><div>pkt->size=7716</div><div>[aac @ 0x25acdc0] Number of bands (18) exceeds limit (3).</div><div>Error submitting the packet to the decoder</div><div>pkt->size=10040</div><div>[aac @ 0x25acdc0] Number of bands (18) exceeds limit (3).</div><div>Error submitting the packet to the decoder</div><div>pkt->size=7718</div><div>[aac @ 0x25acdc0] Number of bands (18) exceeds limit (3).</div><div>Error submitting the packet to the decoder</div><div>pkt->size=510</div><div>pkt->size=511</div><div>pkt->size=515</div><div>pkt->size=510</div><div>pkt->size=495</div></div><div><br></div></div></div></div></div></div></div>