venc_data_dump.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <stdio.h>
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #include "decode_simple.h"
  22. #include "libavutil/common.h"
  23. #include "libavutil/dict.h"
  24. #include "libavutil/error.h"
  25. #include "libavutil/video_enc_params.h"
  26. #include "libavformat/avformat.h"
  27. #include "libavcodec/avcodec.h"
  28. static int process_frame(DecodeContext *dc, AVFrame *frame)
  29. {
  30. AVFrameSideData *sd;
  31. if (!frame)
  32. return 0;
  33. fprintf(stdout, "frame %"PRId64"\n", dc->decoder->frame_num - 1);
  34. sd = av_frame_get_side_data(frame, AV_FRAME_DATA_VIDEO_ENC_PARAMS);
  35. if (sd) {
  36. AVVideoEncParams *par = (AVVideoEncParams*)sd->data;
  37. fprintf(stdout, "AVVideoEncParams %d\n", par->type);
  38. fprintf(stdout, "qp %d\n", par->qp);
  39. for (int i = 0; i < FF_ARRAY_ELEMS(par->delta_qp); i++)
  40. for (int j = 0; j < FF_ARRAY_ELEMS(par->delta_qp[i]); j++) {
  41. if (par->delta_qp[i][j])
  42. fprintf(stdout, "delta_qp[%d][%d] %"PRId32"\n", i, j, par->delta_qp[i][j]);
  43. }
  44. if (par->nb_blocks) {
  45. fprintf(stdout, "nb_blocks %d\n", par->nb_blocks);
  46. for (int i = 0; i < par->nb_blocks; i++) {
  47. AVVideoBlockParams *b = av_video_enc_params_block(par, i);
  48. fprintf(stdout, "block %d %d:%d %dx%d %"PRId32"\n",
  49. i, b->src_x, b->src_y, b->w, b->h, b->delta_qp);
  50. }
  51. }
  52. }
  53. return 0;
  54. }
  55. int main(int argc, char **argv)
  56. {
  57. DecodeContext dc;
  58. unsigned int stream_idx, max_frames;
  59. const char *filename, *thread_type = NULL, *nb_threads = NULL;
  60. int ret = 0;
  61. if (argc <= 3) {
  62. fprintf(stderr, "Usage: %s <input file> <stream index> <max frame count> [<thread count> <thread type>]\n", argv[0]);
  63. return 0;
  64. }
  65. filename = argv[1];
  66. stream_idx = strtol(argv[2], NULL, 0);
  67. max_frames = strtol(argv[3], NULL, 0);
  68. if (argc > 5) {
  69. nb_threads = argv[4];
  70. thread_type = argv[5];
  71. }
  72. ret = ds_open(&dc, filename, stream_idx);
  73. if (ret < 0)
  74. goto finish;
  75. dc.process_frame = process_frame;
  76. dc.max_frames = max_frames;
  77. ret = av_dict_set(&dc.decoder_opts, "threads", nb_threads, 0);
  78. ret |= av_dict_set(&dc.decoder_opts, "thread_type", thread_type, 0);
  79. ret |= av_dict_set(&dc.decoder_opts, "export_side_data", "venc_params", 0);
  80. if (ret < 0)
  81. goto finish;
  82. ret = ds_run(&dc);
  83. finish:
  84. ds_free(&dc);
  85. return ret;
  86. }