00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00025 #include "libavutil/adler32.h"
00026 #include "libavutil/imgutils.h"
00027 #include "libavutil/internal.h"
00028 #include "libavutil/pixdesc.h"
00029 #include "libavutil/timestamp.h"
00030 #include "avfilter.h"
00031 #include "internal.h"
00032 #include "video.h"
00033
00034 typedef struct {
00035 unsigned int frame;
00036 } ShowInfoContext;
00037
00038 static av_cold int init(AVFilterContext *ctx, const char *args)
00039 {
00040 ShowInfoContext *showinfo = ctx->priv;
00041 showinfo->frame = 0;
00042 return 0;
00043 }
00044
00045 static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame)
00046 {
00047 AVFilterContext *ctx = inlink->dst;
00048 ShowInfoContext *showinfo = ctx->priv;
00049 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
00050 uint32_t plane_checksum[4] = {0}, checksum = 0;
00051 int i, plane, vsub = desc->log2_chroma_h;
00052
00053 for (plane = 0; plane < 4 && frame->data[plane]; plane++) {
00054 int64_t linesize = av_image_get_linesize(frame->format, frame->video->w, plane);
00055 uint8_t *data = frame->data[plane];
00056 int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h;
00057
00058 if (linesize < 0)
00059 return linesize;
00060
00061 for (i = 0; i < h; i++) {
00062 plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
00063 checksum = av_adler32_update(checksum, data, linesize);
00064 data += frame->linesize[plane];
00065 }
00066 }
00067
00068 av_log(ctx, AV_LOG_INFO,
00069 "n:%d pts:%s pts_time:%s pos:%"PRId64" "
00070 "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
00071 "checksum:%08X plane_checksum:[%08X",
00072 showinfo->frame,
00073 av_ts2str(frame->pts), av_ts2timestr(frame->pts, &inlink->time_base), frame->pos,
00074 desc->name,
00075 frame->video->sample_aspect_ratio.num, frame->video->sample_aspect_ratio.den,
00076 frame->video->w, frame->video->h,
00077 !frame->video->interlaced ? 'P' :
00078 frame->video->top_field_first ? 'T' : 'B',
00079 frame->video->key_frame,
00080 av_get_picture_type_char(frame->video->pict_type),
00081 checksum, plane_checksum[0]);
00082
00083 for (plane = 1; plane < 4 && frame->data[plane]; plane++)
00084 av_log(ctx, AV_LOG_INFO, " %08X", plane_checksum[plane]);
00085 av_log(ctx, AV_LOG_INFO, "]\n");
00086
00087 showinfo->frame++;
00088 return ff_filter_frame(inlink->dst->outputs[0], frame);
00089 }
00090
00091 static const AVFilterPad avfilter_vf_showinfo_inputs[] = {
00092 {
00093 .name = "default",
00094 .type = AVMEDIA_TYPE_VIDEO,
00095 .get_video_buffer = ff_null_get_video_buffer,
00096 .filter_frame = filter_frame,
00097 .min_perms = AV_PERM_READ,
00098 },
00099 { NULL }
00100 };
00101
00102 static const AVFilterPad avfilter_vf_showinfo_outputs[] = {
00103 {
00104 .name = "default",
00105 .type = AVMEDIA_TYPE_VIDEO
00106 },
00107 { NULL }
00108 };
00109
00110 AVFilter avfilter_vf_showinfo = {
00111 .name = "showinfo",
00112 .description = NULL_IF_CONFIG_SMALL("Show textual information for each video frame."),
00113
00114 .priv_size = sizeof(ShowInfoContext),
00115 .init = init,
00116
00117 .inputs = avfilter_vf_showinfo_inputs,
00118
00119 .outputs = avfilter_vf_showinfo_outputs,
00120 };