vf_showinfo.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * @file
  21. * filter for showing textual video frame information
  22. */
  23. #include "libavutil/adler32.h"
  24. #include "libavutil/imgutils.h"
  25. #include "libavutil/pixdesc.h"
  26. #include "libavutil/timestamp.h"
  27. #include "avfilter.h"
  28. #include "internal.h"
  29. #include "video.h"
  30. typedef struct {
  31. unsigned int frame;
  32. } ShowInfoContext;
  33. static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
  34. {
  35. ShowInfoContext *showinfo = ctx->priv;
  36. showinfo->frame = 0;
  37. return 0;
  38. }
  39. static void end_frame(AVFilterLink *inlink)
  40. {
  41. AVFilterContext *ctx = inlink->dst;
  42. ShowInfoContext *showinfo = ctx->priv;
  43. AVFilterBufferRef *picref = inlink->cur_buf;
  44. uint32_t plane_checksum[4] = {0}, checksum = 0;
  45. int i, plane, vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
  46. for (plane = 0; picref->data[plane] && plane < 4; plane++) {
  47. size_t linesize = av_image_get_linesize(picref->format, picref->video->w, plane);
  48. uint8_t *data = picref->data[plane];
  49. int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h;
  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 += picref->linesize[plane];
  54. }
  55. }
  56. av_log(ctx, AV_LOG_INFO,
  57. "n:%d 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. showinfo->frame,
  61. av_ts2str(picref->pts), av_ts2timestr(picref->pts, &inlink->time_base), picref->pos,
  62. av_pix_fmt_descriptors[picref->format].name,
  63. picref->video->sample_aspect_ratio.num, picref->video->sample_aspect_ratio.den,
  64. picref->video->w, picref->video->h,
  65. !picref->video->interlaced ? 'P' : /* Progressive */
  66. picref->video->top_field_first ? 'T' : 'B', /* Top / Bottom */
  67. picref->video->key_frame,
  68. av_get_picture_type_char(picref->video->pict_type),
  69. checksum, plane_checksum[0]);
  70. for (plane = 1; picref->data[plane] && plane < 4; plane++)
  71. av_log(ctx, AV_LOG_INFO, " %08X", plane_checksum[plane]);
  72. av_log(ctx, AV_LOG_INFO, "]\n");
  73. showinfo->frame++;
  74. avfilter_unref_buffer(picref);
  75. avfilter_end_frame(inlink->dst->outputs[0]);
  76. }
  77. AVFilter avfilter_vf_showinfo = {
  78. .name = "showinfo",
  79. .description = NULL_IF_CONFIG_SMALL("Show textual information for each video frame."),
  80. .priv_size = sizeof(ShowInfoContext),
  81. .init = init,
  82. .inputs = (const AVFilterPad[]) {{ .name = "default",
  83. .type = AVMEDIA_TYPE_VIDEO,
  84. .get_video_buffer = ff_null_get_video_buffer,
  85. .start_frame = ff_null_start_frame_keep_ref,
  86. .end_frame = end_frame,
  87. .min_perms = AV_PERM_READ, },
  88. { .name = NULL}},
  89. .outputs = (const AVFilterPad[]) {{ .name = "default",
  90. .type = AVMEDIA_TYPE_VIDEO },
  91. { .name = NULL}},
  92. };