You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.0KB

  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/internal.h"
  26. #include "libavutil/pixdesc.h"
  27. #include "libavutil/timestamp.h"
  28. #include "avfilter.h"
  29. #include "internal.h"
  30. #include "video.h"
  31. typedef struct {
  32. unsigned int frame;
  33. } ShowInfoContext;
  34. static av_cold int init(AVFilterContext *ctx, const char *args)
  35. {
  36. ShowInfoContext *showinfo = ctx->priv;
  37. showinfo->frame = 0;
  38. return 0;
  39. }
  40. static int end_frame(AVFilterLink *inlink)
  41. {
  42. AVFilterContext *ctx = inlink->dst;
  43. ShowInfoContext *showinfo = ctx->priv;
  44. AVFilterBufferRef *picref = inlink->cur_buf;
  45. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  46. uint32_t plane_checksum[4] = {0}, checksum = 0;
  47. int i, plane, vsub = desc->log2_chroma_h;
  48. for (plane = 0; picref->data[plane] && plane < 4; plane++) {
  49. int64_t linesize = av_image_get_linesize(picref->format, picref->video->w, plane);
  50. uint8_t *data = picref->data[plane];
  51. int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h;
  52. if (linesize < 0)
  53. return linesize;
  54. for (i = 0; i < h; i++) {
  55. plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
  56. checksum = av_adler32_update(checksum, data, linesize);
  57. data += picref->linesize[plane];
  58. }
  59. }
  60. av_log(ctx, AV_LOG_INFO,
  61. "n:%d pts:%s pts_time:%s pos:%"PRId64" "
  62. "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
  63. "checksum:%08X plane_checksum:[%08X",
  64. showinfo->frame,
  65. av_ts2str(picref->pts), av_ts2timestr(picref->pts, &inlink->time_base), picref->pos,
  66. desc->name,
  67. picref->video->sample_aspect_ratio.num, picref->video->sample_aspect_ratio.den,
  68. picref->video->w, picref->video->h,
  69. !picref->video->interlaced ? 'P' : /* Progressive */
  70. picref->video->top_field_first ? 'T' : 'B', /* Top / Bottom */
  71. picref->video->key_frame,
  72. av_get_picture_type_char(picref->video->pict_type),
  73. checksum, plane_checksum[0]);
  74. for (plane = 1; picref->data[plane] && plane < 4; plane++)
  75. av_log(ctx, AV_LOG_INFO, " %08X", plane_checksum[plane]);
  76. av_log(ctx, AV_LOG_INFO, "]\n");
  77. showinfo->frame++;
  78. return ff_end_frame(inlink->dst->outputs[0]);
  79. }
  80. static const AVFilterPad avfilter_vf_showinfo_inputs[] = {
  81. {
  82. .name = "default",
  83. .type = AVMEDIA_TYPE_VIDEO,
  84. .get_video_buffer = ff_null_get_video_buffer,
  85. .start_frame = ff_null_start_frame,
  86. .end_frame = end_frame,
  87. .min_perms = AV_PERM_READ,
  88. },
  89. { NULL }
  90. };
  91. static const AVFilterPad avfilter_vf_showinfo_outputs[] = {
  92. {
  93. .name = "default",
  94. .type = AVMEDIA_TYPE_VIDEO
  95. },
  96. { NULL }
  97. };
  98. AVFilter avfilter_vf_showinfo = {
  99. .name = "showinfo",
  100. .description = NULL_IF_CONFIG_SMALL("Show textual information for each video frame."),
  101. .priv_size = sizeof(ShowInfoContext),
  102. .init = init,
  103. .inputs = avfilter_vf_showinfo_inputs,
  104. .outputs = avfilter_vf_showinfo_outputs,
  105. };