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.

97 lines
3.2KB

  1. /*
  2. * FLV Encoding specific code.
  3. * This file is part of FFmpeg.
  4. *
  5. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include "mpegvideo.h"
  20. #include "flv.h"
  21. void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number)
  22. {
  23. int format;
  24. align_put_bits(&s->pb);
  25. put_bits(&s->pb, 17, 1);
  26. put_bits(&s->pb, 5, (s->h263_flv-1)); /* 0: h263 escape codes 1: 11-bit escape codes */
  27. put_bits(&s->pb, 8, (((int64_t)s->picture_number * 30 * s->avctx->time_base.num) / //FIXME use timestamp
  28. s->avctx->time_base.den) & 0xff); /* TemporalReference */
  29. if (s->width == 352 && s->height == 288)
  30. format = 2;
  31. else if (s->width == 176 && s->height == 144)
  32. format = 3;
  33. else if (s->width == 128 && s->height == 96)
  34. format = 4;
  35. else if (s->width == 320 && s->height == 240)
  36. format = 5;
  37. else if (s->width == 160 && s->height == 120)
  38. format = 6;
  39. else if (s->width <= 255 && s->height <= 255)
  40. format = 0; /* use 1 byte width & height */
  41. else
  42. format = 1; /* use 2 bytes width & height */
  43. put_bits(&s->pb, 3, format); /* PictureSize */
  44. if (format == 0) {
  45. put_bits(&s->pb, 8, s->width);
  46. put_bits(&s->pb, 8, s->height);
  47. } else if (format == 1) {
  48. put_bits(&s->pb, 16, s->width);
  49. put_bits(&s->pb, 16, s->height);
  50. }
  51. put_bits(&s->pb, 2, s->pict_type == FF_P_TYPE); /* PictureType */
  52. put_bits(&s->pb, 1, 1); /* DeblockingFlag: on */
  53. put_bits(&s->pb, 5, s->qscale); /* Quantizer */
  54. put_bits(&s->pb, 1, 0); /* ExtraInformation */
  55. if(s->h263_aic){
  56. s->y_dc_scale_table=
  57. s->c_dc_scale_table= ff_aic_dc_scale_table;
  58. }else{
  59. s->y_dc_scale_table=
  60. s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
  61. }
  62. }
  63. void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, int last){
  64. if(level < 64) { // 7-bit level
  65. put_bits(pb, 1, 0);
  66. put_bits(pb, 1, last);
  67. put_bits(pb, 6, run);
  68. put_sbits(pb, 7, slevel);
  69. } else {
  70. /* 11-bit level */
  71. put_bits(pb, 1, 1);
  72. put_bits(pb, 1, last);
  73. put_bits(pb, 6, run);
  74. put_sbits(pb, 11, slevel);
  75. }
  76. }
  77. AVCodec flv_encoder = {
  78. "flv",
  79. CODEC_TYPE_VIDEO,
  80. CODEC_ID_FLV1,
  81. sizeof(MpegEncContext),
  82. MPV_encode_init,
  83. MPV_encode_picture,
  84. MPV_encode_end,
  85. .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
  86. .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"),
  87. };