~phatforge/libav/fixup

« back to all changes in this revision

Viewing changes to libavcodec/libx264.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2011-04-30 14:27:42 UTC
  • mfrom: (1.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110430142742-quvblxk1tj6adlh5
Tags: 4:0.7~b1-1ubuntu1
* Merge from debian. Remaining changes:
  - don't build against libfaad, libdirac, librtmp and libopenjpeg
    (all in universe)
  - explicitly --enable-pic on powerpc, cf. LP #654666
  - different arm configure bits that should probably better be
    merged into debian
* Cherry-picked from git: 
  - install doc/APIChanges and refer to them in NEWS.Debian (Closes: #623682)
  - don't try to install non-existing documentation, fixes FTBFS on powerpc

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * H.264 encoding using the x264 library
3
3
 * Copyright (C) 2005  Mans Rullgard <mans@mansr.com>
4
4
 *
5
 
 * This file is part of FFmpeg.
 
5
 * This file is part of Libav.
6
6
 *
7
 
 * FFmpeg is free software; you can redistribute it and/or
 
7
 * Libav is free software; you can redistribute it and/or
8
8
 * modify it under the terms of the GNU Lesser General Public
9
9
 * License as published by the Free Software Foundation; either
10
10
 * version 2.1 of the License, or (at your option) any later version.
11
11
 *
12
 
 * FFmpeg is distributed in the hope that it will be useful,
 
12
 * Libav is distributed in the hope that it will be useful,
13
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
15
 * Lesser General Public License for more details.
16
16
 *
17
17
 * You should have received a copy of the GNU Lesser General Public
18
 
 * License along with FFmpeg; if not, write to the Free Software
 
18
 * License along with Libav; if not, write to the Free Software
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 */
21
21
 
89
89
    int nnal, i;
90
90
    x264_picture_t pic_out;
91
91
 
 
92
    x264_picture_init( &x4->pic );
92
93
    x4->pic.img.i_csp   = X264_CSP_I420;
93
94
    x4->pic.img.i_plane = 3;
94
95
 
99
100
        }
100
101
 
101
102
        x4->pic.i_pts  = frame->pts;
102
 
        x4->pic.i_type = X264_TYPE_AUTO;
 
103
        x4->pic.i_type =
 
104
            frame->pict_type == FF_I_TYPE ? X264_TYPE_KEYFRAME :
 
105
            frame->pict_type == FF_P_TYPE ? X264_TYPE_P :
 
106
            frame->pict_type == FF_B_TYPE ? X264_TYPE_B :
 
107
                                            X264_TYPE_AUTO;
 
108
        if (x4->params.b_tff != frame->top_field_first) {
 
109
            x4->params.b_tff = frame->top_field_first;
 
110
            x264_encoder_reconfig(x4->enc, &x4->params);
 
111
        }
103
112
    }
104
113
 
 
114
    do {
105
115
    if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
106
116
        return -1;
107
117
 
108
118
    bufsize = encode_nals(ctx, buf, bufsize, nal, nnal, 0);
109
119
    if (bufsize < 0)
110
120
        return -1;
 
121
    } while (!bufsize && !frame && x264_encoder_delayed_frames(x4->enc));
111
122
 
112
123
    /* FIXME: libx264 now provides DTS, but AVFrame doesn't have a field for it. */
113
124
    x4->out_pic.pts = pic_out.i_pts;
156
167
    x4->params.p_log_private        = avctx;
157
168
 
158
169
    x4->params.i_keyint_max         = avctx->gop_size;
 
170
    x4->params.b_intra_refresh      = avctx->flags2 & CODEC_FLAG2_INTRA_REFRESH;
159
171
    x4->params.rc.i_bitrate         = avctx->bit_rate       / 1000;
160
172
    x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
161
173
    x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate    / 1000;
166
178
        if (avctx->crf) {
167
179
            x4->params.rc.i_rc_method   = X264_RC_CRF;
168
180
            x4->params.rc.f_rf_constant = avctx->crf;
 
181
            x4->params.rc.f_rf_constant_max = avctx->crf_max;
169
182
        } else if (avctx->cqp > -1) {
170
183
            x4->params.rc.i_rc_method   = X264_RC_CQP;
171
184
            x4->params.rc.i_qp_constant = avctx->cqp;
264
277
    if (avctx->level > 0)
265
278
        x4->params.i_level_idc = avctx->level;
266
279
 
267
 
    x4->params.rc.f_rate_tolerance =
268
 
        (float)avctx->bit_rate_tolerance/avctx->bit_rate;
269
 
 
270
 
    if ((avctx->rc_buffer_size != 0) &&
 
280
    if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy &&
271
281
        (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
272
282
        x4->params.rc.f_vbv_buffer_init =
273
283
            (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size;
274
 
    } else
275
 
        x4->params.rc.f_vbv_buffer_init = 0.9;
 
284
    }
276
285
 
277
286
    x4->params.rc.b_mb_tree               = !!(avctx->flags2 & CODEC_FLAG2_MBTREE);
278
287
    x4->params.rc.f_ip_factor             = 1 / fabs(avctx->i_quant_factor);
289
298
 
290
299
    x4->params.b_interlaced   = avctx->flags & CODEC_FLAG_INTERLACED_DCT;
291
300
 
 
301
    x4->params.i_slice_count  = avctx->slices;
 
302
 
 
303
    x4->params.vui.b_fullrange = avctx->pix_fmt == PIX_FMT_YUVJ420P;
 
304
 
292
305
    if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER)
293
306
        x4->params.b_repeat_headers = 0;
294
307
 
315
328
    return 0;
316
329
}
317
330
 
318
 
AVCodec libx264_encoder = {
 
331
AVCodec ff_libx264_encoder = {
319
332
    .name           = "libx264",
320
333
    .type           = AVMEDIA_TYPE_VIDEO,
321
334
    .id             = CODEC_ID_H264,
324
337
    .encode         = X264_frame,
325
338
    .close          = X264_close,
326
339
    .capabilities   = CODEC_CAP_DELAY,
327
 
    .pix_fmts       = (const enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_NONE },
 
340
    .pix_fmts       = (const enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_YUVJ420P, PIX_FMT_NONE },
328
341
    .long_name      = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
329
342
};