ratecontrol.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Ratecontrol
  3. * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
  4. * Copyright (c) 2002-2004 Michael Niedermayer
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVCODEC_RATECONTROL_H
  23. #define AVCODEC_RATECONTROL_H
  24. /**
  25. * @file ratecontrol.h
  26. * ratecontrol header.
  27. */
  28. #include "eval.h"
  29. typedef struct Predictor{
  30. double coeff;
  31. double count;
  32. double decay;
  33. } Predictor;
  34. typedef struct RateControlEntry{
  35. int pict_type;
  36. float qscale;
  37. int mv_bits;
  38. int i_tex_bits;
  39. int p_tex_bits;
  40. int misc_bits;
  41. int header_bits;
  42. uint64_t expected_bits;
  43. int new_pict_type;
  44. float new_qscale;
  45. int mc_mb_var_sum;
  46. int mb_var_sum;
  47. int i_count;
  48. int skip_count;
  49. int f_code;
  50. int b_code;
  51. }RateControlEntry;
  52. /**
  53. * rate control context.
  54. */
  55. typedef struct RateControlContext{
  56. FILE *stats_file;
  57. int num_entries; ///< number of RateControlEntries
  58. RateControlEntry *entry;
  59. double buffer_index; ///< amount of bits in the video/audio buffer
  60. Predictor pred[5];
  61. double short_term_qsum; ///< sum of recent qscales
  62. double short_term_qcount; ///< count of recent qscales
  63. double pass1_rc_eq_output_sum;///< sum of the output of the rc equation, this is used for normalization
  64. double pass1_wanted_bits; ///< bits which should have been outputed by the pass1 code (including complexity init)
  65. double last_qscale;
  66. double last_qscale_for[5]; ///< last qscale for a specific pict type, used for max_diff & ipb factor stuff
  67. int last_mc_mb_var_sum;
  68. int last_mb_var_sum;
  69. uint64_t i_cplx_sum[5];
  70. uint64_t p_cplx_sum[5];
  71. uint64_t mv_bits_sum[5];
  72. uint64_t qscale_sum[5];
  73. int frame_count[5];
  74. int last_non_b_pict_type;
  75. void *non_lavc_opaque; ///< context for non lavc rc code (for example xvid)
  76. float dry_run_qscale; ///< for xvid rc
  77. int last_picture_number; ///< for xvid rc
  78. AVEvalExpr * rc_eq_eval;
  79. }RateControlContext;
  80. struct MpegEncContext;
  81. /* rate control */
  82. int ff_rate_control_init(struct MpegEncContext *s);
  83. float ff_rate_estimate_qscale(struct MpegEncContext *s, int dry_run);
  84. void ff_write_pass1_stats(struct MpegEncContext *s);
  85. void ff_rate_control_uninit(struct MpegEncContext *s);
  86. int ff_vbv_update(struct MpegEncContext *s, int frame_size);
  87. void ff_get_2pass_fcode(struct MpegEncContext *s);
  88. int ff_xvid_rate_control_init(struct MpegEncContext *s);
  89. void ff_xvid_rate_control_uninit(struct MpegEncContext *s);
  90. float ff_xvid_rate_estimate_qscale(struct MpegEncContext *s, int dry_run);
  91. #endif /* AVCODEC_RATECONTROL_H */