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.

73 lines
2.1KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (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
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include <stdint.h>
  19. // for FF_QSCALE_TYPE_*
  20. #include "libavcodec/internal.h"
  21. #include "libavutil/frame.h"
  22. #include "libavutil/mem.h"
  23. #include "libavutil/video_enc_params.h"
  24. #include "qp_table.h"
  25. int ff_qp_table_extract(AVFrame *frame, int8_t **table, int *table_w, int *table_h,
  26. int *qscale_type)
  27. {
  28. AVFrameSideData *sd;
  29. AVVideoEncParams *par;
  30. unsigned int mb_h = (frame->height + 15) / 16;
  31. unsigned int mb_w = (frame->width + 15) / 16;
  32. unsigned int nb_mb = mb_h * mb_w;
  33. unsigned int block_idx;
  34. *table = NULL;
  35. sd = av_frame_get_side_data(frame, AV_FRAME_DATA_VIDEO_ENC_PARAMS);
  36. if (!sd)
  37. return 0;
  38. par = (AVVideoEncParams*)sd->data;
  39. if (par->type != AV_VIDEO_ENC_PARAMS_MPEG2 ||
  40. (par->nb_blocks != 0 && par->nb_blocks != nb_mb))
  41. return AVERROR(ENOSYS);
  42. *table = av_malloc(nb_mb);
  43. if (!*table)
  44. return AVERROR(ENOMEM);
  45. if (table_w)
  46. *table_w = mb_w;
  47. if (table_h)
  48. *table_h = mb_h;
  49. if (qscale_type)
  50. *qscale_type = FF_QSCALE_TYPE_MPEG2;
  51. if (par->nb_blocks == 0) {
  52. memset(*table, par->qp, nb_mb);
  53. return 0;
  54. }
  55. for (block_idx = 0; block_idx < nb_mb; block_idx++) {
  56. AVVideoBlockParams *b = av_video_enc_params_block(par, block_idx);
  57. (*table)[block_idx] = par->qp + b->delta_qp;
  58. }
  59. return 0;
  60. }