Mercurial > libavcodec.hg
annotate x264.c @ 2792:0a8c847ad5e7 libavcodec
skip_idct
skip_frame
skip_loop_filter
author | michael |
---|---|
date | Thu, 14 Jul 2005 21:39:36 +0000 |
parents | cdf74a048614 |
children | dd5a1abbf9a3 |
rev | line source |
---|---|
2556
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
1 /* |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
2 * H.264 encoding using the x264 library |
2568
f06d5bf3da71
B frames and CABAC/CAVLC selection by Erik Slagter (erik at slagter dot name)
mru
parents:
2563
diff
changeset
|
3 * Copyright (C) 2005 Mans Rullgard <mru@inprovide.com> |
2556
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
4 * |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
8 * version 2 of the License, or (at your option) any later version. |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
9 * |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
14 * |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
18 */ |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
19 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
20 #include "avcodec.h" |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
21 #include <x264.h> |
2784
cdf74a048614
patch from http://www.freebsd.org/cgi/cvsweb.cgi/ports/multimedia/ffmpeg-devel/files/patch-libavcodec::x264.c
michael
parents:
2742
diff
changeset
|
22 #include <math.h> |
2556
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
23 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
24 typedef struct X264Context { |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
25 x264_param_t params; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
26 x264_t *enc; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
27 x264_picture_t pic; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
28 AVFrame out_pic; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
29 } X264Context; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
30 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
31 static void |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
32 X264_log(void *p, int level, const char *fmt, va_list args) |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
33 { |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
34 static const int level_map[] = { |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
35 [X264_LOG_ERROR] = AV_LOG_ERROR, |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
36 [X264_LOG_WARNING] = AV_LOG_ERROR, |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
37 [X264_LOG_INFO] = AV_LOG_INFO, |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
38 [X264_LOG_DEBUG] = AV_LOG_DEBUG |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
39 }; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
40 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
41 if(level < 0 || level > X264_LOG_DEBUG) |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
42 return; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
43 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
44 av_vlog(p, level_map[level], fmt, args); |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
45 } |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
46 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
47 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
48 static int |
2603 | 49 encode_nals(uint8_t *buf, int size, x264_nal_t *nals, int nnal) |
2556
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
50 { |
2603 | 51 uint8_t *p = buf; |
2556
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
52 int i; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
53 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
54 for(i = 0; i < nnal; i++){ |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
55 int s = x264_nal_encode(p, &size, 1, nals + i); |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
56 if(s < 0) |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
57 return -1; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
58 p += s; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
59 } |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
60 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
61 return p - buf; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
62 } |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
63 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
64 extern int |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
65 X264_frame(AVCodecContext *ctx, uint8_t *buf, int bufsize, void *data) |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
66 { |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
67 X264Context *x4 = ctx->priv_data; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
68 AVFrame *frame = data; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
69 x264_nal_t *nal; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
70 int nnal, i; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
71 x264_picture_t pic_out; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
72 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
73 x4->pic.img.i_csp = X264_CSP_I420; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
74 x4->pic.img.i_plane = 3; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
75 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
76 for(i = 0; i < 3; i++){ |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
77 x4->pic.img.plane[i] = frame->data[i]; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
78 x4->pic.img.i_stride[i] = frame->linesize[i]; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
79 } |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
80 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
81 x4->pic.i_pts = frame->pts; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
82 x4->pic.i_type = X264_TYPE_AUTO; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
83 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
84 if(x264_encoder_encode(x4->enc, &nal, &nnal, &x4->pic, &pic_out)) |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
85 return -1; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
86 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
87 bufsize = encode_nals(buf, bufsize, nal, nnal); |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
88 if(bufsize < 0) |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
89 return -1; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
90 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
91 /* FIXME: dts */ |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
92 x4->out_pic.pts = pic_out.i_pts; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
93 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
94 switch(pic_out.i_type){ |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
95 case X264_TYPE_IDR: |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
96 case X264_TYPE_I: |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
97 x4->out_pic.pict_type = FF_I_TYPE; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
98 break; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
99 case X264_TYPE_P: |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
100 x4->out_pic.pict_type = FF_P_TYPE; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
101 break; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
102 case X264_TYPE_B: |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
103 case X264_TYPE_BREF: |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
104 x4->out_pic.pict_type = FF_B_TYPE; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
105 break; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
106 } |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
107 |
2563 | 108 x4->out_pic.key_frame = pic_out.i_type == X264_TYPE_IDR; |
109 x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; | |
2556
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
110 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
111 return bufsize; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
112 } |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
113 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
114 static int |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
115 X264_close(AVCodecContext *avctx) |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
116 { |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
117 X264Context *x4 = avctx->priv_data; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
118 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
119 if(x4->enc) |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
120 x264_encoder_close(x4->enc); |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
121 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
122 return 0; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
123 } |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
124 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
125 extern int |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
126 X264_init(AVCodecContext *avctx) |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
127 { |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
128 X264Context *x4 = avctx->priv_data; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
129 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
130 x264_param_default(&x4->params); |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
131 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
132 x4->params.pf_log = X264_log; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
133 x4->params.p_log_private = avctx; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
134 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
135 x4->params.i_keyint_max = avctx->gop_size; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
136 x4->params.rc.i_bitrate = avctx->bit_rate / 1000; |
2682 | 137 x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000; |
2556
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
138 if(avctx->rc_buffer_size) |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
139 x4->params.rc.b_cbr = 1; |
2569 | 140 x4->params.i_bframe = avctx->max_b_frames; |
141 x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC; | |
2568
f06d5bf3da71
B frames and CABAC/CAVLC selection by Erik Slagter (erik at slagter dot name)
mru
parents:
2563
diff
changeset
|
142 |
2556
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
143 x4->params.rc.i_qp_min = avctx->qmin; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
144 x4->params.rc.i_qp_max = avctx->qmax; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
145 x4->params.rc.i_qp_step = avctx->max_qdiff; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
146 |
2563 | 147 if(avctx->flags & CODEC_FLAG_QSCALE && avctx->global_quality > 0) |
148 x4->params.rc.i_qp_constant = | |
149 12 + 6 * log2((double) avctx->global_quality / FF_QP2LAMBDA); | |
150 | |
2556
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
151 x4->params.i_width = avctx->width; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
152 x4->params.i_height = avctx->height; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
153 x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
154 x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den; |
2637 | 155 x4->params.i_fps_num = avctx->time_base.den; |
156 x4->params.i_fps_den = avctx->time_base.num; | |
2556
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
157 |
2742 | 158 x4->params.i_threads = avctx->thread_count; |
159 | |
2556
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
160 x4->enc = x264_encoder_open(&x4->params); |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
161 if(!x4->enc) |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
162 return -1; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
163 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
164 avctx->coded_frame = &x4->out_pic; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
165 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
166 return 0; |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
167 } |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
168 |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
169 AVCodec x264_encoder = { |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
170 .name = "h264", |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
171 .type = CODEC_TYPE_VIDEO, |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
172 .id = CODEC_ID_H264, |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
173 .priv_data_size = sizeof(X264Context), |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
174 .init = X264_init, |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
175 .encode = X264_frame, |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
176 .close = X264_close, |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
177 .pix_fmts = (enum PixelFormat[]) { PIX_FMT_YUV420P, -1 } |
e5af3bc1d038
H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff
changeset
|
178 }; |