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.

196 lines
6.7KB

  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. * @file
  21. * filter for showing textual video frame information
  22. */
  23. #include <inttypes.h>
  24. #include "libavutil/adler32.h"
  25. #include "libavutil/display.h"
  26. #include "libavutil/imgutils.h"
  27. #include "libavutil/internal.h"
  28. #include "libavutil/pixdesc.h"
  29. #include "libavutil/stereo3d.h"
  30. #include "avfilter.h"
  31. #include "internal.h"
  32. #include "video.h"
  33. typedef struct ShowInfoContext {
  34. unsigned int frame;
  35. } ShowInfoContext;
  36. static void dump_stereo3d(AVFilterContext *ctx, AVFrameSideData *sd)
  37. {
  38. AVStereo3D *stereo;
  39. av_log(ctx, AV_LOG_INFO, "stereoscopic information: ");
  40. if (sd->size < sizeof(*stereo)) {
  41. av_log(ctx, AV_LOG_INFO, "invalid data");
  42. return;
  43. }
  44. stereo = (AVStereo3D *)sd->data;
  45. av_log(ctx, AV_LOG_INFO, "type - ");
  46. switch (stereo->type) {
  47. case AV_STEREO3D_2D: av_log(ctx, AV_LOG_INFO, "2D"); break;
  48. case AV_STEREO3D_SIDEBYSIDE: av_log(ctx, AV_LOG_INFO, "side by side"); break;
  49. case AV_STEREO3D_TOPBOTTOM: av_log(ctx, AV_LOG_INFO, "top and bottom"); break;
  50. case AV_STEREO3D_FRAMESEQUENCE: av_log(ctx, AV_LOG_INFO, "frame alternate"); break;
  51. case AV_STEREO3D_CHECKERBOARD: av_log(ctx, AV_LOG_INFO, "checkerboard"); break;
  52. case AV_STEREO3D_LINES: av_log(ctx, AV_LOG_INFO, "interleaved lines"); break;
  53. case AV_STEREO3D_COLUMNS: av_log(ctx, AV_LOG_INFO, "interleaved columns"); break;
  54. case AV_STEREO3D_SIDEBYSIDE_QUINCUNX: av_log(ctx, AV_LOG_INFO, "side by side "
  55. "(quincunx subsampling)"); break;
  56. default: av_log(ctx, AV_LOG_WARNING, "unknown"); break;
  57. }
  58. if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
  59. av_log(ctx, AV_LOG_INFO, " (inverted)");
  60. }
  61. static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
  62. {
  63. AVFilterContext *ctx = inlink->dst;
  64. ShowInfoContext *showinfo = ctx->priv;
  65. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  66. uint32_t plane_checksum[4] = {0}, checksum = 0;
  67. int i, plane, vsub = desc->log2_chroma_h;
  68. for (plane = 0; frame->data[plane] && plane < 4; plane++) {
  69. uint8_t *data = frame->data[plane];
  70. int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h;
  71. int linesize = av_image_get_linesize(frame->format, frame->width, plane);
  72. if (linesize < 0)
  73. return linesize;
  74. for (i = 0; i < h; i++) {
  75. plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
  76. checksum = av_adler32_update(checksum, data, linesize);
  77. data += frame->linesize[plane];
  78. }
  79. }
  80. av_log(ctx, AV_LOG_INFO,
  81. "n:%d pts:%"PRId64" pts_time:%f "
  82. "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
  83. "checksum:%"PRIu32" plane_checksum:[%"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32"]\n",
  84. showinfo->frame,
  85. frame->pts, frame->pts * av_q2d(inlink->time_base),
  86. desc->name,
  87. frame->sample_aspect_ratio.num, frame->sample_aspect_ratio.den,
  88. frame->width, frame->height,
  89. !frame->interlaced_frame ? 'P' : /* Progressive */
  90. frame->top_field_first ? 'T' : 'B', /* Top / Bottom */
  91. frame->key_frame,
  92. av_get_picture_type_char(frame->pict_type),
  93. checksum, plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3]);
  94. for (i = 0; i < frame->nb_side_data; i++) {
  95. AVFrameSideData *sd = frame->side_data[i];
  96. av_log(ctx, AV_LOG_INFO, " side data - ");
  97. switch (sd->type) {
  98. case AV_FRAME_DATA_PANSCAN:
  99. av_log(ctx, AV_LOG_INFO, "pan/scan");
  100. break;
  101. case AV_FRAME_DATA_A53_CC:
  102. av_log(ctx, AV_LOG_INFO, "A/53 closed captions (%d bytes)", sd->size);
  103. break;
  104. case AV_FRAME_DATA_STEREO3D:
  105. dump_stereo3d(ctx, sd);
  106. break;
  107. case AV_FRAME_DATA_DISPLAYMATRIX:
  108. av_log(ctx, AV_LOG_INFO, "displaymatrix: rotation of %.2f degrees",
  109. av_display_rotation_get((int32_t *)sd->data));
  110. break;
  111. case AV_FRAME_DATA_AFD:
  112. av_log(ctx, AV_LOG_INFO, "afd: value of %"PRIu8, sd->data[0]);
  113. break;
  114. default:
  115. av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)",
  116. sd->type, sd->size);
  117. break;
  118. }
  119. av_log(ctx, AV_LOG_INFO, "\n");
  120. }
  121. showinfo->frame++;
  122. return ff_filter_frame(inlink->dst->outputs[0], frame);
  123. }
  124. static int config_props(AVFilterContext *ctx, AVFilterLink *link, int is_out)
  125. {
  126. av_log(ctx, AV_LOG_INFO, "config %s time_base: %d/%d, frame_rate: %d/%d\n",
  127. is_out ? "out" : "in",
  128. link->time_base.num, link->time_base.den,
  129. link->frame_rate.num, link->frame_rate.den);
  130. return 0;
  131. }
  132. static int config_props_in(AVFilterLink *link)
  133. {
  134. AVFilterContext *ctx = link->dst;
  135. return config_props(ctx, link, 0);
  136. }
  137. static int config_props_out(AVFilterLink *link)
  138. {
  139. AVFilterContext *ctx = link->src;
  140. return config_props(ctx, link, 1);
  141. }
  142. static const AVFilterPad avfilter_vf_showinfo_inputs[] = {
  143. {
  144. .name = "default",
  145. .type = AVMEDIA_TYPE_VIDEO,
  146. .get_video_buffer = ff_null_get_video_buffer,
  147. .filter_frame = filter_frame,
  148. .config_props = config_props_in,
  149. },
  150. { NULL }
  151. };
  152. static const AVFilterPad avfilter_vf_showinfo_outputs[] = {
  153. {
  154. .name = "default",
  155. .type = AVMEDIA_TYPE_VIDEO,
  156. .config_props = config_props_out,
  157. },
  158. { NULL }
  159. };
  160. AVFilter ff_vf_showinfo = {
  161. .name = "showinfo",
  162. .description = NULL_IF_CONFIG_SMALL("Show textual information for each video frame."),
  163. .priv_size = sizeof(ShowInfoContext),
  164. .inputs = avfilter_vf_showinfo_inputs,
  165. .outputs = avfilter_vf_showinfo_outputs,
  166. };