[FFmpeg-devel] [PATCH] ffprobe: add support to audio frame information printing

Stefano Sabatini stefasab at gmail.com
Wed Jan 11 12:43:13 CET 2012


On date Wednesday 2012-01-11 09:25:53 +0100, Clément Bœsch encoded:
> On Tue, Jan 10, 2012 at 10:50:13PM +0100, Stefano Sabatini wrote:
> > ---
> >  ffprobe.c |   75 +++++++++++++++++++++++++++++++++++++++++++-----------------
> >  1 files changed, 54 insertions(+), 21 deletions(-)
> > 
> > diff --git a/ffprobe.c b/ffprobe.c
[...]
> > -static av_always_inline int get_video_frame(AVFormatContext *fmt_ctx,
> > -                                            AVFrame *frame, AVPacket *pkt)
> > +static av_always_inline int get_decoded_frame(AVFormatContext *fmt_ctx,
> > +                                              AVFrame *frame, int *got_frame,
> > +                                              AVPacket *pkt)
> >  {
> >      AVCodecContext *dec_ctx = fmt_ctx->streams[pkt->stream_index]->codec;
> > -    int got_picture = 0;
> > +    int ret = 0;
> > +
> > +    *got_frame = 0;
> > +    if (dec_ctx->codec_id   != CODEC_ID_NONE) {
> 
> since you changed the line, maybe you could fix the weird spacing

Fixed.

> > +        switch (dec_ctx->codec_type) {
> > +        case AVMEDIA_TYPE_VIDEO:
> > +            ret = avcodec_decode_video2(dec_ctx, frame, got_frame, pkt);
> > +            break;
> >  
> > -    if (dec_ctx->codec_id   != CODEC_ID_NONE &&
> > -        dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO)
> > -        avcodec_decode_video2(dec_ctx, frame, &got_picture, pkt);
> > -    return got_picture;
> > +        case AVMEDIA_TYPE_AUDIO:
> > +            ret = avcodec_decode_audio4(dec_ctx, frame, got_frame, pkt);
> > +            break;
> > +        }
> > +    }
> > +    return ret;
> >  }
> >  
> >  static void show_packets(WriterContext *w, AVFormatContext *fmt_ctx)
> >  {
> > -    AVPacket pkt;
> > +    AVPacket pkt, pkt1;
> >      AVFrame frame;
> > -    int i = 0;
> > +    int i = 0, ret, got_frame;
> >  
> >      av_init_packet(&pkt);
> >  
> >      while (!av_read_frame(fmt_ctx, &pkt)) {
> >          if (do_show_packets)
> >              show_packet(w, fmt_ctx, &pkt, i++);
> > -        if (do_show_frames &&
> > -            get_video_frame(fmt_ctx, &frame, &pkt)) {
> > -            show_frame(w, &frame, fmt_ctx->streams[pkt.stream_index]);
> > +        if (do_show_frames) {
> > +            pkt1 = pkt;
> > +            while (1) {
> > +                ret = get_decoded_frame(fmt_ctx, &frame, &got_frame, &pkt1);
> > +                if (ret < 0 || !got_frame)
> > +                    break;
> 

> I'm not sure, but I think the API needs you to deal with the special case
> of ret < 0. See 220481e1d6582277ae4c02b05f87251a8670e6cc for instance. I
> can look for a sample to confirm this if you need one.

Should not be necessary since the packet is just dropped in case ret <
0, and no more processing is done with it, but testing with a sample
can't hurt.

> 
> > +                show_frame(w, &frame, fmt_ctx->streams[pkt.stream_index]);
> > +                pkt1.data += ret;
> > +                pkt1.size -= ret;
> > +            }
> 
> IIRC the documentation also mentions only the video frames; maybe you want
> to add audio frames there too.

Yes, I also added the missing ffprobe.xsd updates.
-- 
FFmpeg = Freak Funny Mystic Pacific Extroverse Geek
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ffprobe-add-support-to-audio-frame-information-print.patch
Type: text/x-diff
Size: 6350 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120111/efbb7771/attachment.bin>


More information about the ffmpeg-devel mailing list