~ubuntu-branches/ubuntu/natty/x264/natty

1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1
/*****************************************************************************
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
2
 * x264: top-level x264cli functions
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
3
 *****************************************************************************
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
4
 * Copyright (C) 2003-2010 x264 project
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
5
 *
1.1.8 by Lionel Le Folgoc
Import upstream version 0.svn20081230
6
 * Authors: Loren Merritt <lorenm@u.washington.edu>
7
 *          Laurent Aimar <fenrir@via.ecp.fr>
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
8
 *          Steven Walters <kemuri9@gmail.com>
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
9
 *          Jason Garrett-Glaser <darkshikari@gmail.com>
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
10
 *          Kieran Kunhya <kieran@kunhya.com>
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
1.1.8 by Lionel Le Folgoc
Import upstream version 0.svn20081230
24
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
25
 *
26
 * This program is also available under a commercial proprietary license.
27
 * For more information, contact us at licensing@x264.com.
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
28
 *****************************************************************************/
29
30
#include <stdlib.h>
31
#include <math.h>
32
33
#include <signal.h>
34
#define _GNU_SOURCE
35
#include <getopt.h>
36
37
#include "common/common.h"
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
38
#include "x264cli.h"
39
#include "input/input.h"
40
#include "output/output.h"
41
#include "filters/filters.h"
42
43
#define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "x264", __VA_ARGS__ )
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
44
1.1.8 by Lionel Le Folgoc
Import upstream version 0.svn20081230
45
#ifdef _WIN32
46
#include <windows.h>
47
#else
48
#define SetConsoleTitle(t)
49
#endif
50
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
51
#if HAVE_LAVF
52
#undef DECLARE_ALIGNED
53
#include <libavformat/avformat.h>
54
#include <libavutil/pixfmt.h>
55
#include <libavutil/pixdesc.h>
56
#endif
57
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
58
/* Ctrl-C handler */
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
59
static volatile int b_ctrl_c = 0;
60
static int          b_exit_on_ctrl_c = 0;
61
static void sigint_handler( int a )
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
62
{
63
    if( b_exit_on_ctrl_c )
64
        exit(0);
65
    b_ctrl_c = 1;
66
}
67
68
typedef struct {
69
    int b_progress;
70
    int i_seek;
71
    hnd_t hin;
72
    hnd_t hout;
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
73
    FILE *qpfile;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
74
    FILE *tcfile_out;
75
    double timebase_convert_multiplier;
76
    int i_pulldown;
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
77
} cli_opt_t;
78
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
79
/* file i/o operation structs */
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
80
cli_input_t input;
81
static cli_output_t output;
82
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
83
/* video filter operation struct */
84
static cli_vid_filter_t filter;
85
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
86
static const char * const demuxer_names[] =
87
{
88
    "auto",
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
89
    "raw",
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
90
    "y4m",
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
91
#if HAVE_AVS
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
92
    "avs",
93
#endif
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
94
#if HAVE_LAVF
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
95
    "lavf",
96
#endif
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
97
#if HAVE_FFMS
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
98
    "ffms",
99
#endif
100
    0
101
};
102
103
static const char * const muxer_names[] =
104
{
105
    "auto",
106
    "raw",
107
    "mkv",
108
    "flv",
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
109
#if HAVE_GPAC
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
110
    "mp4",
111
#endif
112
    0
113
};
114
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
115
static const char * const pulldown_names[] = { "none", "22", "32", "64", "double", "triple", "euro", 0 };
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
116
static const char * const log_level_names[] = { "none", "error", "warning", "info", "debug", 0 };
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
117
118
typedef struct{
119
    int mod;
120
    uint8_t pattern[24];
121
    float fps_factor;
122
} cli_pulldown_t;
123
124
enum pulldown_type_e
125
{
126
    X264_PULLDOWN_22 = 1,
127
    X264_PULLDOWN_32,
128
    X264_PULLDOWN_64,
129
    X264_PULLDOWN_DOUBLE,
130
    X264_PULLDOWN_TRIPLE,
131
    X264_PULLDOWN_EURO
132
};
133
134
#define TB  PIC_STRUCT_TOP_BOTTOM
135
#define BT  PIC_STRUCT_BOTTOM_TOP
136
#define TBT PIC_STRUCT_TOP_BOTTOM_TOP
137
#define BTB PIC_STRUCT_BOTTOM_TOP_BOTTOM
138
139
static const cli_pulldown_t pulldown_values[] =
140
{
141
    [X264_PULLDOWN_22]     = {1,  {TB},                                   1.0},
142
    [X264_PULLDOWN_32]     = {4,  {TBT, BT, BTB, TB},                     1.25},
143
    [X264_PULLDOWN_64]     = {2,  {PIC_STRUCT_DOUBLE, PIC_STRUCT_TRIPLE}, 1.0},
144
    [X264_PULLDOWN_DOUBLE] = {1,  {PIC_STRUCT_DOUBLE},                    2.0},
145
    [X264_PULLDOWN_TRIPLE] = {1,  {PIC_STRUCT_TRIPLE},                    3.0},
146
    [X264_PULLDOWN_EURO]   = {24, {TBT, BT, BT, BT, BT, BT, BT, BT, BT, BT, BT, BT,
147
                                   BTB, TB, TB, TB, TB, TB, TB, TB, TB, TB, TB, TB}, 25.0/24.0}
148
};
149
150
#undef TB
151
#undef BT
152
#undef TBT
153
#undef BTB
154
155
// indexed by pic_struct enum
156
static const float pulldown_frame_duration[10] = { 0.0, 1, 0.5, 0.5, 1, 1, 1.5, 1.5, 2, 3 };
157
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
158
static void help( x264_param_t *defaults, int longhelp );
159
static int  parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt );
160
static int  encode( x264_param_t *param, cli_opt_t *opt );
161
162
/* logging and printing for within the cli system */
163
static int cli_log_level;
164
void x264_cli_log( const char *name, int i_level, const char *fmt, ... )
165
{
166
    if( i_level > cli_log_level )
167
        return;
168
    char *s_level;
169
    switch( i_level )
170
    {
171
        case X264_LOG_ERROR:
172
            s_level = "error";
173
            break;
174
        case X264_LOG_WARNING:
175
            s_level = "warning";
176
            break;
177
        case X264_LOG_INFO:
178
            s_level = "info";
179
            break;
180
        case X264_LOG_DEBUG:
181
            s_level = "debug";
182
            break;
183
        default:
184
            s_level = "unknown";
185
            break;
186
    }
187
    fprintf( stderr, "%s [%s]: ", name, s_level );
188
    va_list arg;
189
    va_start( arg, fmt );
190
    vfprintf( stderr, fmt, arg );
191
    va_end( arg );
192
}
193
194
void x264_cli_printf( int i_level, const char *fmt, ... )
195
{
196
    if( i_level > cli_log_level )
197
        return;
198
    va_list arg;
199
    va_start( arg, fmt );
200
    vfprintf( stderr, fmt, arg );
201
    va_end( arg );
202
}
203
204
static void print_version_info()
205
{
206
#ifdef X264_POINTVER
207
    printf( "x264 "X264_POINTVER"\n" );
208
#else
209
    printf( "x264 0.%d.X\n", X264_BUILD );
210
#endif
211
    printf( "built on " __DATE__ ", " );
212
#ifdef __GNUC__
213
    printf( "gcc: " __VERSION__ "\n" );
214
#else
215
    printf( "using a non-gcc compiler\n" );
216
#endif
217
    printf( "configuration: --bit-depth=%d\n", x264_bit_depth );
218
    printf( "x264 license: " );
219
#if HAVE_GPL
220
    printf( "GPL version 2 or later\n" );
221
#else
222
    printf( "Non-GPL commercial\n" );
223
#endif
224
#if HAVE_LAVF
225
    const char *license = avformat_license();
226
    printf( "libavformat license: %s\n", license );
227
    if( !strcmp( license, "nonfree and unredistributable" ) ||
228
       (!HAVE_GPL && (!strcmp( license, "GPL version 2 or later" )
229
                  ||  !strcmp( license, "GPL version 3 or later" ))))
230
        printf( "WARNING: This binary is unredistributable!\n" );
231
#endif
232
}
233
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
234
int main( int argc, char **argv )
235
{
236
    x264_param_t param;
237
    cli_opt_t opt;
1.1.3 by John Dong
Import upstream version 0.cvs20070117
238
    int ret;
239
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
240
#if PTW32_STATIC_LIB
1.1.3 by John Dong
Import upstream version 0.cvs20070117
241
    pthread_win32_process_attach_np();
242
    pthread_win32_thread_attach_np();
243
#endif
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
244
1.1.8 by Lionel Le Folgoc
Import upstream version 0.svn20081230
245
#ifdef _WIN32
1.1.1 by Sebastian Dröge
Import upstream version 0.cvs20060720
246
    _setmode(_fileno(stdin), _O_BINARY);
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
247
    _setmode(_fileno(stdout), _O_BINARY);
248
#endif
249
250
    /* Parse command line */
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
251
    if( parse( argc, argv, &param, &opt ) < 0 )
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
252
        return -1;
253
254
    /* Control-C handler */
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
255
    signal( SIGINT, sigint_handler );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
256
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
257
    ret = encode( &param, &opt );
1.1.3 by John Dong
Import upstream version 0.cvs20070117
258
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
259
#if PTW32_STATIC_LIB
1.1.3 by John Dong
Import upstream version 0.cvs20070117
260
    pthread_win32_thread_detach_np();
261
    pthread_win32_process_detach_np();
262
#endif
263
264
    return ret;
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
265
}
266
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
267
static char const *strtable_lookup( const char * const table[], int idx )
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
268
{
269
    int i = 0; while( table[i] ) i++;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
270
    return ( ( idx >= 0 && idx < i ) ? table[ idx ] : "???" );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
271
}
272
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
273
static char *stringify_names( char *buf, const char * const names[] )
274
{
275
    int i = 0;
276
    char *p = buf;
277
    for( p[0] = 0; names[i]; i++ )
278
    {
279
        p += sprintf( p, "%s", names[i] );
280
        if( names[i+1] )
281
            p += sprintf( p, ", " );
282
    }
283
    return buf;
284
}
285
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
286
static void print_csp_names( int longhelp )
287
{
288
    if( longhelp < 2 )
289
        return;
290
#   define INDENT "                                "
291
    printf( "                              - valid csps for `raw' demuxer:\n" );
292
    printf( INDENT );
293
    for( int i = X264_CSP_NONE+1; i < X264_CSP_CLI_MAX; i++ )
294
    {
295
        printf( "%s", x264_cli_csps[i].name );
296
        if( i+1 < X264_CSP_CLI_MAX )
297
            printf( ", " );
298
    }
299
#if HAVE_LAVF
300
    printf( "\n" );
301
    printf( "                              - valid csps for `lavf' demuxer:\n" );
302
    printf( INDENT );
303
    int line_len = strlen( INDENT );
304
    for( enum PixelFormat i = PIX_FMT_NONE+1; i < PIX_FMT_NB; i++ )
305
    {
306
        const char *pfname = av_pix_fmt_descriptors[i].name;
307
        int name_len = strlen( pfname );
308
        if( line_len + name_len > (80 - strlen( ", " )) )
309
        {
310
            printf( "\n" INDENT );
311
            line_len = strlen( INDENT );
312
        }
313
        printf( "%s", pfname );
314
        line_len += name_len;
315
        if( i+1 < PIX_FMT_NB )
316
        {
317
            printf( ", " );
318
            line_len += 2;
319
        }
320
    }
321
#endif
322
    printf( "\n" );
323
}
324
325
static void help( x264_param_t *defaults, int longhelp )
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
326
{
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
327
    char buf[50];
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
328
#define H0 printf
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
329
#define H1 if(longhelp>=1) printf
330
#define H2 if(longhelp==2) printf
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
331
    H0( "x264 core:%d%s\n"
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
332
        "Syntax: x264 [options] -o outfile infile\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
333
        "\n"
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
334
        "Infile can be raw (in which case resolution is required),\n"
335
        "  or YUV4MPEG (*.y4m),\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
336
        "  or Avisynth if compiled with support (%s).\n"
337
        "  or libav* formats if compiled with lavf support (%s) or ffms support (%s).\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
338
        "Outfile type is selected by filename:\n"
339
        " .264 -> Raw bytestream\n"
340
        " .mkv -> Matroska\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
341
        " .flv -> Flash Video\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
342
        " .mp4 -> MP4 if compiled with GPAC support (%s)\n"
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
343
        "Output bit depth: %d (configured at compile time)\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
344
        "\n"
345
        "Options:\n"
346
        "\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
347
        "  -h, --help                  List basic options\n"
348
        "      --longhelp              List more options\n"
349
        "      --fullhelp              List all options\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
350
        "\n",
351
        X264_BUILD, X264_VERSION,
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
352
#if HAVE_AVS
353
        "yes",
354
#else
355
        "no",
356
#endif
357
#if HAVE_LAVF
358
        "yes",
359
#else
360
        "no",
361
#endif
362
#if HAVE_FFMS
363
        "yes",
364
#else
365
        "no",
366
#endif
367
#if HAVE_GPAC
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
368
        "yes",
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
369
#else
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
370
        "no",
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
371
#endif
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
372
        x264_bit_depth
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
373
      );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
374
    H0( "Example usage:\n" );
375
    H0( "\n" );
376
    H0( "      Constant quality mode:\n" );
377
    H0( "            x264 --crf 24 -o <output> <input>\n" );
378
    H0( "\n" );
379
    H0( "      Two-pass with a bitrate of 1000kbps:\n" );
380
    H0( "            x264 --pass 1 --bitrate 1000 -o <output> <input>\n" );
381
    H0( "            x264 --pass 2 --bitrate 1000 -o <output> <input>\n" );
382
    H0( "\n" );
383
    H0( "      Lossless:\n" );
384
    H0( "            x264 --crf 0 -o <output> <input>\n" );
385
    H0( "\n" );
386
    H0( "      Maximum PSNR at the cost of speed and visual quality:\n" );
387
    H0( "            x264 --preset placebo --tune psnr -o <output> <input>\n" );
388
    H0( "\n" );
389
    H0( "      Constant bitrate at 1000kbps with a 2 second-buffer:\n");
390
    H0( "            x264 --vbv-bufsize 2000 --bitrate 1000 -o <output> <input>\n" );
391
    H0( "\n" );
392
    H0( "Presets:\n" );
393
    H0( "\n" );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
394
    H0( "      --profile               Force the limits of an H.264 profile\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
395
        "                                  Overrides all settings.\n" );
396
    H2( "                                  - baseline:\n"
397
        "                                    --no-8x8dct --bframes 0 --no-cabac\n"
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
398
        "                                    --cqm flat --weightp 0\n"
399
        "                                    No interlaced.\n"
400
        "                                    No lossless.\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
401
        "                                  - main:\n"
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
402
        "                                    --no-8x8dct --cqm flat\n"
403
        "                                    No lossless.\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
404
        "                                  - high:\n"
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
405
        "                                    No lossless.\n"
406
        "                                  - high10:\n"
407
        "                                    No lossless.\n"
408
        "                                    Support for bit depth 8-10.\n" );
409
        else H0( "                                  - baseline,main,high,high10\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
410
    H0( "      --preset                Use a preset to select encoding settings [medium]\n"
411
        "                                  Overridden by user settings.\n" );
412
    H2( "                                  - ultrafast:\n"
413
        "                                    --no-8x8dct --aq-mode 0 --b-adapt 0\n"
414
        "                                    --bframes 0 --no-cabac --no-deblock\n"
415
        "                                    --no-mbtree --me dia --no-mixed-refs\n"
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
416
        "                                    --partitions none --rc-lookahead 0 --ref 1\n"
417
        "                                    --scenecut 0 --subme 0 --trellis 0\n"
418
        "                                    --no-weightb --weightp 0\n"
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
419
        "                                  - superfast:\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
420
        "                                    --no-mbtree --me dia --no-mixed-refs\n"
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
421
        "                                    --partitions i8x8,i4x4 --rc-lookahead 0\n"
422
        "                                    --ref 1 --subme 1 --trellis 0 --weightp 0\n"
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
423
        "                                  - veryfast:\n"
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
424
        "                                    --no-mixed-refs --rc-lookahead 10\n"
425
        "                                    --ref 1 --subme 2 --trellis 0 --weightp 0\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
426
        "                                  - faster:\n"
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
427
        "                                    --no-mixed-refs --rc-lookahead 20\n"
428
        "                                    --ref 2 --subme 4 --weightp 1\n"
1.1.12 by Reinhard Tartler
Import upstream version 0.85.1442.1+git781d30
429
        "                                  - fast:\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
430
        "                                    --rc-lookahead 30 --ref 2 --subme 6\n"
1.1.12 by Reinhard Tartler
Import upstream version 0.85.1442.1+git781d30
431
        "                                  - medium:\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
432
        "                                    Default settings apply.\n"
1.1.12 by Reinhard Tartler
Import upstream version 0.85.1442.1+git781d30
433
        "                                  - slow:\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
434
        "                                    --b-adapt 2 --direct auto --me umh\n"
435
        "                                    --rc-lookahead 50 --ref 5 --subme 8\n"
1.1.12 by Reinhard Tartler
Import upstream version 0.85.1442.1+git781d30
436
        "                                  - slower:\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
437
        "                                    --b-adapt 2 --direct auto --me umh\n"
438
        "                                    --partitions all --rc-lookahead 60\n"
439
        "                                    --ref 8 --subme 9 --trellis 2\n"
1.1.12 by Reinhard Tartler
Import upstream version 0.85.1442.1+git781d30
440
        "                                  - veryslow:\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
441
        "                                    --b-adapt 2 --bframes 8 --direct auto\n"
442
        "                                    --me umh --merange 24 --partitions all\n"
443
        "                                    --ref 16 --subme 10 --trellis 2\n"
444
        "                                    --rc-lookahead 60\n"
1.1.12 by Reinhard Tartler
Import upstream version 0.85.1442.1+git781d30
445
        "                                  - placebo:\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
446
        "                                    --bframes 16 --b-adapt 2 --direct auto\n"
447
        "                                    --slow-firstpass --no-fast-pskip\n"
448
        "                                    --me tesa --merange 24 --partitions all\n"
449
        "                                    --rc-lookahead 60 --ref 16 --subme 10\n"
450
        "                                    --trellis 2\n" );
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
451
    else H0( "                                  - ultrafast,superfast,veryfast,faster,fast\n"
452
             "                                  - medium,slow,slower,veryslow,placebo\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
453
    H0( "      --tune                  Tune the settings for a particular type of source\n"
454
        "                              or situation\n"
455
        "                                  Overridden by user settings.\n"
456
        "                                  Multiple tunings are separated by commas.\n"
457
        "                                  Only one psy tuning can be used at a time.\n" );
458
    H2( "                                  - film (psy tuning):\n"
459
        "                                    --deblock -1:-1 --psy-rd <unset>:0.15\n"
1.1.12 by Reinhard Tartler
Import upstream version 0.85.1442.1+git781d30
460
        "                                  - animation (psy tuning):\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
461
        "                                    --bframes {+2} --deblock 1:1\n"
462
        "                                    --psy-rd 0.4:<unset> --aq-strength 0.6\n"
463
        "                                    --ref {Double if >1 else 1}\n"
1.1.12 by Reinhard Tartler
Import upstream version 0.85.1442.1+git781d30
464
        "                                  - grain (psy tuning):\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
465
        "                                    --aq-strength 0.5 --no-dct-decimate\n"
466
        "                                    --deadzone-inter 6 --deadzone-intra 6\n"
467
        "                                    --deblock -2:-2 --ipratio 1.1 \n"
468
        "                                    --pbratio 1.1 --psy-rd <unset>:0.25\n"
469
        "                                    --qcomp 0.8\n"
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
470
        "                                  - stillimage (psy tuning):\n"
471
        "                                    --aq-strength 1.2 --deblock -3:-3\n"
472
        "                                    --psy-rd 2.0:0.7\n"
1.1.12 by Reinhard Tartler
Import upstream version 0.85.1442.1+git781d30
473
        "                                  - psnr (psy tuning):\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
474
        "                                    --aq-mode 0 --no-psy\n"
1.1.12 by Reinhard Tartler
Import upstream version 0.85.1442.1+git781d30
475
        "                                  - ssim (psy tuning):\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
476
        "                                    --aq-mode 2 --no-psy\n"
477
        "                                  - fastdecode:\n"
478
        "                                    --no-cabac --no-deblock --no-weightb\n"
479
        "                                    --weightp 0\n"
480
        "                                  - zerolatency:\n"
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
481
        "                                    --bframes 0 --force-cfr --no-mbtree\n"
482
        "                                    --sync-lookahead 0 --sliced-threads\n"
483
        "                                    --rc-lookahead 0\n" );
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
484
    else H0( "                                  - psy tunings: film,animation,grain,\n"
485
             "                                                 stillimage,psnr,ssim\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
486
             "                                  - other tunings: fastdecode,zerolatency\n" );
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
487
    H2( "      --slow-firstpass        Don't force these faster settings with --pass 1:\n"
488
        "                                  --no-8x8dct --me dia --partitions none\n"
489
        "                                  --ref 1 --subme {2 if >2 else unchanged}\n"
490
        "                                  --trellis 0 --fast-pskip\n" );
491
    else H1( "      --slow-firstpass        Don't force faster settings with --pass 1\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
492
    H0( "\n" );
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
493
    H0( "Frame-type options:\n" );
494
    H0( "\n" );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
495
    H0( "  -I, --keyint <integer or \"infinite\"> Maximum GOP size [%d]\n", defaults->i_keyint_max );
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
496
    H2( "  -i, --min-keyint <integer>  Minimum GOP size [auto]\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
497
    H2( "      --no-scenecut           Disable adaptive I-frame decision\n" );
498
    H2( "      --scenecut <integer>    How aggressively to insert extra I-frames [%d]\n", defaults->i_scenecut_threshold );
499
    H2( "      --intra-refresh         Use Periodic Intra Refresh instead of IDR frames\n" );
500
    H1( "  -b, --bframes <integer>     Number of B-frames between I and P [%d]\n", defaults->i_bframe );
501
    H1( "      --b-adapt <integer>     Adaptive B-frame decision method [%d]\n"
1.1.8 by Lionel Le Folgoc
Import upstream version 0.svn20081230
502
        "                                  Higher values may lower threading efficiency.\n"
503
        "                                  - 0: Disabled\n"
504
        "                                  - 1: Fast\n"
505
        "                                  - 2: Optimal (slow with high --bframes)\n", defaults->i_bframe_adaptive );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
506
    H2( "      --b-bias <integer>      Influences how often B-frames are used [%d]\n", defaults->i_bframe_bias );
507
    H1( "      --b-pyramid <string>    Keep some B-frames as references [%s]\n"
508
        "                                  - none: Disabled\n"
509
        "                                  - strict: Strictly hierarchical pyramid\n"
510
        "                                  - normal: Non-strict (not Blu-ray compatible)\n",
511
        strtable_lookup( x264_b_pyramid_names, defaults->i_bframe_pyramid ) );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
512
    H1( "      --open-gop <string>     Use recovery points to close GOPs [none]\n"
513
        "                                  - none: closed GOPs only\n"
514
        "                                  - normal: standard open GOPs\n"
515
        "                                            (not Blu-ray compatible)\n"
516
        "                                  - bluray: Blu-ray-compatible open GOPs\n"
517
        "                              Only available with b-frames\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
518
    H1( "      --no-cabac              Disable CABAC\n" );
519
    H1( "  -r, --ref <integer>         Number of reference frames [%d]\n", defaults->i_frame_reference );
1.1.3 by John Dong
Import upstream version 0.cvs20070117
520
    H1( "      --no-deblock            Disable loop filter\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
521
    H1( "  -f, --deblock <alpha:beta>  Loop filter parameters [%d:%d]\n",
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
522
                                       defaults->i_deblocking_filter_alphac0, defaults->i_deblocking_filter_beta );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
523
    H2( "      --slices <integer>      Number of slices per frame; forces rectangular\n"
524
        "                              slices and is overridden by other slicing options\n" );
525
    else H1( "      --slices <integer>      Number of slices per frame\n" );
526
    H2( "      --slice-max-size <integer> Limit the size of each slice in bytes\n");
527
    H2( "      --slice-max-mbs <integer> Limit the size of each slice in macroblocks\n");
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
528
    H0( "      --tff                   Enable interlaced mode (top field first)\n" );
529
    H0( "      --bff                   Enable interlaced mode (bottom field first)\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
530
    H2( "      --constrained-intra     Enable constrained intra prediction.\n" );
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
531
    H0( "      --pulldown <string>     Use soft pulldown to change frame rate\n"
532
        "                                  - none, 22, 32, 64, double, triple, euro (requires cfr input)\n" );
533
    H2( "      --fake-interlaced       Flag stream as interlaced but encode progressive.\n"
534
        "                              Makes it possible to encode 25p and 30p Blu-Ray\n"
535
        "                              streams. Ignored in interlaced mode.\n" );
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
536
    H0( "\n" );
537
    H0( "Ratecontrol:\n" );
538
    H0( "\n" );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
539
    H1( "  -q, --qp <integer>          Force constant QP (0-%d, 0=lossless)\n", QP_MAX );
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
540
    H0( "  -B, --bitrate <integer>     Set bitrate (kbit/s)\n" );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
541
    H0( "      --crf <float>           Quality-based VBR (0-%d, 0=lossless) [%.1f]\n", QP_MAX, defaults->rc.f_rf_constant );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
542
    H1( "      --rc-lookahead <integer> Number of frames for frametype lookahead [%d]\n", defaults->rc.i_lookahead );
543
    H0( "      --vbv-maxrate <integer> Max local bitrate (kbit/s) [%d]\n", defaults->rc.i_vbv_max_bitrate );
544
    H0( "      --vbv-bufsize <integer> Set size of the VBV buffer (kbit) [%d]\n", defaults->rc.i_vbv_buffer_size );
545
    H2( "      --vbv-init <float>      Initial VBV buffer occupancy [%.1f]\n", defaults->rc.f_vbv_buffer_init );
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
546
    H2( "      --crf-max <float>       With CRF+VBV, limit RF to this value\n"
547
        "                                  May cause VBV underflows!\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
548
    H2( "      --qpmin <integer>       Set min QP [%d]\n", defaults->rc.i_qp_min );
549
    H2( "      --qpmax <integer>       Set max QP [%d]\n", defaults->rc.i_qp_max );
550
    H2( "      --qpstep <integer>      Set max QP step [%d]\n", defaults->rc.i_qp_step );
551
    H2( "      --ratetol <float>       Tolerance of ABR ratecontrol and VBV [%.1f]\n", defaults->rc.f_rate_tolerance );
552
    H2( "      --ipratio <float>       QP factor between I and P [%.2f]\n", defaults->rc.f_ip_factor );
553
    H2( "      --pbratio <float>       QP factor between P and B [%.2f]\n", defaults->rc.f_pb_factor );
554
    H2( "      --chroma-qp-offset <integer>  QP difference between chroma and luma [%d]\n", defaults->analyse.i_chroma_qp_offset );
555
    H2( "      --aq-mode <integer>     AQ method [%d]\n"
1.1.7 by John Dong
Import upstream version 0.svn20080408
556
        "                                  - 0: Disabled\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
557
        "                                  - 1: Variance AQ (complexity mask)\n"
558
        "                                  - 2: Auto-variance AQ (experimental)\n", defaults->rc.i_aq_mode );
559
    H1( "      --aq-strength <float>   Reduces blocking and blurring in flat and\n"
560
        "                              textured areas. [%.1f]\n", defaults->rc.f_aq_strength );
561
    H1( "\n" );
562
    H0( "  -p, --pass <integer>        Enable multipass ratecontrol\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
563
        "                                  - 1: First pass, creates stats file\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
564
        "                                  - 2: Last pass, does not overwrite stats file\n" );
565
    H2( "                                  - 3: Nth pass, overwrites stats file\n" );
566
    H1( "      --stats <string>        Filename for 2 pass stats [\"%s\"]\n", defaults->rc.psz_stat_out );
567
    H2( "      --no-mbtree             Disable mb-tree ratecontrol.\n");
568
    H2( "      --qcomp <float>         QP curve compression [%.2f]\n", defaults->rc.f_qcompress );
569
    H2( "      --cplxblur <float>      Reduce fluctuations in QP (before curve compression) [%.1f]\n", defaults->rc.f_complexity_blur );
570
    H2( "      --qblur <float>         Reduce fluctuations in QP (after curve compression) [%.1f]\n", defaults->rc.f_qblur );
571
    H2( "      --zones <zone0>/<zone1>/...  Tweak the bitrate of regions of the video\n" );
572
    H2( "                              Each zone is of the form\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
573
        "                                  <start frame>,<end frame>,<option>\n"
574
        "                                  where <option> is either\n"
575
        "                                      q=<integer> (force QP)\n"
576
        "                                  or  b=<float> (bitrate multiplier)\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
577
    H2( "      --qpfile <string>       Force frametypes and QPs for some or all frames\n"
1.1.9 by Alessio Treglia
Import upstream version 0.svn20090502
578
        "                              Format of each line: framenumber frametype QP\n"
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
579
        "                              QP of -1 lets x264 choose. Frametypes: I,i,K,P,B,b.\n"
580
        "                                  K=<I or i> depending on open-gop setting\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
581
        "                              QPs are restricted by qpmin/qpmax.\n" );
582
    H1( "\n" );
583
    H1( "Analysis:\n" );
584
    H1( "\n" );
585
    H1( "  -A, --partitions <string>   Partitions to consider [\"p8x8,b8x8,i8x8,i4x4\"]\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
586
        "                                  - p8x8, p4x4, b8x8, i8x8, i4x4\n"
587
        "                                  - none, all\n"
588
        "                                  (p4x4 requires p8x8. i8x8 requires --8x8dct.)\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
589
    H1( "      --direct <string>       Direct MV prediction mode [\"%s\"]\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
590
        "                                  - none, spatial, temporal, auto\n",
591
                                       strtable_lookup( x264_direct_pred_names, defaults->analyse.i_direct_mv_pred ) );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
592
    H2( "      --no-weightb            Disable weighted prediction for B-frames\n" );
593
    H1( "      --weightp <integer>     Weighted prediction for P-frames [%d]\n"
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
594
        "                                  - 0: Disabled\n"
595
        "                                  - 1: Blind offset\n"
596
        "                                  - 2: Smart analysis\n", defaults->analyse.i_weighted_pred );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
597
    H1( "      --me <string>           Integer pixel motion estimation method [\"%s\"]\n",
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
598
                                       strtable_lookup( x264_motion_est_names, defaults->analyse.i_me_method ) );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
599
    H2( "                                  - dia: diamond search, radius 1 (fast)\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
600
        "                                  - hex: hexagonal search, radius 2\n"
601
        "                                  - umh: uneven multi-hexagon search\n"
1.1.7 by John Dong
Import upstream version 0.svn20080408
602
        "                                  - esa: exhaustive search\n"
603
        "                                  - tesa: hadamard exhaustive search (slow)\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
604
    else H1( "                                  - dia, hex, umh\n" );
605
    H2( "      --merange <integer>     Maximum motion vector search range [%d]\n", defaults->analyse.i_me_range );
606
    H2( "      --mvrange <integer>     Maximum motion vector length [-1 (auto)]\n" );
607
    H2( "      --mvrange-thread <int>  Minimum buffer between threads [-1 (auto)]\n" );
608
    H1( "  -m, --subme <integer>       Subpixel motion estimation and mode decision [%d]\n", defaults->analyse.i_subpel_refine );
609
    H2( "                                  - 0: fullpel only (not recommended)\n"
1.1.8 by Lionel Le Folgoc
Import upstream version 0.svn20081230
610
        "                                  - 1: SAD mode decision, one qpel iteration\n"
611
        "                                  - 2: SATD mode decision\n"
612
        "                                  - 3-5: Progressively more qpel\n"
613
        "                                  - 6: RD mode decision for I/P-frames\n"
614
        "                                  - 7: RD mode decision for all frames\n"
615
        "                                  - 8: RD refinement for I/P-frames\n"
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
616
        "                                  - 9: RD refinement for all frames\n"
617
        "                                  - 10: QP-RD - requires trellis=2, aq-mode>0\n" );
618
    else H1( "                                  decision quality: 1=fast, 10=best.\n"  );
619
    H1( "      --psy-rd                Strength of psychovisual optimization [\"%.1f:%.1f\"]\n"
1.1.8 by Lionel Le Folgoc
Import upstream version 0.svn20081230
620
        "                                  #1: RD (requires subme>=6)\n"
621
        "                                  #2: Trellis (requires trellis, experimental)\n",
622
                                       defaults->analyse.f_psy_rd, defaults->analyse.f_psy_trellis );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
623
    H2( "      --no-psy                Disable all visual optimizations that worsen\n"
624
        "                              both PSNR and SSIM.\n" );
625
    H2( "      --no-mixed-refs         Don't decide references on a per partition basis\n" );
626
    H2( "      --no-chroma-me          Ignore chroma in motion estimation\n" );
627
    H1( "      --no-8x8dct             Disable adaptive spatial transform size\n" );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
628
    H1( "  -t, --trellis <integer>     Trellis RD quantization. [%d]\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
629
        "                                  - 0: disabled\n"
630
        "                                  - 1: enabled only on the final encode of a MB\n"
631
        "                                  - 2: enabled on all mode decisions\n", defaults->analyse.i_trellis );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
632
    H2( "      --no-fast-pskip         Disables early SKIP detection on P-frames\n" );
633
    H2( "      --no-dct-decimate       Disables coefficient thresholding on P-frames\n" );
634
    H1( "      --nr <integer>          Noise reduction [%d]\n", defaults->analyse.i_noise_reduction );
635
    H2( "\n" );
636
    H2( "      --deadzone-inter <int>  Set the size of the inter luma quantization deadzone [%d]\n", defaults->analyse.i_luma_deadzone[0] );
637
    H2( "      --deadzone-intra <int>  Set the size of the intra luma quantization deadzone [%d]\n", defaults->analyse.i_luma_deadzone[1] );
638
    H2( "                                  Deadzones should be in the range 0 - 32.\n" );
639
    H2( "      --cqm <string>          Preset quant matrices [\"flat\"]\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
640
        "                                  - jvt, flat\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
641
    H1( "      --cqmfile <string>      Read custom quant matrices from a JM-compatible file\n" );
642
    H2( "                                  Overrides any other --cqm* options.\n" );
643
    H2( "      --cqm4 <list>           Set all 4x4 quant matrices\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
644
        "                                  Takes a comma-separated list of 16 integers.\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
645
    H2( "      --cqm8 <list>           Set all 8x8 quant matrices\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
646
        "                                  Takes a comma-separated list of 64 integers.\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
647
    H2( "      --cqm4i, --cqm4p, --cqm8i, --cqm8p\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
648
        "                              Set both luma and chroma quant matrices\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
649
    H2( "      --cqm4iy, --cqm4ic, --cqm4py, --cqm4pc\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
650
        "                              Set individual quant matrices\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
651
    H2( "\n" );
652
    H2( "Video Usability Info (Annex E):\n" );
653
    H2( "The VUI settings are not used by the encoder but are merely suggestions to\n" );
654
    H2( "the playback equipment. See doc/vui.txt for details. Use at your own risk.\n" );
655
    H2( "\n" );
656
    H2( "      --overscan <string>     Specify crop overscan setting [\"%s\"]\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
657
        "                                  - undef, show, crop\n",
658
                                       strtable_lookup( x264_overscan_names, defaults->vui.i_overscan ) );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
659
    H2( "      --videoformat <string>  Specify video format [\"%s\"]\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
660
        "                                  - component, pal, ntsc, secam, mac, undef\n",
661
                                       strtable_lookup( x264_vidformat_names, defaults->vui.i_vidformat ) );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
662
    H2( "      --fullrange <string>    Specify full range samples setting [\"%s\"]\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
663
        "                                  - off, on\n",
664
                                       strtable_lookup( x264_fullrange_names, defaults->vui.b_fullrange ) );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
665
    H2( "      --colorprim <string>    Specify color primaries [\"%s\"]\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
666
        "                                  - undef, bt709, bt470m, bt470bg\n"
667
        "                                    smpte170m, smpte240m, film\n",
668
                                       strtable_lookup( x264_colorprim_names, defaults->vui.i_colorprim ) );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
669
    H2( "      --transfer <string>     Specify transfer characteristics [\"%s\"]\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
670
        "                                  - undef, bt709, bt470m, bt470bg, linear,\n"
671
        "                                    log100, log316, smpte170m, smpte240m\n",
672
                                       strtable_lookup( x264_transfer_names, defaults->vui.i_transfer ) );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
673
    H2( "      --colormatrix <string>  Specify color matrix setting [\"%s\"]\n"
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
674
        "                                  - undef, bt709, fcc, bt470bg\n"
675
        "                                    smpte170m, smpte240m, GBR, YCgCo\n",
676
                                       strtable_lookup( x264_colmatrix_names, defaults->vui.i_colmatrix ) );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
677
    H2( "      --chromaloc <integer>   Specify chroma sample location (0 to 5) [%d]\n",
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
678
                                       defaults->vui.i_chroma_loc );
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
679
680
    H2( "      --nal-hrd <string>      Signal HRD information (requires vbv-bufsize)\n"
681
        "                                  - none, vbr, cbr (cbr not allowed in .mp4)\n" );
682
    H2( "      --pic-struct            Force pic_struct in Picture Timing SEI\n" );
683
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
684
    H0( "\n" );
685
    H0( "Input/Output:\n" );
686
    H0( "\n" );
687
    H0( "  -o, --output                Specify output file\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
688
    H1( "      --muxer <string>        Specify output container format [\"%s\"]\n"
689
        "                                  - %s\n", muxer_names[0], stringify_names( buf, muxer_names ) );
690
    H1( "      --demuxer <string>      Specify input container format [\"%s\"]\n"
691
        "                                  - %s\n", demuxer_names[0], stringify_names( buf, demuxer_names ) );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
692
    H1( "      --input-csp <string>    Specify input colorspace format for raw input\n" );
693
    print_csp_names( longhelp );
694
    H1( "      --input-depth <integer> Specify input bit depth for raw input\n" );
695
    H1( "      --input-res <intxint>   Specify input resolution (width x height)\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
696
    H1( "      --index <string>        Filename for input index file\n" );
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
697
    H0( "      --sar width:height      Specify Sample Aspect Ratio\n" );
698
    H0( "      --fps <float|rational>  Specify framerate\n" );
699
    H0( "      --seek <integer>        First frame to encode\n" );
700
    H0( "      --frames <integer>      Maximum number of frames to encode\n" );
701
    H0( "      --level <string>        Specify level (as defined by Annex A)\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
702
    H1( "\n" );
703
    H1( "  -v, --verbose               Print stats for each frame\n" );
704
    H1( "      --no-progress           Don't show the progress indicator while encoding\n" );
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
705
    H0( "      --quiet                 Quiet Mode\n" );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
706
    H1( "      --log-level <string>    Specify the maximum level of logging [\"%s\"]\n"
707
        "                                  - %s\n", strtable_lookup( log_level_names, cli_log_level - X264_LOG_NONE ),
708
                                       stringify_names( buf, log_level_names ) );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
709
    H1( "      --psnr                  Enable PSNR computation\n" );
710
    H1( "      --ssim                  Enable SSIM computation\n" );
711
    H1( "      --threads <integer>     Force a specific number of threads\n" );
712
    H2( "      --sliced-threads        Low-latency but lower-efficiency threading\n" );
713
    H2( "      --thread-input          Run Avisynth in its own thread\n" );
714
    H2( "      --sync-lookahead <integer> Number of buffer frames for threaded lookahead\n" );
715
    H2( "      --non-deterministic     Slightly improve quality of SMP, at the cost of repeatability\n" );
716
    H2( "      --asm <integer>         Override CPU detection\n" );
717
    H2( "      --no-asm                Disable all CPU optimizations\n" );
718
    H2( "      --visualize             Show MB types overlayed on the encoded video\n" );
719
    H2( "      --dump-yuv <string>     Save reconstructed frames\n" );
720
    H2( "      --sps-id <integer>      Set SPS and PPS id numbers [%d]\n", defaults->i_sps_id );
721
    H2( "      --aud                   Use access unit delimiters\n" );
722
    H2( "      --force-cfr             Force constant framerate timestamp generation\n" );
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
723
    H2( "      --tcfile-in <string>    Force timestamp generation with timecode file\n" );
724
    H2( "      --tcfile-out <string>   Output timecode v2 file from input timestamps\n" );
725
    H2( "      --timebase <int/int>    Specify timebase numerator and denominator\n"
726
        "                 <integer>    Specify timebase numerator for input timecode file\n"
727
        "                              or specify timebase denominator for other input\n" );
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
728
    H0( "\n" );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
729
    H0( "Filtering:\n" );
730
    H0( "\n" );
731
    H0( "      --vf, --video-filter <filter0>/<filter1>/... Apply video filtering to the input file\n" );
732
    H0( "\n" );
733
    H0( "      Filter options may be specified in <filter>:<option>=<value> format.\n" );
734
    H0( "\n" );
735
    H0( "      Available filters:\n" );
736
    x264_register_vid_filters();
737
    x264_vid_filter_help( longhelp );
738
    H0( "\n" );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
739
}
740
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
741
enum
742
{
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
743
    OPT_FRAMES = 256,
744
    OPT_SEEK,
745
    OPT_QPFILE,
746
    OPT_THREAD_INPUT,
747
    OPT_QUIET,
748
    OPT_NOPROGRESS,
749
    OPT_VISUALIZE,
750
    OPT_LONGHELP,
751
    OPT_PROFILE,
752
    OPT_PRESET,
753
    OPT_TUNE,
754
    OPT_SLOWFIRSTPASS,
755
    OPT_FULLHELP,
756
    OPT_FPS,
757
    OPT_MUXER,
758
    OPT_DEMUXER,
759
    OPT_INDEX,
760
    OPT_INTERLACED,
761
    OPT_TCFILE_IN,
762
    OPT_TCFILE_OUT,
763
    OPT_TIMEBASE,
764
    OPT_PULLDOWN,
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
765
    OPT_LOG_LEVEL,
766
    OPT_VIDEO_FILTER,
767
    OPT_INPUT_RES,
768
    OPT_INPUT_CSP,
769
    OPT_INPUT_DEPTH
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
770
} OptionsOPT;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
771
772
static char short_options[] = "8A:B:b:f:hI:i:m:o:p:q:r:t:Vvw";
773
static struct option long_options[] =
774
{
775
    { "help",              no_argument, NULL, 'h' },
776
    { "longhelp",          no_argument, NULL, OPT_LONGHELP },
777
    { "fullhelp",          no_argument, NULL, OPT_FULLHELP },
778
    { "version",           no_argument, NULL, 'V' },
779
    { "profile",     required_argument, NULL, OPT_PROFILE },
780
    { "preset",      required_argument, NULL, OPT_PRESET },
781
    { "tune",        required_argument, NULL, OPT_TUNE },
782
    { "slow-firstpass",    no_argument, NULL, OPT_SLOWFIRSTPASS },
783
    { "bitrate",     required_argument, NULL, 'B' },
784
    { "bframes",     required_argument, NULL, 'b' },
785
    { "b-adapt",     required_argument, NULL, 0 },
786
    { "no-b-adapt",        no_argument, NULL, 0 },
787
    { "b-bias",      required_argument, NULL, 0 },
788
    { "b-pyramid",   required_argument, NULL, 0 },
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
789
    { "open-gop",    required_argument, NULL, 0 },
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
790
    { "min-keyint",  required_argument, NULL, 'i' },
791
    { "keyint",      required_argument, NULL, 'I' },
792
    { "intra-refresh",     no_argument, NULL, 0 },
793
    { "scenecut",    required_argument, NULL, 0 },
794
    { "no-scenecut",       no_argument, NULL, 0 },
795
    { "nf",                no_argument, NULL, 0 },
796
    { "no-deblock",        no_argument, NULL, 0 },
797
    { "filter",      required_argument, NULL, 0 },
798
    { "deblock",     required_argument, NULL, 'f' },
799
    { "interlaced",        no_argument, NULL, OPT_INTERLACED },
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
800
    { "tff",               no_argument, NULL, OPT_INTERLACED },
801
    { "bff",               no_argument, NULL, OPT_INTERLACED },
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
802
    { "no-interlaced",     no_argument, NULL, OPT_INTERLACED },
803
    { "constrained-intra", no_argument, NULL, 0 },
804
    { "cabac",             no_argument, NULL, 0 },
805
    { "no-cabac",          no_argument, NULL, 0 },
806
    { "qp",          required_argument, NULL, 'q' },
807
    { "qpmin",       required_argument, NULL, 0 },
808
    { "qpmax",       required_argument, NULL, 0 },
809
    { "qpstep",      required_argument, NULL, 0 },
810
    { "crf",         required_argument, NULL, 0 },
811
    { "rc-lookahead",required_argument, NULL, 0 },
812
    { "ref",         required_argument, NULL, 'r' },
813
    { "asm",         required_argument, NULL, 0 },
814
    { "no-asm",            no_argument, NULL, 0 },
815
    { "sar",         required_argument, NULL, 0 },
816
    { "fps",         required_argument, NULL, OPT_FPS },
817
    { "frames",      required_argument, NULL, OPT_FRAMES },
818
    { "seek",        required_argument, NULL, OPT_SEEK },
819
    { "output",      required_argument, NULL, 'o' },
820
    { "muxer",       required_argument, NULL, OPT_MUXER },
821
    { "demuxer",     required_argument, NULL, OPT_DEMUXER },
822
    { "stdout",      required_argument, NULL, OPT_MUXER },
823
    { "stdin",       required_argument, NULL, OPT_DEMUXER },
824
    { "index",       required_argument, NULL, OPT_INDEX },
825
    { "analyse",     required_argument, NULL, 0 },
826
    { "partitions",  required_argument, NULL, 'A' },
827
    { "direct",      required_argument, NULL, 0 },
828
    { "weightb",           no_argument, NULL, 'w' },
829
    { "no-weightb",        no_argument, NULL, 0 },
830
    { "weightp",     required_argument, NULL, 0 },
831
    { "me",          required_argument, NULL, 0 },
832
    { "merange",     required_argument, NULL, 0 },
833
    { "mvrange",     required_argument, NULL, 0 },
834
    { "mvrange-thread", required_argument, NULL, 0 },
835
    { "subme",       required_argument, NULL, 'm' },
836
    { "psy-rd",      required_argument, NULL, 0 },
837
    { "no-psy",            no_argument, NULL, 0 },
838
    { "psy",               no_argument, NULL, 0 },
839
    { "mixed-refs",        no_argument, NULL, 0 },
840
    { "no-mixed-refs",     no_argument, NULL, 0 },
841
    { "no-chroma-me",      no_argument, NULL, 0 },
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
842
    { "8x8dct",            no_argument, NULL, '8' },
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
843
    { "no-8x8dct",         no_argument, NULL, 0 },
844
    { "trellis",     required_argument, NULL, 't' },
845
    { "fast-pskip",        no_argument, NULL, 0 },
846
    { "no-fast-pskip",     no_argument, NULL, 0 },
847
    { "no-dct-decimate",   no_argument, NULL, 0 },
848
    { "aq-strength", required_argument, NULL, 0 },
849
    { "aq-mode",     required_argument, NULL, 0 },
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
850
    { "deadzone-inter", required_argument, NULL, 0 },
851
    { "deadzone-intra", required_argument, NULL, 0 },
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
852
    { "level",       required_argument, NULL, 0 },
853
    { "ratetol",     required_argument, NULL, 0 },
854
    { "vbv-maxrate", required_argument, NULL, 0 },
855
    { "vbv-bufsize", required_argument, NULL, 0 },
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
856
    { "vbv-init",    required_argument, NULL, 0 },
857
    { "crf-max",     required_argument, NULL, 0 },
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
858
    { "ipratio",     required_argument, NULL, 0 },
859
    { "pbratio",     required_argument, NULL, 0 },
860
    { "chroma-qp-offset", required_argument, NULL, 0 },
861
    { "pass",        required_argument, NULL, 'p' },
862
    { "stats",       required_argument, NULL, 0 },
863
    { "qcomp",       required_argument, NULL, 0 },
864
    { "mbtree",            no_argument, NULL, 0 },
865
    { "no-mbtree",         no_argument, NULL, 0 },
866
    { "qblur",       required_argument, NULL, 0 },
867
    { "cplxblur",    required_argument, NULL, 0 },
868
    { "zones",       required_argument, NULL, 0 },
869
    { "qpfile",      required_argument, NULL, OPT_QPFILE },
870
    { "threads",     required_argument, NULL, 0 },
871
    { "sliced-threads",    no_argument, NULL, 0 },
872
    { "no-sliced-threads", no_argument, NULL, 0 },
873
    { "slice-max-size",    required_argument, NULL, 0 },
874
    { "slice-max-mbs",     required_argument, NULL, 0 },
875
    { "slices",            required_argument, NULL, 0 },
876
    { "thread-input",      no_argument, NULL, OPT_THREAD_INPUT },
877
    { "sync-lookahead",    required_argument, NULL, 0 },
878
    { "non-deterministic", no_argument, NULL, 0 },
879
    { "psnr",              no_argument, NULL, 0 },
880
    { "ssim",              no_argument, NULL, 0 },
881
    { "quiet",             no_argument, NULL, OPT_QUIET },
882
    { "verbose",           no_argument, NULL, 'v' },
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
883
    { "log-level",   required_argument, NULL, OPT_LOG_LEVEL },
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
884
    { "no-progress",       no_argument, NULL, OPT_NOPROGRESS },
885
    { "visualize",         no_argument, NULL, OPT_VISUALIZE },
886
    { "dump-yuv",    required_argument, NULL, 0 },
887
    { "sps-id",      required_argument, NULL, 0 },
888
    { "aud",               no_argument, NULL, 0 },
889
    { "nr",          required_argument, NULL, 0 },
890
    { "cqm",         required_argument, NULL, 0 },
891
    { "cqmfile",     required_argument, NULL, 0 },
892
    { "cqm4",        required_argument, NULL, 0 },
893
    { "cqm4i",       required_argument, NULL, 0 },
894
    { "cqm4iy",      required_argument, NULL, 0 },
895
    { "cqm4ic",      required_argument, NULL, 0 },
896
    { "cqm4p",       required_argument, NULL, 0 },
897
    { "cqm4py",      required_argument, NULL, 0 },
898
    { "cqm4pc",      required_argument, NULL, 0 },
899
    { "cqm8",        required_argument, NULL, 0 },
900
    { "cqm8i",       required_argument, NULL, 0 },
901
    { "cqm8p",       required_argument, NULL, 0 },
902
    { "overscan",    required_argument, NULL, 0 },
903
    { "videoformat", required_argument, NULL, 0 },
904
    { "fullrange",   required_argument, NULL, 0 },
905
    { "colorprim",   required_argument, NULL, 0 },
906
    { "transfer",    required_argument, NULL, 0 },
907
    { "colormatrix", required_argument, NULL, 0 },
908
    { "chromaloc",   required_argument, NULL, 0 },
909
    { "force-cfr",         no_argument, NULL, 0 },
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
910
    { "tcfile-in",   required_argument, NULL, OPT_TCFILE_IN },
911
    { "tcfile-out",  required_argument, NULL, OPT_TCFILE_OUT },
912
    { "timebase",    required_argument, NULL, OPT_TIMEBASE },
913
    { "pic-struct",        no_argument, NULL, 0 },
914
    { "nal-hrd",     required_argument, NULL, 0 },
915
    { "pulldown",    required_argument, NULL, OPT_PULLDOWN },
916
    { "fake-interlaced",   no_argument, NULL, 0 },
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
917
    { "vf",          required_argument, NULL, OPT_VIDEO_FILTER },
918
    { "video-filter", required_argument, NULL, OPT_VIDEO_FILTER },
919
    { "input-res",   required_argument, NULL, OPT_INPUT_RES },
920
    { "input-csp",   required_argument, NULL, OPT_INPUT_CSP },
921
    { "input-depth", required_argument, NULL, OPT_INPUT_DEPTH },
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
922
    {0, 0, 0, 0}
923
};
924
925
static int select_output( const char *muxer, char *filename, x264_param_t *param )
926
{
927
    const char *ext = get_filename_extension( filename );
928
    if( !strcmp( filename, "-" ) || strcasecmp( muxer, "auto" ) )
929
        ext = muxer;
930
931
    if( !strcasecmp( ext, "mp4" ) )
932
    {
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
933
#if HAVE_GPAC
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
934
        output = mp4_output;
935
        param->b_annexb = 0;
936
        param->b_dts_compress = 0;
937
        param->b_repeat_headers = 0;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
938
        if( param->i_nal_hrd == X264_NAL_HRD_CBR )
939
        {
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
940
            x264_cli_log( "x264", X264_LOG_WARNING, "cbr nal-hrd is not compatible with mp4\n" );
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
941
            param->i_nal_hrd = X264_NAL_HRD_VBR;
942
        }
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
943
#else
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
944
        x264_cli_log( "x264", X264_LOG_ERROR, "not compiled with MP4 output support\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
945
        return -1;
946
#endif
947
    }
948
    else if( !strcasecmp( ext, "mkv" ) )
949
    {
950
        output = mkv_output;
951
        param->b_annexb = 0;
952
        param->b_dts_compress = 0;
953
        param->b_repeat_headers = 0;
954
    }
955
    else if( !strcasecmp( ext, "flv" ) )
956
    {
957
        output = flv_output;
958
        param->b_annexb = 0;
959
        param->b_dts_compress = 1;
960
        param->b_repeat_headers = 0;
961
    }
962
    else
963
        output = raw_output;
964
    return 0;
965
}
966
967
static int select_input( const char *demuxer, char *used_demuxer, char *filename,
968
                         hnd_t *p_handle, video_info_t *info, cli_input_opt_t *opt )
969
{
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
970
    int b_auto = !strcasecmp( demuxer, "auto" );
971
    const char *ext = b_auto ? get_filename_extension( filename ) : "";
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
972
    int b_regular = strcmp( filename, "-" );
973
    if( !b_regular && b_auto )
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
974
        ext = "raw";
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
975
    b_regular = b_regular && x264_is_regular_file_path( filename );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
976
    if( b_regular )
977
    {
978
        FILE *f = fopen( filename, "r" );
979
        if( f )
980
        {
981
            b_regular = x264_is_regular_file( f );
982
            fclose( f );
983
        }
984
    }
985
    const char *module = b_auto ? ext : demuxer;
986
987
    if( !strcasecmp( module, "avs" ) || !strcasecmp( ext, "d2v" ) || !strcasecmp( ext, "dga" ) )
988
    {
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
989
#if HAVE_AVS
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
990
        input = avs_input;
991
        module = "avs";
992
#else
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
993
        x264_cli_log( "x264", X264_LOG_ERROR, "not compiled with AVS input support\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
994
        return -1;
995
#endif
996
    }
997
    else if( !strcasecmp( module, "y4m" ) )
998
        input = y4m_input;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
999
    else if( !strcasecmp( module, "raw" ) || !strcasecmp( ext, "yuv" ) )
1000
        input = raw_input;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1001
    else
1002
    {
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1003
#if HAVE_FFMS
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1004
        if( b_regular && (b_auto || !strcasecmp( demuxer, "ffms" )) &&
1005
            !ffms_input.open_file( filename, p_handle, info, opt ) )
1006
        {
1007
            module = "ffms";
1008
            b_auto = 0;
1009
            input = ffms_input;
1010
        }
1011
#endif
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1012
#if HAVE_LAVF
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1013
        if( (b_auto || !strcasecmp( demuxer, "lavf" )) &&
1014
            !lavf_input.open_file( filename, p_handle, info, opt ) )
1015
        {
1016
            module = "lavf";
1017
            b_auto = 0;
1018
            input = lavf_input;
1019
        }
1020
#endif
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1021
#if HAVE_AVS
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1022
        if( b_regular && (b_auto || !strcasecmp( demuxer, "avs" )) &&
1023
            !avs_input.open_file( filename, p_handle, info, opt ) )
1024
        {
1025
            module = "avs";
1026
            b_auto = 0;
1027
            input = avs_input;
1028
        }
1029
#endif
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1030
        if( b_auto && !raw_input.open_file( filename, p_handle, info, opt ) )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1031
        {
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1032
            module = "raw";
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1033
            b_auto = 0;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1034
            input = raw_input;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1035
        }
1036
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1037
        FAIL_IF_ERROR( !(*p_handle), "could not open input file `%s' via any method!\n", filename )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1038
    }
1039
    strcpy( used_demuxer, module );
1040
1041
    return 0;
1042
}
1043
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1044
static int init_vid_filters( char *sequence, hnd_t *handle, video_info_t *info, x264_param_t *param )
1045
{
1046
    x264_register_vid_filters();
1047
1048
    /* intialize baseline filters */
1049
    if( x264_init_vid_filter( "source", handle, &filter, info, param, NULL ) ) /* wrap demuxer into a filter */
1050
        return -1;
1051
    if( x264_init_vid_filter( "resize", handle, &filter, info, param, "normcsp" ) ) /* normalize csps to be of a known/supported format */
1052
        return -1;
1053
    if( x264_init_vid_filter( "fix_vfr_pts", handle, &filter, info, param, NULL ) ) /* fix vfr pts */
1054
        return -1;
1055
1056
    /* parse filter chain */
1057
    for( char *p = sequence; p && *p; )
1058
    {
1059
        int tok_len = strcspn( p, "/" );
1060
        int p_len = strlen( p );
1061
        p[tok_len] = 0;
1062
        int name_len = strcspn( p, ":" );
1063
        p[name_len] = 0;
1064
        name_len += name_len != tok_len;
1065
        if( x264_init_vid_filter( p, handle, &filter, info, param, p + name_len ) )
1066
            return -1;
1067
        p += X264_MIN( tok_len+1, p_len );
1068
    }
1069
1070
    /* force end result resolution */
1071
    if( !param->i_width && !param->i_height )
1072
    {
1073
        param->i_height = info->height;
1074
        param->i_width  = info->width;
1075
    }
1076
    /* if the current csp is supported by libx264, have libx264 use this csp.
1077
     * otherwise change the csp to I420 and have libx264 use this.
1078
     * when more colorspaces are supported, this decision will need to be updated. */
1079
    int csp = info->csp & X264_CSP_MASK;
1080
    if( csp > X264_CSP_NONE && csp < X264_CSP_MAX )
1081
        param->i_csp = info->csp;
1082
    else
1083
        param->i_csp = X264_CSP_I420 | ( info->csp & X264_CSP_HIGH_DEPTH );
1084
    if( x264_init_vid_filter( "resize", handle, &filter, info, param, NULL ) )
1085
        return -1;
1086
1087
    char args[20];
1088
    sprintf( args, "bit_depth=%d", x264_bit_depth );
1089
1090
    if( x264_init_vid_filter( "depth", handle, &filter, info, param, args ) )
1091
        return -1;
1092
1093
    return 0;
1094
}
1095
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1096
static int parse_enum_name( const char *arg, const char * const *names, const char **dst )
1097
{
1098
    for( int i = 0; names[i]; i++ )
1099
        if( !strcasecmp( arg, names[i] ) )
1100
        {
1101
            *dst = names[i];
1102
            return 0;
1103
        }
1104
    return -1;
1105
}
1106
1107
static int parse_enum_value( const char *arg, const char * const *names, int *dst )
1108
{
1109
    for( int i = 0; names[i]; i++ )
1110
        if( !strcasecmp( arg, names[i] ) )
1111
        {
1112
            *dst = i;
1113
            return 0;
1114
        }
1115
    return -1;
1116
}
1117
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1118
static int parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt )
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1119
{
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1120
    char *input_filename = NULL;
1121
    const char *demuxer = demuxer_names[0];
1122
    char *output_filename = NULL;
1123
    const char *muxer = muxer_names[0];
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1124
    char *tcfile_name = NULL;
1125
    x264_param_t defaults;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1126
    char *profile = NULL;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1127
    char *vid_filters = NULL;
1.1.1 by Sebastian Dröge
Import upstream version 0.cvs20060720
1128
    int b_thread_input = 0;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1129
    int b_turbo = 1;
1130
    int b_user_ref = 0;
1131
    int b_user_fps = 0;
1132
    int b_user_interlaced = 0;
1133
    cli_input_opt_t input_opt;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1134
    char *preset = NULL;
1135
    char *tune = NULL;
1136
1137
    x264_param_default( &defaults );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1138
    cli_log_level = defaults.i_log_level;
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1139
1140
    memset( opt, 0, sizeof(cli_opt_t) );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1141
    memset( &input_opt, 0, sizeof(cli_input_opt_t) );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1142
    input_opt.bit_depth = 8;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1143
    opt->b_progress = 1;
1144
1145
    /* Presets are applied before all other options. */
1146
    for( optind = 0;; )
1147
    {
1148
        int c = getopt_long( argc, argv, short_options, long_options, NULL );
1149
        if( c == -1 )
1150
            break;
1151
        if( c == OPT_PRESET )
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1152
            preset = optarg;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1153
        if( c == OPT_TUNE )
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1154
            tune = optarg;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1155
        else if( c == '?' )
1156
            return -1;
1157
    }
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1158
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1159
    if( preset && !strcasecmp( preset, "placebo" ) )
1160
        b_turbo = 0;
1161
1162
    if( x264_param_default_preset( param, preset, tune ) < 0 )
1163
        return -1;
1164
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1165
    /* Parse command line options */
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1166
    for( optind = 0;; )
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1167
    {
1168
        int b_error = 0;
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1169
        int long_options_index = -1;
1170
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1171
        int c = getopt_long( argc, argv, short_options, long_options, &long_options_index );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1172
1173
        if( c == -1 )
1174
        {
1175
            break;
1176
        }
1177
1178
        switch( c )
1179
        {
1180
            case 'h':
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1181
                help( &defaults, 0 );
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1182
                exit(0);
1183
            case OPT_LONGHELP:
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1184
                help( &defaults, 1 );
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1185
                exit(0);
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1186
            case OPT_FULLHELP:
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1187
                help( &defaults, 2 );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1188
                exit(0);
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1189
            case 'V':
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1190
                print_version_info();
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1191
                exit(0);
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1192
            case OPT_FRAMES:
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1193
                param->i_frame_total = X264_MAX( atoi( optarg ), 0 );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1194
                break;
1195
            case OPT_SEEK:
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1196
                opt->i_seek = input_opt.seek = X264_MAX( atoi( optarg ), 0 );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1197
                break;
1198
            case 'o':
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1199
                output_filename = optarg;
1200
                break;
1201
            case OPT_MUXER:
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1202
                FAIL_IF_ERROR( parse_enum_name( optarg, muxer_names, &muxer ), "Unknown muxer `%s'\n", optarg )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1203
                break;
1204
            case OPT_DEMUXER:
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1205
                FAIL_IF_ERROR( parse_enum_name( optarg, demuxer_names, &demuxer ), "Unknown demuxer `%s'\n", optarg )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1206
                break;
1207
            case OPT_INDEX:
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1208
                input_opt.index_file = optarg;
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1209
                break;
1210
            case OPT_QPFILE:
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1211
                opt->qpfile = fopen( optarg, "rb" );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1212
                FAIL_IF_ERROR( !opt->qpfile, "can't open qpfile `%s'\n", optarg )
1213
                if( !x264_is_regular_file( opt->qpfile ) )
1214
                {
1215
                    x264_cli_log( "x264", X264_LOG_ERROR, "qpfile incompatible with non-regular file `%s'\n", optarg );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1216
                    fclose( opt->qpfile );
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1217
                    return -1;
1218
                }
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1219
                break;
1.1.1 by Sebastian Dröge
Import upstream version 0.cvs20060720
1220
            case OPT_THREAD_INPUT:
1221
                b_thread_input = 1;
1222
                break;
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1223
            case OPT_QUIET:
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1224
                cli_log_level = param->i_log_level = X264_LOG_NONE;
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1225
                break;
1226
            case 'v':
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1227
                cli_log_level = param->i_log_level = X264_LOG_DEBUG;
1228
                break;
1229
            case OPT_LOG_LEVEL:
1230
                if( !parse_enum_value( optarg, log_level_names, &cli_log_level ) )
1231
                    cli_log_level += X264_LOG_NONE;
1232
                else
1233
                    cli_log_level = atoi( optarg );
1234
                param->i_log_level = cli_log_level;
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1235
                break;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1236
            case OPT_NOPROGRESS:
1237
                opt->b_progress = 0;
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1238
                break;
1239
            case OPT_VISUALIZE:
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1240
#if HAVE_VISUALIZE
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1241
                param->b_visualize = 1;
1242
                b_exit_on_ctrl_c = 1;
1243
#else
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1244
                x264_cli_log( "x264", X264_LOG_WARNING, "not compiled with visualization support\n" );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1245
#endif
1246
                break;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1247
            case OPT_TUNE:
1248
            case OPT_PRESET:
1249
                break;
1250
            case OPT_PROFILE:
1251
                profile = optarg;
1252
                break;
1253
            case OPT_SLOWFIRSTPASS:
1254
                b_turbo = 0;
1255
                break;
1256
            case 'r':
1257
                b_user_ref = 1;
1258
                goto generic_option;
1259
            case OPT_FPS:
1260
                b_user_fps = 1;
1261
                param->b_vfr_input = 0;
1262
                goto generic_option;
1263
            case OPT_INTERLACED:
1264
                b_user_interlaced = 1;
1265
                goto generic_option;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1266
            case OPT_TCFILE_IN:
1267
                tcfile_name = optarg;
1268
                break;
1269
            case OPT_TCFILE_OUT:
1270
                opt->tcfile_out = fopen( optarg, "wb" );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1271
                FAIL_IF_ERROR( !opt->tcfile_out, "can't open `%s'\n", optarg )
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1272
                break;
1273
            case OPT_TIMEBASE:
1274
                input_opt.timebase = optarg;
1275
                break;
1276
            case OPT_PULLDOWN:
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1277
                FAIL_IF_ERROR( parse_enum_value( optarg, pulldown_names, &opt->i_pulldown ), "Unknown pulldown `%s'\n", optarg )
1278
                break;
1279
            case OPT_VIDEO_FILTER:
1280
                vid_filters = optarg;
1281
                break;
1282
            case OPT_INPUT_RES:
1283
                input_opt.resolution = optarg;
1284
                break;
1285
            case OPT_INPUT_CSP:
1286
                input_opt.colorspace = optarg;
1287
                break;
1288
            case OPT_INPUT_DEPTH:
1289
                input_opt.bit_depth = atoi( optarg );
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1290
                break;
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1291
            default:
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1292
generic_option:
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1293
            {
1294
                if( long_options_index < 0 )
1295
                {
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1296
                    for( int i = 0; long_options[i].name; i++ )
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1297
                        if( long_options[i].val == c )
1298
                        {
1299
                            long_options_index = i;
1300
                            break;
1301
                        }
1302
                    if( long_options_index < 0 )
1303
                    {
1304
                        /* getopt_long already printed an error message */
1305
                        return -1;
1306
                    }
1307
                }
1308
1.1.3 by John Dong
Import upstream version 0.cvs20070117
1309
                b_error |= x264_param_parse( param, long_options[long_options_index].name, optarg );
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1310
            }
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1311
        }
1312
1313
        if( b_error )
1314
        {
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1315
            const char *name = long_options_index > 0 ? long_options[long_options_index].name : argv[optind-2];
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1316
            x264_cli_log( "x264", X264_LOG_ERROR, "invalid argument: %s = %s\n", name, optarg );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1317
            return -1;
1318
        }
1319
    }
1320
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1321
    /* If first pass mode is used, apply faster settings. */
1322
    if( b_turbo )
1323
        x264_param_apply_fastfirstpass( param );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1324
1325
    /* Apply profile restrictions. */
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1326
    if( x264_param_apply_profile( param, profile ) < 0 )
1327
        return -1;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1328
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1329
    /* Get the file name */
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1330
    FAIL_IF_ERROR( optind > argc - 1 || !output_filename, "No %s file. Run x264 --help for a list of options.\n",
1331
                   optind > argc - 1 ? "input" : "output" )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1332
1333
    if( select_output( muxer, output_filename, param ) )
1334
        return -1;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1335
    FAIL_IF_ERROR( output.open_file( output_filename, &opt->hout ), "could not open output file `%s'\n", output_filename )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1336
1337
    input_filename = argv[optind++];
1338
    video_info_t info = {0};
1339
    char demuxername[5];
1340
1341
    /* set info flags to param flags to be overwritten by demuxer as necessary. */
1342
    info.csp        = param->i_csp;
1343
    info.fps_num    = param->i_fps_num;
1344
    info.fps_den    = param->i_fps_den;
1345
    info.interlaced = param->b_interlaced;
1346
    info.sar_width  = param->vui.i_sar_width;
1347
    info.sar_height = param->vui.i_sar_height;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1348
    info.tff        = param->b_tff;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1349
    info.vfr        = param->b_vfr_input;
1350
1351
    if( select_input( demuxer, demuxername, input_filename, &opt->hin, &info, &input_opt ) )
1352
        return -1;
1353
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1354
    FAIL_IF_ERROR( !opt->hin && input.open_file( input_filename, &opt->hin, &info, &input_opt ),
1355
                   "could not open input file `%s'\n", input_filename )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1356
1357
    x264_reduce_fraction( &info.sar_width, &info.sar_height );
1358
    x264_reduce_fraction( &info.fps_num, &info.fps_den );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1359
    x264_cli_log( demuxername, X264_LOG_INFO, "%dx%d%c %d:%d @ %d/%d fps (%cfr)\n", info.width,
1360
                  info.height, info.interlaced ? 'i' : 'p', info.sar_width, info.sar_height,
1361
                  info.fps_num, info.fps_den, info.vfr ? 'v' : 'c' );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1362
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1363
    if( tcfile_name )
1364
    {
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1365
        FAIL_IF_ERROR( b_user_fps, "--fps + --tcfile-in is incompatible.\n" )
1366
        FAIL_IF_ERROR( timecode_input.open_file( tcfile_name, &opt->hin, &info, &input_opt ), "timecode input failed\n" )
1367
        input = timecode_input;
1368
    }
1369
    else FAIL_IF_ERROR( !info.vfr && input_opt.timebase, "--timebase is incompatible with cfr input\n" )
1370
1371
    /* init threaded input while the information about the input video is unaltered by filtering */
1372
#if HAVE_PTHREAD
1373
    if( info.thread_safe && (b_thread_input || param->i_threads > 1
1374
        || (param->i_threads == X264_THREADS_AUTO && x264_cpu_num_processors() > 1)) )
1375
    {
1376
        if( thread_input.open_file( NULL, &opt->hin, &info, NULL ) )
1377
        {
1378
            fprintf( stderr, "x264 [error]: threaded input failed\n" );
1379
            return -1;
1380
        }
1381
        input = thread_input;
1382
    }
1383
#endif
1384
1385
    /* override detected values by those specified by the user */
1386
    if( param->vui.i_sar_width && param->vui.i_sar_height )
1387
    {
1388
        info.sar_width  = param->vui.i_sar_width;
1389
        info.sar_height = param->vui.i_sar_height;
1390
    }
1391
    if( b_user_fps )
1392
    {
1393
        info.fps_num = param->i_fps_num;
1394
        info.fps_den = param->i_fps_den;
1395
    }
1396
    if( !info.vfr )
1397
    {
1398
        info.timebase_num = info.fps_den;
1399
        info.timebase_den = info.fps_num;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1400
    }
1401
    if( !tcfile_name && input_opt.timebase )
1402
    {
1403
        uint64_t i_user_timebase_num;
1404
        uint64_t i_user_timebase_den;
1405
        int ret = sscanf( input_opt.timebase, "%"SCNu64"/%"SCNu64, &i_user_timebase_num, &i_user_timebase_den );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1406
        FAIL_IF_ERROR( !ret, "invalid argument: timebase = %s\n", input_opt.timebase )
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1407
        else if( ret == 1 )
1408
        {
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1409
            i_user_timebase_num = info.timebase_num;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1410
            i_user_timebase_den = strtoul( input_opt.timebase, NULL, 10 );
1411
        }
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1412
        FAIL_IF_ERROR( i_user_timebase_num > UINT32_MAX || i_user_timebase_den > UINT32_MAX,
1413
                       "timebase you specified exceeds H.264 maximum\n" )
1414
        opt->timebase_convert_multiplier = ((double)i_user_timebase_den / info.timebase_den)
1415
                                         * ((double)info.timebase_num / i_user_timebase_num);
1416
        info.timebase_num = i_user_timebase_num;
1417
        info.timebase_den = i_user_timebase_den;
1418
        info.vfr = 1;
1419
    }
1420
    if( b_user_interlaced )
1421
    {
1422
        info.interlaced = param->b_interlaced;
1423
        info.tff = param->b_tff;
1424
    }
1425
1426
    if( init_vid_filters( vid_filters, &opt->hin, &info, param ) )
1427
        return -1;
1428
1429
    /* set param flags from the post-filtered video */
1430
    param->b_vfr_input = info.vfr;
1431
    param->i_fps_num = info.fps_num;
1432
    param->i_fps_den = info.fps_den;
1433
    param->i_timebase_num = info.timebase_num;
1434
    param->i_timebase_den = info.timebase_den;
1435
    param->vui.i_sar_width  = info.sar_width;
1436
    param->vui.i_sar_height = info.sar_height;
1437
1438
    info.num_frames = X264_MAX( info.num_frames - opt->i_seek, 0 );
1439
    if( (!info.num_frames || param->i_frame_total < info.num_frames)
1440
        && param->i_frame_total > 0 )
1441
        info.num_frames = param->i_frame_total;
1442
    param->i_frame_total = info.num_frames;
1443
1444
    if( !b_user_interlaced && info.interlaced )
1445
    {
1446
        x264_cli_log( "x264", X264_LOG_WARNING, "input appears to be interlaced, enabling %cff interlaced mode.\n"
1447
                      "                If you want otherwise, use --no-interlaced or --%cff\n",
1448
                      info.tff ? 't' : 'b', info.tff ? 'b' : 't' );
1449
        param->b_interlaced = 1;
1450
        param->b_tff = !!info.tff;
1451
    }
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1452
1453
    /* Automatically reduce reference frame count to match the user's target level
1454
     * if the user didn't explicitly set a reference frame count. */
1455
    if( !b_user_ref )
1456
    {
1457
        int mbs = (((param->i_width)+15)>>4) * (((param->i_height)+15)>>4);
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1458
        for( int i = 0; x264_levels[i].level_idc != 0; i++ )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1459
            if( param->i_level_idc == x264_levels[i].level_idc )
1460
            {
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1461
                while( mbs * 384 * param->i_frame_reference > x264_levels[i].dpb &&
1462
                       param->i_frame_reference > 1 )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1463
                {
1464
                    param->i_frame_reference--;
1465
                }
1466
                break;
1467
            }
1468
    }
1469
1470
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1471
    return 0;
1472
}
1473
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1474
static void parse_qpfile( cli_opt_t *opt, x264_picture_t *pic, int i_frame )
1475
{
1.1.8 by Lionel Le Folgoc
Import upstream version 0.svn20081230
1476
    int num = -1, qp, ret;
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1477
    char type;
1.1.8 by Lionel Le Folgoc
Import upstream version 0.svn20081230
1478
    uint64_t file_pos;
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1479
    while( num < i_frame )
1480
    {
1.1.8 by Lionel Le Folgoc
Import upstream version 0.svn20081230
1481
        file_pos = ftell( opt->qpfile );
1482
        ret = fscanf( opt->qpfile, "%d %c %d\n", &num, &type, &qp );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1483
        if( num > i_frame || ret == EOF )
1484
        {
1485
            pic->i_type = X264_TYPE_AUTO;
1486
            pic->i_qpplus1 = 0;
1487
            fseek( opt->qpfile, file_pos, SEEK_SET );
1488
            break;
1489
        }
1490
        if( num < i_frame && ret == 3 )
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1491
            continue;
1492
        pic->i_qpplus1 = qp+1;
1493
        if     ( type == 'I' ) pic->i_type = X264_TYPE_IDR;
1494
        else if( type == 'i' ) pic->i_type = X264_TYPE_I;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1495
        else if( type == 'K' ) pic->i_type = X264_TYPE_KEYFRAME;
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1496
        else if( type == 'P' ) pic->i_type = X264_TYPE_P;
1497
        else if( type == 'B' ) pic->i_type = X264_TYPE_BREF;
1498
        else if( type == 'b' ) pic->i_type = X264_TYPE_B;
1499
        else ret = 0;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1500
        if( ret != 3 || qp < -1 || qp > QP_MAX )
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1501
        {
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1502
            x264_cli_log( "x264", X264_LOG_ERROR, "can't parse qpfile for frame %d\n", i_frame );
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1503
            fclose( opt->qpfile );
1504
            opt->qpfile = NULL;
1505
            pic->i_type = X264_TYPE_AUTO;
1506
            pic->i_qpplus1 = 0;
1507
            break;
1508
        }
1509
    }
1510
}
1511
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1512
static int encode_frame( x264_t *h, hnd_t hout, x264_picture_t *pic, int64_t *last_dts )
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1513
{
1514
    x264_picture_t pic_out;
1515
    x264_nal_t *nal;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1516
    int i_nal;
1517
    int i_frame_size = 0;
1518
1519
    i_frame_size = x264_encoder_encode( h, &nal, &i_nal, pic, &pic_out );
1520
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1521
    FAIL_IF_ERROR( i_frame_size < 0, "x264_encoder_encode failed\n" );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1522
1523
    if( i_frame_size )
1524
    {
1525
        i_frame_size = output.write_frame( hout, nal[0].p_payload, i_frame_size, &pic_out );
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1526
        *last_dts = pic_out.i_dts;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1527
    }
1528
1529
    return i_frame_size;
1530
}
1531
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1532
static void print_status( int64_t i_start, int i_frame, int i_frame_total, int64_t i_file, x264_param_t *param, int64_t last_ts )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1533
{
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1534
    char buf[200];
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1535
    int64_t i_elapsed = x264_mdate() - i_start;
1536
    double fps = i_elapsed > 0 ? i_frame * 1000000. / i_elapsed : 0;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1537
    double bitrate;
1538
    if( last_ts )
1539
        bitrate = (double) i_file * 8 / ( (double) last_ts * 1000 * param->i_timebase_num / param->i_timebase_den );
1540
    else
1541
        bitrate = (double) i_file * 8 / ( (double) 1000 * param->i_fps_den / param->i_fps_num );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1542
    if( i_frame_total )
1543
    {
1544
        int eta = i_elapsed * (i_frame_total - i_frame) / ((int64_t)i_frame * 1000000);
1545
        sprintf( buf, "x264 [%.1f%%] %d/%d frames, %.2f fps, %.2f kb/s, eta %d:%02d:%02d",
1546
                 100. * i_frame / i_frame_total, i_frame, i_frame_total, fps, bitrate,
1547
                 eta/3600, (eta/60)%60, eta%60 );
1548
    }
1549
    else
1550
    {
1551
        sprintf( buf, "x264 %d frames: %.2f fps, %.2f kb/s", i_frame, fps, bitrate );
1552
    }
1553
    fprintf( stderr, "%s  \r", buf+5 );
1554
    SetConsoleTitle( buf );
1555
    fflush( stderr ); // needed in windows
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1556
}
1557
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1558
static void convert_cli_to_lib_pic( x264_picture_t *lib, cli_pic_t *cli )
1559
{
1560
    memcpy( lib->img.i_stride, cli->img.stride, sizeof(cli->img.stride) );
1561
    memcpy( lib->img.plane, cli->img.plane, sizeof(cli->img.plane) );
1562
    lib->img.i_plane = cli->img.planes;
1563
    lib->img.i_csp = cli->img.csp;
1564
    lib->i_pts = cli->pts;
1565
}
1566
1567
static int encode( x264_param_t *param, cli_opt_t *opt )
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1568
{
1569
    x264_t *h;
1570
    x264_picture_t pic;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1571
    cli_pic_t cli_pic;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1572
    const cli_pulldown_t *pulldown = NULL; // shut up gcc
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1573
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1574
    int     i_frame, i_frame_output;
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1575
    int64_t i_start, i_end;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1576
    int64_t i_file = 0;
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1577
    int     i_frame_size;
1.1.8 by Lionel Le Folgoc
Import upstream version 0.svn20081230
1578
    int     i_update_interval;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1579
    int64_t last_dts = 0;
1580
    int64_t prev_dts = 0;
1581
    int64_t first_dts = 0;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1582
#   define  MAX_PTS_WARNING 3 /* arbitrary */
1583
    int     pts_warning_cnt = 0;
1584
    int64_t largest_pts = -1;
1585
    int64_t second_largest_pts = -1;
1586
    int64_t ticks_per_frame;
1587
    double  duration;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1588
    int     prev_timebase_den;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1589
    int     dts_compress_multiplier;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1590
    double  pulldown_pts = 0;
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1591
1.1.8 by Lionel Le Folgoc
Import upstream version 0.svn20081230
1592
    opt->b_progress &= param->i_log_level < X264_LOG_DEBUG;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1593
    i_update_interval = param->i_frame_total ? x264_clip3( param->i_frame_total / 1000, 1, 10 ) : 10;
1594
    x264_picture_init( &pic );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1595
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1596
    /* set up pulldown */
1597
    if( opt->i_pulldown && !param->b_vfr_input )
1598
    {
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1599
        param->b_pulldown = 1;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1600
        param->b_pic_struct = 1;
1601
        pulldown = &pulldown_values[opt->i_pulldown];
1602
        param->i_timebase_num = param->i_fps_den;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1603
        FAIL_IF_ERROR( fmod( param->i_fps_num * pulldown->fps_factor, 1 ),
1604
                       "unsupported framerate for chosen pulldown\n" )
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1605
        param->i_timebase_den = param->i_fps_num * pulldown->fps_factor;
1606
    }
1607
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1608
    prev_timebase_den = param->i_timebase_den / gcd( param->i_timebase_num, param->i_timebase_den );
1609
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1610
    if( ( h = x264_encoder_open( param ) ) == NULL )
1611
    {
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1612
        x264_cli_log( "x264", X264_LOG_ERROR, "x264_encoder_open failed\n" );
1613
        filter.free( opt->hin );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1614
        return -1;
1615
    }
1616
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1617
    x264_encoder_parameters( h, param );
1618
1619
    dts_compress_multiplier = param->i_timebase_den / prev_timebase_den;
1620
1621
    if( output.set_param( opt->hout, param ) )
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1622
    {
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1623
        x264_cli_log( "x264", X264_LOG_ERROR, "can't set outfile param\n" );
1624
        filter.free( opt->hin );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1625
        output.close_file( opt->hout, largest_pts, second_largest_pts );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1626
        return -1;
1627
    }
1628
1629
    i_start = x264_mdate();
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1630
    /* ticks/frame = ticks/second / frames/second */
1631
    ticks_per_frame = (int64_t)param->i_timebase_den * param->i_fps_den / param->i_timebase_num / param->i_fps_num;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1632
    FAIL_IF_ERROR( ticks_per_frame < 1, "ticks_per_frame invalid: %"PRId64"\n", ticks_per_frame )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1633
1634
    if( !param->b_repeat_headers )
1635
    {
1636
        // Write SPS/PPS/SEI
1637
        x264_nal_t *headers;
1638
        int i_nal;
1639
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1640
        FAIL_IF_ERROR( x264_encoder_headers( h, &headers, &i_nal ) < 0, "x264_encoder_headers failed\n" )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1641
        if( (i_file = output.write_headers( opt->hout, headers )) < 0 )
1642
            return -1;
1643
    }
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1644
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1645
    if( opt->tcfile_out )
1646
        fprintf( opt->tcfile_out, "# timecode format v2\n" );
1647
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1648
    /* Encode frames */
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1649
    for( i_frame = 0, i_frame_output = 0; !b_ctrl_c && (i_frame < param->i_frame_total || !param->i_frame_total); i_frame++ )
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1650
    {
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1651
        if( filter.get_frame( opt->hin, &cli_pic, i_frame + opt->i_seek ) )
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1652
            break;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1653
        convert_cli_to_lib_pic( &pic, &cli_pic );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1654
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1655
        if( !param->b_vfr_input )
1656
            pic.i_pts = i_frame;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1657
1658
        if( opt->i_pulldown && !param->b_vfr_input )
1659
        {
1660
            pic.i_pic_struct = pulldown->pattern[ i_frame % pulldown->mod ];
1661
            pic.i_pts = (int64_t)( pulldown_pts + 0.5 );
1662
            pulldown_pts += pulldown_frame_duration[pic.i_pic_struct];
1663
        }
1664
        else if( opt->timebase_convert_multiplier )
1665
            pic.i_pts = (int64_t)( pic.i_pts * opt->timebase_convert_multiplier + 0.5 );
1666
1667
        int64_t output_pts = pic.i_pts * dts_compress_multiplier;   /* pts libx264 returns */
1668
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1669
        if( pic.i_pts <= largest_pts )
1670
        {
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1671
            if( cli_log_level >= X264_LOG_DEBUG || pts_warning_cnt < MAX_PTS_WARNING )
1672
                x264_cli_log( "x264", X264_LOG_WARNING, "non-strictly-monotonic pts at frame %d (%"PRId64" <= %"PRId64")\n",
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1673
                             i_frame, output_pts, largest_pts * dts_compress_multiplier );
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1674
            else if( pts_warning_cnt == MAX_PTS_WARNING )
1675
                x264_cli_log( "x264", X264_LOG_WARNING, "too many nonmonotonic pts warnings, suppressing further ones\n" );
1676
            pts_warning_cnt++;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1677
            pic.i_pts = largest_pts + ticks_per_frame;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1678
            output_pts = pic.i_pts * dts_compress_multiplier;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1679
        }
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1680
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1681
        second_largest_pts = largest_pts;
1682
        largest_pts = pic.i_pts;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1683
        if( opt->tcfile_out )
1684
            fprintf( opt->tcfile_out, "%.6f\n", output_pts * ((double)param->i_timebase_num / param->i_timebase_den) * 1e3 );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1685
1.1.2 by Christian Marillat
Import upstream version 0.cvs20060928
1686
        if( opt->qpfile )
1687
            parse_qpfile( opt, &pic, i_frame + opt->i_seek );
1688
        else
1689
        {
1690
            /* Do not force any parameters */
1691
            pic.i_type = X264_TYPE_AUTO;
1692
            pic.i_qpplus1 = 0;
1693
        }
1694
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1695
        prev_dts = last_dts;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1696
        i_frame_size = encode_frame( h, opt->hout, &pic, &last_dts );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1697
        if( i_frame_size < 0 )
1698
            return -1;
1699
        i_file += i_frame_size;
1700
        if( i_frame_size )
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1701
        {
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1702
            i_frame_output++;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1703
            if( i_frame_output == 1 )
1704
                first_dts = prev_dts = last_dts;
1705
        }
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1706
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1707
        if( filter.release_frame( opt->hin, &cli_pic, i_frame + opt->i_seek ) )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1708
            break;
1709
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1710
        /* update status line (up to 1000 times per input file) */
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1711
        if( opt->b_progress && i_frame_output % i_update_interval == 0 && i_frame_output )
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1712
            print_status( i_start, i_frame_output, param->i_frame_total, i_file, param, 2 * last_dts - prev_dts - first_dts );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1713
    }
1714
    /* Flush delayed frames */
1715
    while( !b_ctrl_c && x264_encoder_delayed_frames( h ) )
1716
    {
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1717
        prev_dts = last_dts;
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1718
        i_frame_size = encode_frame( h, opt->hout, NULL, &last_dts );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1719
        if( i_frame_size < 0 )
1720
            return -1;
1721
        i_file += i_frame_size;
1722
        if( i_frame_size )
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1723
        {
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1724
            i_frame_output++;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1725
            if( i_frame_output == 1 )
1726
                first_dts = prev_dts = last_dts;
1727
        }
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1728
        if( opt->b_progress && i_frame_output % i_update_interval == 0 && i_frame_output )
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1729
            print_status( i_start, i_frame_output, param->i_frame_total, i_file, param, 2 * last_dts - prev_dts - first_dts );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1730
    }
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1731
    if( pts_warning_cnt >= MAX_PTS_WARNING && cli_log_level < X264_LOG_DEBUG )
1732
        x264_cli_log( "x264", X264_LOG_WARNING, "%d suppressed nonmonotonic pts warnings\n", pts_warning_cnt-MAX_PTS_WARNING );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1733
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1734
    largest_pts *= dts_compress_multiplier;
1735
    second_largest_pts *= dts_compress_multiplier;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1736
    /* duration algorithm fails when only 1 frame is output */
1737
    if( i_frame_output == 1 )
1738
        duration = (double)param->i_fps_den / param->i_fps_num;
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1739
    else if( b_ctrl_c )
1740
        duration = (double)(2 * last_dts - prev_dts - first_dts) * param->i_timebase_num / param->i_timebase_den;
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1741
    else
1742
        duration = (double)(2 * largest_pts - second_largest_pts) * param->i_timebase_num / param->i_timebase_den;
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1743
1744
    i_end = x264_mdate();
1.1.8 by Lionel Le Folgoc
Import upstream version 0.svn20081230
1745
    /* Erase progress indicator before printing encoding stats. */
1746
    if( opt->b_progress )
1747
        fprintf( stderr, "                                                                               \r" );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1748
    x264_encoder_close( h );
1749
    fprintf( stderr, "\n" );
1750
1751
    if( b_ctrl_c )
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1752
        fprintf( stderr, "aborted at input frame %d, output frame %d\n", opt->i_seek + i_frame, i_frame_output );
1753
1.2.2 by Reinhard Tartler
Import upstream version 0.98.1653+git88b90d9
1754
    if( opt->tcfile_out )
1755
    {
1756
        fclose( opt->tcfile_out );
1757
        opt->tcfile_out = NULL;
1758
    }
1759
1.2.3 by Reinhard Tartler
Import upstream version 0.106.1741
1760
    filter.free( opt->hin );
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1761
    output.close_file( opt->hout, largest_pts, second_largest_pts );
1762
1763
    if( i_frame_output > 0 )
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1764
    {
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1765
        double fps = (double)i_frame_output * (double)1000000 /
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1766
                     (double)( i_end - i_start );
1767
1.1.11 by Reinhard Tartler
Import upstream version 0.85.1442+gitfcf70c
1768
        fprintf( stderr, "encoded %d frames, %.2f fps, %.2f kb/s\n", i_frame_output, fps,
1769
                 (double) i_file * 8 / ( 1000 * duration ) );
1 by Reinhard Tartler
Import upstream version 0.cvs20060210
1770
    }
1771
1772
    return 0;
1773
}