Browse code

Split out flv encoding.

Originally committed as revision 21050 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Niedermayer authored on 2010/01/07 13:42:39
Showing 6 changed files
... ...
@@ -128,7 +128,7 @@ OBJS-$(CONFIG_H263_DECODER)            += h263dec.o h263.o \
128 128
                                           mpegvideo.o error_resilience.o
129 129
 OBJS-$(CONFIG_H263_VAAPI_HWACCEL)      += vaapi_mpeg4.o
130 130
 OBJS-$(CONFIG_H263_ENCODER)            += mpegvideo_enc.o motion_est.o      \
131
-                                          ratecontrol.o h263.o mpeg12data.o \
131
+                                          ratecontrol.o h263.o flvenc.o mpeg12data.o \
132 132
                                           mpegvideo.o error_resilience.o
133 133
 OBJS-$(CONFIG_H264_DECODER)            += h264.o h264idct.o h264pred.o cabac.o \
134 134
                                           mpegvideo.o error_resilience.o
135 135
new file mode 100644
... ...
@@ -0,0 +1,27 @@
0
+/*
1
+ * FLV specific private header.
2
+ * This file is part of FFmpeg.
3
+ *
4
+ * FFmpeg is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU Lesser General Public
6
+ * License as published by the Free Software Foundation; either
7
+ * version 2.1 of the License, or (at your option) any later version.
8
+ *
9
+ * FFmpeg is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * Lesser General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Lesser General Public
15
+ * License along with FFmpeg; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
18
+
19
+#ifndef AVCODEC_FLV_H
20
+#define AVCODEC_FLV_H
21
+
22
+void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number);
23
+void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, int last);
24
+
25
+#endif
26
+
0 27
new file mode 100644
... ...
@@ -0,0 +1,84 @@
0
+/*
1
+ * FLV Encoding specific code.
2
+ * This file is part of FFmpeg.
3
+ *
4
+ * FFmpeg is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU Lesser General Public
6
+ * License as published by the Free Software Foundation; either
7
+ * version 2.1 of the License, or (at your option) any later version.
8
+ *
9
+ * FFmpeg is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * Lesser General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Lesser General Public
15
+ * License along with FFmpeg; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
18
+
19
+#include "mpegvideo.h"
20
+#include "flv.h"
21
+
22
+void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number)
23
+{
24
+      int format;
25
+
26
+      align_put_bits(&s->pb);
27
+
28
+      put_bits(&s->pb, 17, 1);
29
+      put_bits(&s->pb, 5, (s->h263_flv-1)); /* 0: h263 escape codes 1: 11-bit escape codes */
30
+      put_bits(&s->pb, 8, (((int64_t)s->picture_number * 30 * s->avctx->time_base.num) / //FIXME use timestamp
31
+                           s->avctx->time_base.den) & 0xff); /* TemporalReference */
32
+      if (s->width == 352 && s->height == 288)
33
+        format = 2;
34
+      else if (s->width == 176 && s->height == 144)
35
+        format = 3;
36
+      else if (s->width == 128 && s->height == 96)
37
+        format = 4;
38
+      else if (s->width == 320 && s->height == 240)
39
+        format = 5;
40
+      else if (s->width == 160 && s->height == 120)
41
+        format = 6;
42
+      else if (s->width <= 255 && s->height <= 255)
43
+        format = 0; /* use 1 byte width & height */
44
+      else
45
+        format = 1; /* use 2 bytes width & height */
46
+      put_bits(&s->pb, 3, format); /* PictureSize */
47
+      if (format == 0) {
48
+        put_bits(&s->pb, 8, s->width);
49
+        put_bits(&s->pb, 8, s->height);
50
+      } else if (format == 1) {
51
+        put_bits(&s->pb, 16, s->width);
52
+        put_bits(&s->pb, 16, s->height);
53
+      }
54
+      put_bits(&s->pb, 2, s->pict_type == FF_P_TYPE); /* PictureType */
55
+      put_bits(&s->pb, 1, 1); /* DeblockingFlag: on */
56
+      put_bits(&s->pb, 5, s->qscale); /* Quantizer */
57
+      put_bits(&s->pb, 1, 0); /* ExtraInformation */
58
+
59
+      if(s->h263_aic){
60
+        s->y_dc_scale_table=
61
+          s->c_dc_scale_table= ff_aic_dc_scale_table;
62
+      }else{
63
+        s->y_dc_scale_table=
64
+          s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
65
+      }
66
+}
67
+
68
+void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, int last){
69
+    if(level < 64) { // 7-bit level
70
+        put_bits(pb, 1, 0);
71
+        put_bits(pb, 1, last);
72
+        put_bits(pb, 6, run);
73
+
74
+        put_sbits(pb, 7, slevel);
75
+    } else {
76
+        /* 11-bit level */
77
+        put_bits(pb, 1, 1);
78
+        put_bits(pb, 1, last);
79
+        put_bits(pb, 6, run);
80
+
81
+        put_sbits(pb, 11, slevel);
82
+    }
83
+}
... ...
@@ -41,6 +41,7 @@
41 41
 #include "mpeg4data.h"
42 42
 #include "mathops.h"
43 43
 #include "unary.h"
44
+#include "flv.h"
44 45
 
45 46
 //#undef NDEBUG
46 47
 //#include <assert.h>
... ...
@@ -170,52 +171,6 @@ static av_const int aspect_to_info(AVRational aspect){
170 170
     return FF_ASPECT_EXTENDED;
171 171
 }
172 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
-}
218
-
219 173
 void h263_encode_picture_header(MpegEncContext * s, int picture_number)
220 174
 {
221 175
     int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref;
... ...
@@ -1634,7 +1589,7 @@ static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n)
1634 1634
             code = get_rl_index(rl, last, run, level);
1635 1635
             put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
1636 1636
             if (code == rl->n) {
1637
-              if(s->h263_flv <= 1){
1637
+              if(!CONFIG_FLV_ENCODER || s->h263_flv <= 1){
1638 1638
                 put_bits(&s->pb, 1, last);
1639 1639
                 put_bits(&s->pb, 6, run);
1640 1640
 
... ...
@@ -1648,20 +1603,7 @@ static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n)
1648 1648
                     put_sbits(&s->pb, 6, slevel>>5);
1649 1649
                 }
1650 1650
               }else{
1651
-                if(level < 64) { // 7-bit level
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
-                    }
1651
+                    ff_flv2_encode_ac_esc(&s->pb, slevel, level, run, last);
1665 1652
               }
1666 1653
             } else {
1667 1654
                 put_bits(&s->pb, 1, sign);
... ...
@@ -814,7 +814,6 @@ void mpeg4_encode_mb(MpegEncContext *s,
814 814
                     DCTELEM block[6][64],
815 815
                     int motion_x, int motion_y);
816 816
 void h263_encode_picture_header(MpegEncContext *s, int picture_number);
817
-void ff_flv_encode_picture_header(MpegEncContext *s, int picture_number);
818 817
 void h263_encode_gob_header(MpegEncContext * s, int mb_line);
819 818
 int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir,
820 819
                         int *px, int *py);
... ...
@@ -35,6 +35,7 @@
35 35
 #include "msmpeg4.h"
36 36
 #include "faandct.h"
37 37
 #include "aandcttab.h"
38
+#include "flv.h"
38 39
 #include <limits.h>
39 40
 
40 41
 //#undef NDEBUG