annotate x264.c @ 2569:980f66959698 libavcodec

indentation fix
author mru
date Sat, 19 Mar 2005 12:30:01 +0000
parents f06d5bf3da71
children 37cdd1a1174a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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>
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
22
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
23 typedef struct X264Context {
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
24 x264_param_t params;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
25 x264_t *enc;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
26 x264_picture_t pic;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
27 AVFrame out_pic;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
28 } X264Context;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
29
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
30 static void
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
31 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
32 {
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
33 static const int level_map[] = {
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
34 [X264_LOG_ERROR] = AV_LOG_ERROR,
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
35 [X264_LOG_WARNING] = AV_LOG_ERROR,
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
36 [X264_LOG_INFO] = AV_LOG_INFO,
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
37 [X264_LOG_DEBUG] = AV_LOG_DEBUG
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
38 };
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 if(level < 0 || level > X264_LOG_DEBUG)
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
41 return;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
42
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
43 av_vlog(p, level_map[level], fmt, args);
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
44 }
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 static int
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
48 encode_nals(u_char *buf, int size, x264_nal_t *nals, int nnal)
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
49 {
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
50 u_char *p = buf;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
51 int i;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
52
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
53 for(i = 0; i < nnal; i++){
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
54 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
55 if(s < 0)
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
56 return -1;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
57 p += s;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
58 }
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 return p - buf;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
61 }
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 extern int
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
64 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
65 {
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
66 X264Context *x4 = ctx->priv_data;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
67 AVFrame *frame = data;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
68 x264_nal_t *nal;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
69 int nnal, i;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
70 x264_picture_t pic_out;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
71
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
72 x4->pic.img.i_csp = X264_CSP_I420;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
73 x4->pic.img.i_plane = 3;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
74
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
75 for(i = 0; i < 3; i++){
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
76 x4->pic.img.plane[i] = frame->data[i];
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
77 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
78 }
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 x4->pic.i_pts = frame->pts;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
81 x4->pic.i_type = X264_TYPE_AUTO;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
82
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
83 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
84 return -1;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
85
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
86 bufsize = encode_nals(buf, bufsize, nal, nnal);
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
87 if(bufsize < 0)
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
88 return -1;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
89
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
90 /* FIXME: dts */
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
91 x4->out_pic.pts = pic_out.i_pts;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
92
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
93 switch(pic_out.i_type){
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
94 case X264_TYPE_IDR:
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
95 case X264_TYPE_I:
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
96 x4->out_pic.pict_type = FF_I_TYPE;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
97 break;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
98 case X264_TYPE_P:
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
99 x4->out_pic.pict_type = FF_P_TYPE;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
100 break;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
101 case X264_TYPE_B:
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
102 case X264_TYPE_BREF:
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
103 x4->out_pic.pict_type = FF_B_TYPE;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
104 break;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
105 }
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
106
2563
1e52ef4887b5 set constant QP from AVCodecContext.global_quality.
mru
parents: 2556
diff changeset
107 x4->out_pic.key_frame = pic_out.i_type == X264_TYPE_IDR;
1e52ef4887b5 set constant QP from AVCodecContext.global_quality.
mru
parents: 2556
diff changeset
108 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
109
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
110 return bufsize;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
111 }
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 static int
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
114 X264_close(AVCodecContext *avctx)
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
115 {
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
116 X264Context *x4 = avctx->priv_data;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
117
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
118 if(x4->enc)
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
119 x264_encoder_close(x4->enc);
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
120
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
121 return 0;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
122 }
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 extern int
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
125 X264_init(AVCodecContext *avctx)
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
126 {
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
127 X264Context *x4 = avctx->priv_data;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
128
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
129 x264_param_default(&x4->params);
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
130
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
131 x4->params.pf_log = X264_log;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
132 x4->params.p_log_private = avctx;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
133
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
134 x4->params.i_keyint_max = avctx->gop_size;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
135 x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
136 x4->params.rc.i_rc_buffer_size = avctx->rc_buffer_size / 1000;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
137 if(avctx->rc_buffer_size)
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
138 x4->params.rc.b_cbr = 1;
2569
980f66959698 indentation fix
mru
parents: 2568
diff changeset
139 x4->params.i_bframe = avctx->max_b_frames;
980f66959698 indentation fix
mru
parents: 2568
diff changeset
140 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
141
2556
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
142 x4->params.rc.i_qp_min = avctx->qmin;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
143 x4->params.rc.i_qp_max = avctx->qmax;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
144 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
145
2563
1e52ef4887b5 set constant QP from AVCodecContext.global_quality.
mru
parents: 2556
diff changeset
146 if(avctx->flags & CODEC_FLAG_QSCALE && avctx->global_quality > 0)
1e52ef4887b5 set constant QP from AVCodecContext.global_quality.
mru
parents: 2556
diff changeset
147 x4->params.rc.i_qp_constant =
1e52ef4887b5 set constant QP from AVCodecContext.global_quality.
mru
parents: 2556
diff changeset
148 12 + 6 * log2((double) avctx->global_quality / FF_QP2LAMBDA);
1e52ef4887b5 set constant QP from AVCodecContext.global_quality.
mru
parents: 2556
diff changeset
149
2556
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
150 x4->params.i_width = avctx->width;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
151 x4->params.i_height = avctx->height;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
152 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
153 x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
154 x4->params.i_fps_num = avctx->frame_rate;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
155 x4->params.i_fps_den = avctx->frame_rate_base;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
156
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
157 x4->enc = x264_encoder_open(&x4->params);
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
158 if(!x4->enc)
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
159 return -1;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
160
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
161 avctx->coded_frame = &x4->out_pic;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
162
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
163 return 0;
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
164 }
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 AVCodec x264_encoder = {
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
167 .name = "h264",
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
168 .type = CODEC_TYPE_VIDEO,
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
169 .id = CODEC_ID_H264,
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
170 .priv_data_size = sizeof(X264Context),
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
171 .init = X264_init,
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
172 .encode = X264_frame,
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
173 .close = X264_close,
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
174 .pix_fmts = (enum PixelFormat[]) { PIX_FMT_YUV420P, -1 }
e5af3bc1d038 H.264 encoding with x264 by (Mns Rullgrd <mru inprovide com>)
michael
parents:
diff changeset
175 };