comparison flvenc.c @ 10787:3f8e40fe25c2 libavcodec

Split out flv encoding.
author michael
date Thu, 07 Jan 2010 04:42:39 +0000
parents
children edaaa3fa540c
comparison
equal deleted inserted replaced
10786:db269539f68f 10787:3f8e40fe25c2
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
20 #include "mpegvideo.h"
21 #include "flv.h"
22
23 void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number)
24 {
25 int format;
26
27 align_put_bits(&s->pb);
28
29 put_bits(&s->pb, 17, 1);
30 put_bits(&s->pb, 5, (s->h263_flv-1)); /* 0: h263 escape codes 1: 11-bit escape codes */
31 put_bits(&s->pb, 8, (((int64_t)s->picture_number * 30 * s->avctx->time_base.num) / //FIXME use timestamp
32 s->avctx->time_base.den) & 0xff); /* TemporalReference */
33 if (s->width == 352 && s->height == 288)
34 format = 2;
35 else if (s->width == 176 && s->height == 144)
36 format = 3;
37 else if (s->width == 128 && s->height == 96)
38 format = 4;
39 else if (s->width == 320 && s->height == 240)
40 format = 5;
41 else if (s->width == 160 && s->height == 120)
42 format = 6;
43 else if (s->width <= 255 && s->height <= 255)
44 format = 0; /* use 1 byte width & height */
45 else
46 format = 1; /* use 2 bytes width & height */
47 put_bits(&s->pb, 3, format); /* PictureSize */
48 if (format == 0) {
49 put_bits(&s->pb, 8, s->width);
50 put_bits(&s->pb, 8, s->height);
51 } else if (format == 1) {
52 put_bits(&s->pb, 16, s->width);
53 put_bits(&s->pb, 16, s->height);
54 }
55 put_bits(&s->pb, 2, s->pict_type == FF_P_TYPE); /* PictureType */
56 put_bits(&s->pb, 1, 1); /* DeblockingFlag: on */
57 put_bits(&s->pb, 5, s->qscale); /* Quantizer */
58 put_bits(&s->pb, 1, 0); /* ExtraInformation */
59
60 if(s->h263_aic){
61 s->y_dc_scale_table=
62 s->c_dc_scale_table= ff_aic_dc_scale_table;
63 }else{
64 s->y_dc_scale_table=
65 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
66 }
67 }
68
69 void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, int last){
70 if(level < 64) { // 7-bit level
71 put_bits(pb, 1, 0);
72 put_bits(pb, 1, last);
73 put_bits(pb, 6, run);
74
75 put_sbits(pb, 7, slevel);
76 } else {
77 /* 11-bit level */
78 put_bits(pb, 1, 1);
79 put_bits(pb, 1, last);
80 put_bits(pb, 6, run);
81
82 put_sbits(pb, 11, slevel);
83 }
84 }