Libav
vf_showinfo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Stefano Sabatini
3  * This file is part of Libav.
4  *
5  * Libav is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * Libav is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with Libav; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #include "libavutil/adler32.h"
26 #include "libavutil/imgutils.h"
27 #include "libavutil/internal.h"
28 #include "libavutil/pixdesc.h"
29 #include "avfilter.h"
30 #include "internal.h"
31 #include "video.h"
32 
33 typedef struct {
34  unsigned int frame;
36 
37 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
38 {
39  AVFilterContext *ctx = inlink->dst;
40  ShowInfoContext *showinfo = ctx->priv;
41  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
42  uint32_t plane_checksum[4] = {0}, checksum = 0;
43  int i, plane, vsub = desc->log2_chroma_h;
44 
45  for (plane = 0; frame->data[plane] && plane < 4; plane++) {
46  size_t linesize = av_image_get_linesize(frame->format, frame->width, plane);
47  uint8_t *data = frame->data[plane];
48  int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h;
49 
50  for (i = 0; i < h; i++) {
51  plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
52  checksum = av_adler32_update(checksum, data, linesize);
53  data += frame->linesize[plane];
54  }
55  }
56 
57  av_log(ctx, AV_LOG_INFO,
58  "n:%d pts:%"PRId64" pts_time:%f "
59  "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
60  "checksum:%u plane_checksum:[%u %u %u %u]\n",
61  showinfo->frame,
62  frame->pts, frame->pts * av_q2d(inlink->time_base),
63  desc->name,
65  frame->width, frame->height,
66  !frame->interlaced_frame ? 'P' : /* Progressive */
67  frame->top_field_first ? 'T' : 'B', /* Top / Bottom */
68  frame->key_frame,
70  checksum, plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3]);
71 
72  showinfo->frame++;
73  return ff_filter_frame(inlink->dst->outputs[0], frame);
74 }
75 
77  {
78  .name = "default",
79  .type = AVMEDIA_TYPE_VIDEO,
80  .get_video_buffer = ff_null_get_video_buffer,
81  .filter_frame = filter_frame,
82  },
83  { NULL }
84 };
85 
87  {
88  .name = "default",
89  .type = AVMEDIA_TYPE_VIDEO
90  },
91  { NULL }
92 };
93 
95  .name = "showinfo",
96  .description = NULL_IF_CONFIG_SMALL("Show textual information for each video frame."),
97 
98  .priv_size = sizeof(ShowInfoContext),
99 
100  .inputs = avfilter_vf_showinfo_inputs,
101 
102  .outputs = avfilter_vf_showinfo_outputs,
103 };
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane...
Definition: imgutils.c:48
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1507
This structure describes decoded (raw) audio or video data.
Definition: frame.h:107
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:122
Main libavfilter public API header.
int num
numerator
Definition: rational.h:44
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:30
static const AVFilterPad avfilter_vf_showinfo_inputs[]
Definition: vf_showinfo.c:76
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: vf_showinfo.c:37
const char * name
Pad name.
Definition: internal.h:42
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:728
uint8_t
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:183
unsigned int frame
Definition: vf_showinfo.c:34
const char data[16]
Definition: mxf.c:66
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
Definition: utils.c:43
unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len)
Calculate the Adler32 checksum of a buffer.
Definition: adler32.c:33
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:292
const char * name
Definition: pixdesc.h:58
A filter pad used for either input or output.
Definition: internal.h:36
int width
width and height of the video frame
Definition: frame.h:146
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:77
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:142
void * priv
private data for use by the filter
Definition: avfilter.h:584
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:148
common internal API header
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:168
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:158
NULL
Definition: eval.c:55
#define AV_LOG_INFO
Standard information.
Definition: log.h:134
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:125
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:57
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:178
static const AVFilterPad avfilter_vf_showinfo_outputs[]
Definition: vf_showinfo.c:86
Filter definition.
Definition: avfilter.h:421
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:111
const char * name
Filter name.
Definition: avfilter.h:425
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:578
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:113
int den
denominator
Definition: rational.h:45
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:297
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:163
An instance of a filter.
Definition: avfilter.h:563
int height
Definition: frame.h:146
internal API functions
AVFilter ff_vf_showinfo
Definition: vf_showinfo.c:94