comparison h263.c @ 10787:3f8e40fe25c2 libavcodec

Split out flv encoding.
author michael
date Thu, 07 Jan 2010 04:42:39 +0000
parents db269539f68f
children 0c8f9288b5e4
comparison
equal deleted inserted replaced
10786:db269539f68f 10787:3f8e40fe25c2
39 #include "mpegvideo.h" 39 #include "mpegvideo.h"
40 #include "h263data.h" 40 #include "h263data.h"
41 #include "mpeg4data.h" 41 #include "mpeg4data.h"
42 #include "mathops.h" 42 #include "mathops.h"
43 #include "unary.h" 43 #include "unary.h"
44 #include "flv.h"
44 45
45 //#undef NDEBUG 46 //#undef NDEBUG
46 //#include <assert.h> 47 //#include <assert.h>
47 48
48 // The defines below define the number of bits that are read at once for 49 // The defines below define the number of bits that are read at once for
166 return i; 167 return i;
167 } 168 }
168 } 169 }
169 170
170 return FF_ASPECT_EXTENDED; 171 return FF_ASPECT_EXTENDED;
171 }
172
173 void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number)
174 {
175 int format;
176
177 align_put_bits(&s->pb);
178
179 put_bits(&s->pb, 17, 1);
180 put_bits(&s->pb, 5, (s->h263_flv-1)); /* 0: h263 escape codes 1: 11-bit escape codes */
181 put_bits(&s->pb, 8, (((int64_t)s->picture_number * 30 * s->avctx->time_base.num) / //FIXME use timestamp
182 s->avctx->time_base.den) & 0xff); /* TemporalReference */
183 if (s->width == 352 && s->height == 288)
184 format = 2;
185 else if (s->width == 176 && s->height == 144)
186 format = 3;
187 else if (s->width == 128 && s->height == 96)
188 format = 4;
189 else if (s->width == 320 && s->height == 240)
190 format = 5;
191 else if (s->width == 160 && s->height == 120)
192 format = 6;
193 else if (s->width <= 255 && s->height <= 255)
194 format = 0; /* use 1 byte width & height */
195 else
196 format = 1; /* use 2 bytes width & height */
197 put_bits(&s->pb, 3, format); /* PictureSize */
198 if (format == 0) {
199 put_bits(&s->pb, 8, s->width);
200 put_bits(&s->pb, 8, s->height);
201 } else if (format == 1) {
202 put_bits(&s->pb, 16, s->width);
203 put_bits(&s->pb, 16, s->height);
204 }
205 put_bits(&s->pb, 2, s->pict_type == FF_P_TYPE); /* PictureType */
206 put_bits(&s->pb, 1, 1); /* DeblockingFlag: on */
207 put_bits(&s->pb, 5, s->qscale); /* Quantizer */
208 put_bits(&s->pb, 1, 0); /* ExtraInformation */
209
210 if(s->h263_aic){
211 s->y_dc_scale_table=
212 s->c_dc_scale_table= ff_aic_dc_scale_table;
213 }else{
214 s->y_dc_scale_table=
215 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
216 }
217 } 172 }
218 173
219 void h263_encode_picture_header(MpegEncContext * s, int picture_number) 174 void h263_encode_picture_header(MpegEncContext * s, int picture_number)
220 { 175 {
221 int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref; 176 int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref;
1632 level = -level; 1587 level = -level;
1633 } 1588 }
1634 code = get_rl_index(rl, last, run, level); 1589 code = get_rl_index(rl, last, run, level);
1635 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); 1590 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
1636 if (code == rl->n) { 1591 if (code == rl->n) {
1637 if(s->h263_flv <= 1){ 1592 if(!CONFIG_FLV_ENCODER || s->h263_flv <= 1){
1638 put_bits(&s->pb, 1, last); 1593 put_bits(&s->pb, 1, last);
1639 put_bits(&s->pb, 6, run); 1594 put_bits(&s->pb, 6, run);
1640 1595
1641 assert(slevel != 0); 1596 assert(slevel != 0);
1642 1597
1646 put_bits(&s->pb, 8, 128); 1601 put_bits(&s->pb, 8, 128);
1647 put_sbits(&s->pb, 5, slevel); 1602 put_sbits(&s->pb, 5, slevel);
1648 put_sbits(&s->pb, 6, slevel>>5); 1603 put_sbits(&s->pb, 6, slevel>>5);
1649 } 1604 }
1650 }else{ 1605 }else{
1651 if(level < 64) { // 7-bit level 1606 ff_flv2_encode_ac_esc(&s->pb, slevel, level, run, last);
1652 put_bits(&s->pb, 1, 0);
1653 put_bits(&s->pb, 1, last);
1654 put_bits(&s->pb, 6, run);
1655
1656 put_sbits(&s->pb, 7, slevel);
1657 } else {
1658 /* 11-bit level */
1659 put_bits(&s->pb, 1, 1);
1660 put_bits(&s->pb, 1, last);
1661 put_bits(&s->pb, 6, run);
1662
1663 put_sbits(&s->pb, 11, slevel);
1664 }
1665 } 1607 }
1666 } else { 1608 } else {
1667 put_bits(&s->pb, 1, sign); 1609 put_bits(&s->pb, 1, sign);
1668 } 1610 }
1669 last_non_zero = i; 1611 last_non_zero = i;