h264_metadata: Add option to delete filler data
[libav.git] / libavfilter / vf_showinfo.c
CommitLineData
ee42716b
SS
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
7513234b
DB
25#include <inttypes.h>
26
ee42716b 27#include "libavutil/adler32.h"
5a69ded1 28#include "libavutil/display.h"
ee42716b 29#include "libavutil/imgutils.h"
1d9c2dc8 30#include "libavutil/internal.h"
ee42716b 31#include "libavutil/pixdesc.h"
883ce264 32#include "libavutil/spherical.h"
b4679ecd
AK
33#include "libavutil/stereo3d.h"
34
ee42716b 35#include "avfilter.h"
9d0bfc50 36#include "internal.h"
c04c533f 37#include "video.h"
ee42716b 38
58400ac1 39typedef struct ShowInfoContext {
ee42716b
SS
40 unsigned int frame;
41} ShowInfoContext;
42
883ce264
VG
43static 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
b4679ecd
AK
80static 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
3f128fc4 92 av_log(ctx, AV_LOG_INFO, "type - %s", av_stereo3d_type_name(stereo->type));
b4679ecd
AK
93
94 if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
95 av_log(ctx, AV_LOG_INFO, " (inverted)");
96}
97
7e350379 98static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
ee42716b
SS
99{
100 AVFilterContext *ctx = inlink->dst;
101 ShowInfoContext *showinfo = ctx->priv;
59ee9f78 102 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
ee42716b 103 uint32_t plane_checksum[4] = {0}, checksum = 0;
59ee9f78 104 int i, plane, vsub = desc->log2_chroma_h;
ee42716b 105
565e4993 106 for (plane = 0; frame->data[plane] && plane < 4; plane++) {
565e4993 107 uint8_t *data = frame->data[plane];
ee42716b 108 int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h;
6d96c7ea
VG
109 int linesize = av_image_get_linesize(frame->format, frame->width, plane);
110 if (linesize < 0)
111 return linesize;
ee42716b
SS
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);
565e4993 116 data += frame->linesize[plane];
ee42716b
SS
117 }
118 }
119
120 av_log(ctx, AV_LOG_INFO,
7e350379 121 "n:%d pts:%"PRId64" pts_time:%f "
ee42716b 122 "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
7513234b 123 "checksum:%"PRIu32" plane_checksum:[%"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32"]\n",
ee42716b 124 showinfo->frame,
7e350379 125 frame->pts, frame->pts * av_q2d(inlink->time_base),
59ee9f78 126 desc->name,
7e350379
AK
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),
ee42716b
SS
133 checksum, plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3]);
134
b4679ecd
AK
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;
883ce264
VG
146 case AV_FRAME_DATA_SPHERICAL:
147 dump_spherical(ctx, frame, sd);
148 break;
b4679ecd
AK
149 case AV_FRAME_DATA_STEREO3D:
150 dump_stereo3d(ctx, sd);
151 break;
5a69ded1
VG
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;
1ef9e837
KK
156 case AV_FRAME_DATA_AFD:
157 av_log(ctx, AV_LOG_INFO, "afd: value of %"PRIu8, sd->data[0]);
158 break;
b4679ecd
AK
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
ee42716b 168 showinfo->frame++;
565e4993 169 return ff_filter_frame(inlink->dst->outputs[0], frame);
ee42716b
SS
170}
171
1339009c
MN
172static 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
183static int config_props_in(AVFilterLink *link)
184{
185 AVFilterContext *ctx = link->dst;
186 return config_props(ctx, link, 0);
187}
188
189static int config_props_out(AVFilterLink *link)
190{
191 AVFilterContext *ctx = link->src;
192 return config_props(ctx, link, 1);
193}
194
568c70e7
MR
195static const AVFilterPad avfilter_vf_showinfo_inputs[] = {
196 {
197 .name = "default",
198 .type = AVMEDIA_TYPE_VIDEO,
199 .get_video_buffer = ff_null_get_video_buffer,
565e4993 200 .filter_frame = filter_frame,
1339009c 201 .config_props = config_props_in,
568c70e7
MR
202 },
203 { NULL }
204};
205
206static const AVFilterPad avfilter_vf_showinfo_outputs[] = {
207 {
208 .name = "default",
1339009c
MN
209 .type = AVMEDIA_TYPE_VIDEO,
210 .config_props = config_props_out,
568c70e7
MR
211 },
212 { NULL }
213};
214
cd43ca04 215AVFilter ff_vf_showinfo = {
ee42716b
SS
216 .name = "showinfo",
217 .description = NULL_IF_CONFIG_SMALL("Show textual information for each video frame."),
218
219 .priv_size = sizeof(ShowInfoContext),
ee42716b 220
568c70e7 221 .inputs = avfilter_vf_showinfo_inputs,
ee42716b 222
568c70e7 223 .outputs = avfilter_vf_showinfo_outputs,
ee42716b 224};