Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
cmdutils.h
Go to the documentation of this file.
1
/*
2
* Various utilities for command line tools
3
* copyright (c) 2003 Fabrice Bellard
4
*
5
* This file is part of Libav.
6
*
7
* Libav is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
11
*
12
* Libav is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
16
*
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with Libav; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
*/
21
22
#ifndef LIBAV_CMDUTILS_H
23
#define LIBAV_CMDUTILS_H
24
25
#include <stdint.h>
26
27
#include "
libavcodec/avcodec.h
"
28
#include "
libavfilter/avfilter.h
"
29
#include "
libavformat/avformat.h
"
30
#include "
libswscale/swscale.h
"
31
35
extern
const
char
program_name
[];
36
40
extern
const
int
program_birth_year
;
41
42
extern
AVCodecContext
*
avcodec_opts
[
AVMEDIA_TYPE_NB
];
43
extern
AVFormatContext
*
avformat_opts
;
44
extern
struct
SwsContext
*
sws_opts
;
45
extern
AVDictionary
*
format_opts
, *
codec_opts
;
46
51
void
init_opts
(
void
);
56
void
uninit_opts
(
void
);
57
62
void
log_callback_help
(
void
* ptr,
int
level
,
const
char
* fmt, va_list vl);
63
68
int
opt_default
(
void
*optctx,
const
char
*opt,
const
char
*arg);
69
73
int
opt_loglevel
(
void
*optctx,
const
char
*opt,
const
char
*arg);
74
78
int
opt_timelimit
(
void
*optctx,
const
char
*opt,
const
char
*arg);
79
93
double
parse_number_or_die
(
const
char
*context,
const
char
*numstr,
int
type,
94
double
min
,
double
max);
95
110
int64_t
parse_time_or_die
(
const
char
*context,
const
char
*timestr,
111
int
is_duration);
112
113
typedef
struct
SpecifierOpt
{
114
char
*
specifier
;
115
union
{
116
uint8_t
*
str
;
117
int
i
;
118
int64_t
i64
;
119
float
f
;
120
double
dbl
;
121
}
u
;
122
}
SpecifierOpt
;
123
124
typedef
struct
OptionDef
{
125
const
char
*
name
;
126
int
flags
;
127
#define HAS_ARG 0x0001
128
#define OPT_BOOL 0x0002
129
#define OPT_EXPERT 0x0004
130
#define OPT_STRING 0x0008
131
#define OPT_VIDEO 0x0010
132
#define OPT_AUDIO 0x0020
133
#define OPT_INT 0x0080
134
#define OPT_FLOAT 0x0100
135
#define OPT_SUBTITLE 0x0200
136
#define OPT_INT64 0x0400
137
#define OPT_EXIT 0x0800
138
#define OPT_DATA 0x1000
139
#define OPT_PERFILE 0x2000
/* the option is per-file (currently avconv-only).
140
implied by OPT_OFFSET or OPT_SPEC */
141
#define OPT_OFFSET 0x4000
/* option is specified as an offset in a passed optctx */
142
#define OPT_SPEC 0x8000
/* option is to be stored in an array of SpecifierOpt.
143
Implies OPT_OFFSET. Next element after the offset is
144
an int containing element count in the array. */
145
#define OPT_TIME 0x10000
146
#define OPT_DOUBLE 0x20000
147
union
{
148
void
*
dst_ptr
;
149
int (*
func_arg
)(
void
*,
const
char
*,
const
char
*);
150
size_t
off
;
151
}
u
;
152
const
char
*
help
;
153
const
char
*
argname
;
154
}
OptionDef
;
155
165
void
show_help_options
(
const
OptionDef
*
options
,
const
char
*msg,
int
req_flags,
166
int
rej_flags,
int
alt_flags);
167
172
void
show_help_children
(
const
AVClass
*
class
,
int
flags
);
173
178
void
show_help_default
(
const
char
*opt,
const
char
*arg);
179
183
int
show_help
(
void
*optctx,
const
char
*opt,
const
char
*arg);
184
197
void
parse_options
(
void
*optctx,
int
argc,
char
**argv,
const
OptionDef
*
options
,
198
void
(* parse_arg_function)(
void
*optctx,
const
char
*));
199
205
int
parse_option
(
void
*optctx,
const
char
*opt,
const
char
*arg,
206
const
OptionDef
*options);
207
213
typedef
struct
Option
{
214
const
OptionDef
*
opt
;
215
const
char
*
key
;
216
const
char
*
val
;
217
}
Option
;
218
219
typedef
struct
OptionGroupDef
{
221
const
char
*
name
;
226
const
char
*
sep
;
227
}
OptionGroupDef
;
228
229
typedef
struct
OptionGroup
{
230
const
OptionGroupDef
*
group_def
;
231
const
char
*
arg
;
232
233
Option
*
opts
;
234
int
nb_opts
;
235
236
AVDictionary
*
codec_opts
;
237
AVDictionary
*
format_opts
;
238
struct
SwsContext
*
sws_opts
;
239
}
OptionGroup
;
240
245
typedef
struct
OptionGroupList
{
246
const
OptionGroupDef
*
group_def
;
247
248
OptionGroup
*
groups
;
249
int
nb_groups
;
250
}
OptionGroupList
;
251
252
typedef
struct
OptionParseContext
{
253
OptionGroup
global_opts
;
254
255
OptionGroupList
*
groups
;
256
int
nb_groups
;
257
258
/* parsing state */
259
OptionGroup
cur_group
;
260
}
OptionParseContext
;
261
267
int
parse_optgroup
(
void
*optctx,
OptionGroup
*
g
);
268
287
int
split_commandline
(
OptionParseContext
*
octx
,
int
argc,
char
*argv[],
288
const
OptionDef
*options,
289
const
OptionGroupDef
*
groups
,
int
nb_groups);
290
294
void
uninit_parse_context
(
OptionParseContext
*
octx
);
295
299
void
parse_loglevel
(
int
argc,
char
**argv,
const
OptionDef
*options);
300
304
int
locate_option
(
int
argc,
char
**argv,
const
OptionDef
*options,
305
const
char
*optname);
306
316
int
check_stream_specifier
(
AVFormatContext
*s,
AVStream
*st,
const
char
*spec);
317
332
AVDictionary
*
filter_codec_opts
(
AVDictionary
*opts,
enum
AVCodecID
codec_id
,
333
AVFormatContext
*s,
AVStream
*st,
AVCodec
*codec);
334
346
AVDictionary
**
setup_find_stream_info_opts
(
AVFormatContext
*s,
347
AVDictionary
*codec_opts);
348
358
void
print_error
(
const
char
*filename,
int
err);
359
365
void
show_banner
(
void
);
366
372
int
show_version
(
void
*optctx,
const
char
*opt,
const
char
*arg);
373
378
int
show_license
(
void
*optctx,
const
char
*opt,
const
char
*arg);
379
384
int
show_formats
(
void
*optctx,
const
char
*opt,
const
char
*arg);
385
390
int
show_codecs
(
void
*optctx,
const
char
*opt,
const
char
*arg);
391
396
int
show_decoders
(
void
*optctx,
const
char
*opt,
const
char
*arg);
397
402
int
show_encoders
(
void
*optctx,
const
char
*opt,
const
char
*arg);
403
408
int
show_filters
(
void
*optctx,
const
char
*opt,
const
char
*arg);
409
414
int
show_bsfs
(
void
*optctx,
const
char
*opt,
const
char
*arg);
415
420
int
show_protocols
(
void
*optctx,
const
char
*opt,
const
char
*arg);
421
426
int
show_pix_fmts
(
void
*optctx,
const
char
*opt,
const
char
*arg);
427
432
int
show_sample_fmts
(
void
*optctx,
const
char
*opt,
const
char
*arg);
433
438
int
read_yesno
(
void
);
439
450
int
cmdutils_read_file
(
const
char
*filename,
char
**bufptr,
size_t
*
size
);
451
452
typedef
struct
PtsCorrectionContext
{
453
int64_t
num_faulty_pts
;
454
int64_t
num_faulty_dts
;
455
int64_t
last_pts
;
456
int64_t
last_dts
;
457
}
PtsCorrectionContext
;
458
462
void
init_pts_correction
(
PtsCorrectionContext
*ctx);
463
475
int64_t
guess_correct_pts
(
PtsCorrectionContext
*ctx, int64_t pts, int64_t dts);
476
494
FILE *
get_preset_file
(
char
*filename,
size_t
filename_size,
495
const
char
*preset_name,
int
is_path,
const
char
*codec_name);
496
507
void
*
grow_array
(
void
*array,
int
elem_size,
int
*
size
,
int
new_size);
508
509
#define GROW_ARRAY(array, nb_elems)\
510
array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
511
512
typedef
struct
FrameBuffer
{
513
uint8_t
*
base
[4];
514
uint8_t
*
data
[4];
515
int
linesize
[4];
516
517
int
h
,
w
;
518
enum
AVPixelFormat
pix_fmt
;
519
520
int
refcount
;
521
struct
FrameBuffer
**
pool
;
522
struct
FrameBuffer
*
next
;
523
}
FrameBuffer
;
524
534
int
codec_get_buffer
(
AVCodecContext
*s,
AVFrame
*frame);
535
540
void
codec_release_buffer
(
AVCodecContext
*s,
AVFrame
*frame);
541
547
void
filter_release_buffer
(
AVFilterBuffer
*fb);
548
553
void
free_buffer_pool
(
FrameBuffer
**
pool
);
554
555
#define GET_PIX_FMT_NAME(pix_fmt)\
556
const char *name = av_get_pix_fmt_name(pix_fmt);
557
558
#define GET_SAMPLE_FMT_NAME(sample_fmt)\
559
const char *name = av_get_sample_fmt_name(sample_fmt)
560
561
#define GET_SAMPLE_RATE_NAME(rate)\
562
char name[16];\
563
snprintf(name, sizeof(name), "%d", rate);
564
565
#define GET_CH_LAYOUT_NAME(ch_layout)\
566
char name[16];\
567
snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
568
569
#define GET_CH_LAYOUT_DESC(ch_layout)\
570
char name[128];\
571
av_get_channel_layout_string(name, sizeof(name), 0, ch_layout);
572
573
#endif
/* LIBAV_CMDUTILS_H */