FFmpeg  2.1.1
vf_showinfo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Stefano Sabatini
3  * This file is part of FFmpeg.
4  *
5  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /**
21  * @file
22  * filter for showing textual video frame information
23  */
24 
25 #include "libavutil/adler32.h"
26 #include "libavutil/imgutils.h"
27 #include "libavutil/internal.h"
28 #include "libavutil/pixdesc.h"
29 #include "libavutil/timestamp.h"
30 #include "avfilter.h"
31 #include "internal.h"
32 #include "video.h"
33 
34 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
35 {
36  AVFilterContext *ctx = inlink->dst;
37  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
38  uint32_t plane_checksum[4] = {0}, checksum = 0;
39  int i, plane, vsub = desc->log2_chroma_h;
40 
41  for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) {
42  int64_t linesize = av_image_get_linesize(frame->format, frame->width, plane);
43  uint8_t *data = frame->data[plane];
44  int h = plane == 1 || plane == 2 ? FF_CEIL_RSHIFT(inlink->h, vsub) : inlink->h;
45 
46  if (linesize < 0)
47  return linesize;
48 
49  for (i = 0; i < h; i++) {
50  plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
51  checksum = av_adler32_update(checksum, data, linesize);
52  data += frame->linesize[plane];
53  }
54  }
55 
56  av_log(ctx, AV_LOG_INFO,
57  "n:%"PRId64" pts:%s pts_time:%s pos:%"PRId64" "
58  "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
59  "checksum:%08X plane_checksum:[%08X",
60  inlink->frame_count,
61  av_ts2str(frame->pts), av_ts2timestr(frame->pts, &inlink->time_base), av_frame_get_pkt_pos(frame),
62  desc->name,
64  frame->width, frame->height,
65  !frame->interlaced_frame ? 'P' : /* Progressive */
66  frame->top_field_first ? 'T' : 'B', /* Top / Bottom */
67  frame->key_frame,
69  checksum, plane_checksum[0]);
70 
71  for (plane = 1; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++)
72  av_log(ctx, AV_LOG_INFO, " %08X", plane_checksum[plane]);
73  av_log(ctx, AV_LOG_INFO, "]\n");
74 
75  return ff_filter_frame(inlink->dst->outputs[0], frame);
76 }
77 
79  {
80  .name = "default",
81  .type = AVMEDIA_TYPE_VIDEO,
82  .filter_frame = filter_frame,
83  },
84  { NULL }
85 };
86 
88  {
89  .name = "default",
90  .type = AVMEDIA_TYPE_VIDEO
91  },
92  { NULL }
93 };
94 
96  .name = "showinfo",
97  .description = NULL_IF_CONFIG_SMALL("Show textual information for each video frame."),
100 };
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:73
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
const char * name
Filter name.
Definition: avfilter.h:468
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:72
AVFilter avfilter_vf_showinfo
Definition: vf_showinfo.c:95
int num
numerator
Definition: rational.h:44
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static const AVFilterPad avfilter_vf_showinfo_inputs[]
Definition: vf_showinfo.c:78
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: vf_showinfo.c:34
const char * name
Pad name.
Definition: internal.h:66
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1118
const char * name
Definition: pixdesc.h:58
uint8_t
unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len) av_pure
Calculate the Adler32 checksum of a buffer.
Definition: adler32.c:35
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:182
#define FF_CEIL_RSHIFT(a, b)
Definition: avcodec.h:916
const char data[16]
Definition: mxf.c:68
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:82
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:293
static AVFrame * frame
Definition: demuxing.c:51
A filter pad used for either input or output.
Definition: internal.h:60
int width
width and height of the video frame
Definition: frame.h:145
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:151
common internal API header
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:167
Main libavfilter public API header.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1938
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:642
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:157
#define AV_LOG_INFO
Standard information.
Definition: avcodec.h:4158
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:177
static const AVFilterPad avfilter_vf_showinfo_outputs[]
Definition: vf_showinfo.c:87
Filter definition.
Definition: avfilter.h:464
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
int den
denominator
Definition: rational.h:45
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:298
int key_frame
1 -&gt; keyframe, 0-&gt; not
Definition: frame.h:162
An instance of a filter.
Definition: avfilter.h:627
int height
Definition: frame.h:145
internal API functions
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:50
int64_t av_frame_get_pkt_pos(const AVFrame *frame)