<div dir="ltr">Hi,<div><br></div><div>I'm trying to create a function that will output the following information for a H.264 stream:</div><div><br></div><div><div>Frame_type: I ; pkt_size: 67839 ; qp_min=26 ; qp_max=38; qp_avg=30</div><div>Frame_type: P ; pkt_size: 2060 ; qp_min=30 ; qp_max=41; qp_avg=35<br></div><div>Frame_type: P ; pkt_size: 2469 ; qp_min=30 ; qp_max=38; qp_avg=35</div><div>Frame_type: P ; pkt_size: 3956 ; qp_min=30 ; qp_max=38; qp_avg=35</div></div><div>:</div><div>.</div><div><br></div><div>My current code is based upon ffmpeg/doc/examples/demuxing_decoding.c</div><div>Getting the frame type and the pkt_size is no problem but I cannot find a way to get the</div><div>qp-values!</div><div><br></div><div>If I enable debug using `-debug qp`, the qp values gets written to the log in function</div><div>ff_print_debug_info2() in libavcodec/mpegvideo.v:2258</div><div>That function is called from h264_decode_frame() in libavcodec/h264.c:1834 <br></div><div><br></div><div>But I fail to find a way to get the qp-values for a frame from my function.</div><div>Any help would be greatly appreciated!</div><div><br></div><div>My function currently looks like this:</div><div><br></div><div><div>static int decode_packet(int *got_frame, int cached)</div><div>{</div><div>    int ret = 0;</div><div>    int decoded = pkt.size;</div><div>    int x, y;</div><div>    int mb_width = (video_dec_ctx->width + 15) / 16;</div><div>    int mb_height = (video_dec_ctx->height + 15) / 16;</div><div>    int mb_stride = mb_width + 1;</div><div><br></div><div>    *got_frame = 0;</div><div><br></div><div>    if (pkt.stream_index == video_stream_idx) {</div><div>        /* decode video frame */</div><div>        ret = avcodec_decode_video2(video_dec_ctx, frame, got_frame, &pkt);</div><div>        if (ret < 0) {</div><div>            fprintf(stderr, "Error decoding video frame (%s)\n", av_err2str(ret));</div><div>            return ret;</div><div>        }</div><div>        if (video_dec_ctx->width != width || video_dec_ctx->height != height ||</div><div>            video_dec_ctx->pix_fmt != pix_fmt) {</div><div>            /* To handle this change, one could call av_image_alloc again and</div><div>             * decode the following frames into another rawvideo file. */</div><div>            fprintf(stderr, "Error: Width, height and pixel format have to be "</div><div>                    "constant in a rawvideo file, but the width, height or "</div><div>                    "pixel format of the input video changed:\n"</div><div>                    "old: width = %d, height = %d, format = %s\n"</div><div>                    "new: width = %d, height = %d, format = %s\n",</div><div>                    width, height, av_get_pix_fmt_name(pix_fmt),</div><div>                    video_dec_ctx->width, video_dec_ctx->height,</div><div>                    av_get_pix_fmt_name(video_dec_ctx->pix_fmt));</div><div>            return -1;</div><div>        }</div><div><br></div><div>        if (*got_frame) {</div><div><br></div><div>            fprintf(stderr,"Frame_type: %c ; pkt_size: %d\n",</div><div>                    av_get_picture_type_char(frame->pict_type),</div><div>                    av_frame_get_pkt_size(frame));</div><div><br></div><div>// This one of many ways that I have tried, all results in a segfault...</div><div>#if 0</div><div>            AVBufferRef* qp_table_buf = av_buffer_ref(frame->qp_table_buf);</div><div>//            qscale_table = qscale_table_buf->data + 2 * s->mb_stride + 1;</div><div>            int8_t* qscale_table = qp_table_buf->data;</div><div><br></div><div>            for (y = 0; y < mb_height; y++) {</div><div>                for (x = 0; x < mb_width; x++) {</div><div>//                        printf("%2d", qscale_table[x + y * mb_stride]);</div><div>                        printf("%2d", qscale_table[x + y * mb_stride]);</div><div>                }</div><div>            }</div><div><br></div><div>#endif</div><div>        }</div><div>    }</div><div><br></div><div>    /* If we use the new API with reference counting, we own the data and need</div><div>     * to de-reference it when we don't use it anymore */</div><div>    if (*got_frame && api_mode == API_MODE_NEW_API_REF_COUNT)</div><div>        av_frame_unref(frame);</div><div><br></div><div>    return decoded;</div><div>}</div></div><div><br></div><div>The complete code can be found in:</div><div><br></div><div><a href="https://gist.github.com/figgis/ea9ac513cdd99a10abf1">https://gist.github.com/figgis/ea9ac513cdd99a10abf1</a><br></div><div><br></div><div>or by doing a</div><div><br></div><div>git clone <a href="https://gist.github.com/ea9ac513cdd99a10abf1.git">https://gist.github.com/ea9ac513cdd99a10abf1.git</a><br></div><div><br></div><div>cheers</div><div>/Fredrik</div><div><br></div></div>