• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavfilter/vf_showinfo.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Stefano Sabatini
00003  * This file is part of Libav.
00004  *
00005  * Libav is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * Libav is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with Libav; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00018  */
00019 
00025 #include "libavutil/adler32.h"
00026 #include "libavutil/imgutils.h"
00027 #include "libavutil/pixdesc.h"
00028 #include "avfilter.h"
00029 
00030 typedef struct {
00031     unsigned int frame;
00032 } ShowInfoContext;
00033 
00034 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
00035 {
00036     ShowInfoContext *showinfo = ctx->priv;
00037     showinfo->frame = 0;
00038     return 0;
00039 }
00040 
00041 static void end_frame(AVFilterLink *inlink)
00042 {
00043     AVFilterContext *ctx = inlink->dst;
00044     ShowInfoContext *showinfo = ctx->priv;
00045     AVFilterBufferRef *picref = inlink->cur_buf;
00046     uint32_t plane_checksum[4] = {0}, checksum = 0;
00047     int i, plane, vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
00048 
00049     for (plane = 0; picref->data[plane] && plane < 4; plane++) {
00050         size_t linesize = av_image_get_linesize(picref->format, picref->video->w, plane);
00051         uint8_t *data = picref->data[plane];
00052         int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h;
00053 
00054         for (i = 0; i < h; i++) {
00055             plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
00056             checksum = av_adler32_update(checksum, data, linesize);
00057             data += picref->linesize[plane];
00058         }
00059     }
00060 
00061     av_log(ctx, AV_LOG_INFO,
00062            "n:%d pts:%"PRId64" pts_time:%f pos:%"PRId64" "
00063            "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
00064            "checksum:%u plane_checksum:[%u %u %u %u]\n",
00065            showinfo->frame,
00066            picref->pts, picref->pts * av_q2d(inlink->time_base), picref->pos,
00067            av_pix_fmt_descriptors[picref->format].name,
00068            picref->video->pixel_aspect.num, picref->video->pixel_aspect.den,
00069            picref->video->w, picref->video->h,
00070            !picref->video->interlaced     ? 'P' :         /* Progressive  */
00071            picref->video->top_field_first ? 'T' : 'B',    /* Top / Bottom */
00072            picref->video->key_frame,
00073            av_get_picture_type_char(picref->video->pict_type),
00074            checksum, plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3]);
00075 
00076     showinfo->frame++;
00077     avfilter_end_frame(inlink->dst->outputs[0]);
00078 }
00079 
00080 AVFilter avfilter_vf_showinfo = {
00081     .name        = "showinfo",
00082     .description = NULL_IF_CONFIG_SMALL("Show textual information for each video frame."),
00083 
00084     .priv_size = sizeof(ShowInfoContext),
00085     .init      = init,
00086 
00087     .inputs    = (AVFilterPad[]) {{ .name = "default",
00088                                     .type             = AVMEDIA_TYPE_VIDEO,
00089                                     .get_video_buffer = avfilter_null_get_video_buffer,
00090                                     .start_frame      = avfilter_null_start_frame,
00091                                     .end_frame        = end_frame,
00092                                     .min_perms        = AV_PERM_READ, },
00093                                   { .name = NULL}},
00094 
00095     .outputs   = (AVFilterPad[]) {{ .name             = "default",
00096                                     .type             = AVMEDIA_TYPE_VIDEO },
00097                                   { .name = NULL}},
00098 };
Generated on Sat Mar 17 2012 12:57:52 for Libav by doxygen 1.7.1