h264_metadata: Add option to delete filler data
[libav.git] / libavfilter / vf_showinfo.c
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
20 /**
21 * @file
22 * filter for showing textual video frame information
23 */
24
25 #include <inttypes.h>
26
27 #include "libavutil/adler32.h"
28 #include "libavutil/display.h"
29 #include "libavutil/imgutils.h"
30 #include "libavutil/internal.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/spherical.h"
33 #include "libavutil/stereo3d.h"
34
35 #include "avfilter.h"
36 #include "internal.h"
37 #include "video.h"
38
39 typedef struct ShowInfoContext {
40 unsigned int frame;
41 } ShowInfoContext;
42
43 static void dump_spherical(AVFilterContext *ctx, AVFrame *frame, AVFrameSideData *sd)
44 {
45 AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
46 double yaw, pitch, roll;
47
48 av_log(ctx, AV_LOG_INFO, "spherical information: ");
49 if (sd->size < sizeof(*spherical)) {
50 av_log(ctx, AV_LOG_INFO, "invalid data");
51 return;
52 }
53
54 if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR)
55 av_log(ctx, AV_LOG_INFO, "equirectangular ");
56 else if (spherical->projection == AV_SPHERICAL_CUBEMAP)
57 av_log(ctx, AV_LOG_INFO, "cubemap ");
58 else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE)
59 av_log(ctx, AV_LOG_INFO, "tiled equirectangular ");
60 else {
61 av_log(ctx, AV_LOG_WARNING, "unknown");
62 return;
63 }
64
65 yaw = ((double)spherical->yaw) / (1 << 16);
66 pitch = ((double)spherical->pitch) / (1 << 16);
67 roll = ((double)spherical->roll) / (1 << 16);
68 av_log(ctx, AV_LOG_INFO, "(%f/%f/%f) ", yaw, pitch, roll);
69
70 if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
71 size_t l, t, r, b;
72 av_spherical_tile_bounds(spherical, frame->width, frame->height,
73 &l, &t, &r, &b);
74 av_log(ctx, AV_LOG_INFO, "[%zu, %zu, %zu, %zu] ", l, t, r, b);
75 } else if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
76 av_log(ctx, AV_LOG_INFO, "[pad %"PRIu32"] ", spherical->padding);
77 }
78 }
79
80 static void dump_stereo3d(AVFilterContext *ctx, AVFrameSideData *sd)
81 {
82 AVStereo3D *stereo;
83
84 av_log(ctx, AV_LOG_INFO, "stereoscopic information: ");
85 if (sd->size < sizeof(*stereo)) {
86 av_log(ctx, AV_LOG_INFO, "invalid data");
87 return;
88 }
89
90 stereo = (AVStereo3D *)sd->data;
91
92 av_log(ctx, AV_LOG_INFO, "type - %s", av_stereo3d_type_name(stereo->type));
93
94 if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
95 av_log(ctx, AV_LOG_INFO, " (inverted)");
96 }
97
98 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
99 {
100 AVFilterContext *ctx = inlink->dst;
101 ShowInfoContext *showinfo = ctx->priv;
102 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
103 uint32_t plane_checksum[4] = {0}, checksum = 0;
104 int i, plane, vsub = desc->log2_chroma_h;
105
106 for (plane = 0; frame->data[plane] && plane < 4; plane++) {
107 uint8_t *data = frame->data[plane];
108 int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h;
109 int linesize = av_image_get_linesize(frame->format, frame->width, plane);
110 if (linesize < 0)
111 return linesize;
112
113 for (i = 0; i < h; i++) {
114 plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
115 checksum = av_adler32_update(checksum, data, linesize);
116 data += frame->linesize[plane];
117 }
118 }
119
120 av_log(ctx, AV_LOG_INFO,
121 "n:%d pts:%"PRId64" pts_time:%f "
122 "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
123 "checksum:%"PRIu32" plane_checksum:[%"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32"]\n",
124 showinfo->frame,
125 frame->pts, frame->pts * av_q2d(inlink->time_base),
126 desc->name,
127 frame->sample_aspect_ratio.num, frame->sample_aspect_ratio.den,
128 frame->width, frame->height,
129 !frame->interlaced_frame ? 'P' : /* Progressive */
130 frame->top_field_first ? 'T' : 'B', /* Top / Bottom */
131 frame->key_frame,
132 av_get_picture_type_char(frame->pict_type),
133 checksum, plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3]);
134
135 for (i = 0; i < frame->nb_side_data; i++) {
136 AVFrameSideData *sd = frame->side_data[i];
137
138 av_log(ctx, AV_LOG_INFO, " side data - ");
139 switch (sd->type) {
140 case AV_FRAME_DATA_PANSCAN:
141 av_log(ctx, AV_LOG_INFO, "pan/scan");
142 break;
143 case AV_FRAME_DATA_A53_CC:
144 av_log(ctx, AV_LOG_INFO, "A/53 closed captions (%d bytes)", sd->size);
145 break;
146 case AV_FRAME_DATA_SPHERICAL:
147 dump_spherical(ctx, frame, sd);
148 break;
149 case AV_FRAME_DATA_STEREO3D:
150 dump_stereo3d(ctx, sd);
151 break;
152 case AV_FRAME_DATA_DISPLAYMATRIX:
153 av_log(ctx, AV_LOG_INFO, "displaymatrix: rotation of %.2f degrees",
154 av_display_rotation_get((int32_t *)sd->data));
155 break;
156 case AV_FRAME_DATA_AFD:
157 av_log(ctx, AV_LOG_INFO, "afd: value of %"PRIu8, sd->data[0]);
158 break;
159 default:
160 av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)",
161 sd->type, sd->size);
162 break;
163 }
164
165 av_log(ctx, AV_LOG_INFO, "\n");
166 }
167
168 showinfo->frame++;
169 return ff_filter_frame(inlink->dst->outputs[0], frame);
170 }
171
172 static int config_props(AVFilterContext *ctx, AVFilterLink *link, int is_out)
173 {
174
175 av_log(ctx, AV_LOG_INFO, "config %s time_base: %d/%d, frame_rate: %d/%d\n",
176 is_out ? "out" : "in",
177 link->time_base.num, link->time_base.den,
178 link->frame_rate.num, link->frame_rate.den);
179
180 return 0;
181 }
182
183 static int config_props_in(AVFilterLink *link)
184 {
185 AVFilterContext *ctx = link->dst;
186 return config_props(ctx, link, 0);
187 }
188
189 static int config_props_out(AVFilterLink *link)
190 {
191 AVFilterContext *ctx = link->src;
192 return config_props(ctx, link, 1);
193 }
194
195 static const AVFilterPad avfilter_vf_showinfo_inputs[] = {
196 {
197 .name = "default",
198 .type = AVMEDIA_TYPE_VIDEO,
199 .get_video_buffer = ff_null_get_video_buffer,
200 .filter_frame = filter_frame,
201 .config_props = config_props_in,
202 },
203 { NULL }
204 };
205
206 static const AVFilterPad avfilter_vf_showinfo_outputs[] = {
207 {
208 .name = "default",
209 .type = AVMEDIA_TYPE_VIDEO,
210 .config_props = config_props_out,
211 },
212 { NULL }
213 };
214
215 AVFilter ff_vf_showinfo = {
216 .name = "showinfo",
217 .description = NULL_IF_CONFIG_SMALL("Show textual information for each video frame."),
218
219 .priv_size = sizeof(ShowInfoContext),
220
221 .inputs = avfilter_vf_showinfo_inputs,
222
223 .outputs = avfilter_vf_showinfo_outputs,
224 };