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.

99 lines
3.2KB

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