Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
}
if (use_audio) {
AVCodecContext *audio_enc;
st = av_mallocz(sizeof(AVStream));
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
audio_enc = &st->codec;
codec_id = file_format->audio_codec;
if (audio_codec_id != CODEC_ID_NONE)
codec_id = audio_codec_id;
audio_enc->codec_id = codec_id;
audio_enc->codec_type = CODEC_TYPE_AUDIO;
audio_enc->bit_rate = audio_bit_rate;
audio_enc->sample_rate = audio_sample_rate;
audio_enc->channels = audio_channels;
oc->streams[nb_streams] = st;
nb_streams++;
}
oc->nb_streams = nb_streams;
if (!nb_streams) {
Fabrice Bellard
committed
fprintf(stderr, "No audio or video streams available\n");
exit(1);
}
if (str_title)
nstrcpy(oc->title, sizeof(oc->title), str_title);
if (str_author)
nstrcpy(oc->author, sizeof(oc->author), str_author);
if (str_copyright)
nstrcpy(oc->copyright, sizeof(oc->copyright), str_copyright);
if (str_comment)
nstrcpy(oc->comment, sizeof(oc->comment), str_comment);
}
output_files[nb_output_files] = oc;
/* dump the file content */
dump_format(oc, nb_output_files, filename, 1);
nb_output_files++;
strcpy(oc->filename, filename);
Fabrice Bellard
committed
/* check filename in case of an image number is expected */
if (oc->format->flags & AVFMT_NEEDNUMBER) {
if (filename_number_test(oc->filename) < 0)
exit(1);
}
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
if (!(oc->format->flags & AVFMT_NOFILE)) {
/* test if it already exists to avoid loosing precious files */
if (!file_overwrite &&
(strchr(filename, ':') == NULL ||
strstart(filename, "file:", NULL))) {
if (url_exist(filename)) {
int c;
printf("File '%s' already exists. Overwrite ? [y/N] ", filename);
fflush(stdout);
c = getchar();
if (toupper(c) != 'Y') {
fprintf(stderr, "Not overwriting - exiting\n");
exit(1);
}
}
}
/* open the file */
if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) {
fprintf(stderr, "Could not open '%s'\n", filename);
exit(1);
}
}
/* reset some options */
file_format = NULL;
audio_disable = 0;
video_disable = 0;
audio_codec_id = CODEC_ID_NONE;
video_codec_id = CODEC_ID_NONE;
}
INT64 getutime(void)
{
struct rusage rusage;
getrusage(RUSAGE_SELF, &rusage);
return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
}
#else
INT64 getutime(void)
{
return gettime();
}
#endif
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
void show_formats(void)
{
AVFormat *f;
URLProtocol *up;
AVCodec *p;
const char **pp;
printf("File formats:\n");
printf(" Encoding:");
for(f = first_format; f != NULL; f = f->next) {
if (f->write_header)
printf(" %s", f->name);
}
printf("\n");
printf(" Decoding:");
for(f = first_format; f != NULL; f = f->next) {
if (f->read_header)
printf(" %s", f->name);
}
printf("\n");
printf("Codecs:\n");
printf(" Encoders:");
for(p = first_avcodec; p != NULL; p = p->next) {
if (p->encode)
printf(" %s", p->name);
}
printf("\n");
printf(" Decoders:");
for(p = first_avcodec; p != NULL; p = p->next) {
if (p->decode)
printf(" %s", p->name);
}
printf("\n");
printf("Supported file protocols:");
for(up = first_protocol; up != NULL; up = up->next)
printf(" %s:", up->name);
printf("\n");
printf("Frame size abbreviations: sqcif qcif cif 4cif\n");
printf("Motion estimation methods:");
pp = motion_str;
while (*pp) {
printf(" %s", *pp);
if ((pp - motion_str) == ME_ZERO)
printf("(fastest)");
else if ((pp - motion_str) == ME_FULL)
printf("(slowest)");
else if ((pp - motion_str) == ME_LOG)
printf("(default)");
pp++;
}
printf("\n");
exit(1);
}
void show_help(void)
{
const OptionDef *po;
int i, expert;
printf("ffmpeg version " FFMPEG_VERSION ", Copyright (c) 2000,2001 Gerard Lantau\n"
"usage: ffmpeg [[options] -i input_file]... {[options] outfile}...\n"
"Hyper fast MPEG1/MPEG4/H263/RV and AC3/MPEG audio encoder\n"
"\n"
"Main options are:\n");
for(i=0;i<2;i++) {
if (i == 1)
printf("\nAdvanced options are:\n");
for(po = options; po->name != NULL; po++) {
char buf[64];
expert = (po->flags & OPT_EXPERT) != 0;
if (expert == i) {
strcpy(buf, po->name);
if (po->flags & HAS_ARG) {
strcat(buf, " ");
strcat(buf, po->argname);
}
printf("-%-17s %s\n", buf, po->help);
}
}
}
exit(1);
}
const OptionDef options[] = {
{ "L", 0, {(void*)show_licence}, "show license" },
{ "h", 0, {(void*)show_help}, "show help" },
{ "formats", 0, {(void*)show_formats}, "show available formats, codecs, protocols, ..." },
{ "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
{ "i", HAS_ARG, {(void*)opt_input_file}, "input file name", "filename" },
{ "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
{ "map", HAS_ARG | OPT_EXPERT, {(void*)opt_map}, "set input stream mapping", "file:stream" },
{ "t", HAS_ARG, {(void*)opt_recording_time}, "set the recording time", "duration" },
{ "title", HAS_ARG | OPT_STRING, {(void*)&str_title}, "set the title", "string" },
{ "author", HAS_ARG | OPT_STRING, {(void*)&str_author}, "set the author", "string" },
{ "copyright", HAS_ARG | OPT_STRING, {(void*)&str_copyright}, "set the copyright", "string" },
{ "comment", HAS_ARG | OPT_STRING, {(void*)&str_comment}, "set the comment", "string" },
{ "b", HAS_ARG, {(void*)opt_video_bitrate}, "set video bitrate (in kbit/s)", "bitrate" },
{ "r", HAS_ARG, {(void*)opt_frame_rate}, "set frame rate (in Hz)", "rate" },
{ "s", HAS_ARG, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" },
{ "g", HAS_ARG | OPT_EXPERT, {(void*)opt_gop_size}, "set the group of picture size", "gop_size" },
{ "intra", OPT_BOOL | OPT_EXPERT, {(void*)&intra_only}, "use only intra frames"},
{ "vn", OPT_BOOL, {(void*)&video_disable}, "disable video" },
{ "qscale", HAS_ARG | OPT_EXPERT, {(void*)opt_qscale}, "use fixed video quantiser scale (VBR)", "q" },
#ifdef CONFIG_GRAB
{ "vd", HAS_ARG | OPT_EXPERT, {(void*)opt_video_device}, "set video device", "device" },
#endif
{ "vcodec", HAS_ARG | OPT_EXPERT, {(void*)opt_video_codec}, "force video codec", "codec" },
{ "me", HAS_ARG | OPT_EXPERT, {(void*)opt_motion_estimation}, "set motion estimation method",
"use same video quality as source (implies VBR)" },
/* audio options */
{ "ab", HAS_ARG, {(void*)opt_audio_bitrate}, "set audio bitrate (in kbit/s)", "bitrate", },
{ "ar", HAS_ARG, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" },
{ "ac", HAS_ARG, {(void*)opt_audio_channels}, "set number of audio channels", "channels" },
{ "an", OPT_BOOL, {(void*)&audio_disable}, "disable audio" },
#ifdef CONFIG_GRAB
{ "ad", HAS_ARG | OPT_EXPERT, {(void*)opt_audio_device}, "set audio device", "device" },
#endif
{ "acodec", HAS_ARG | OPT_EXPERT, {(void*)opt_audio_codec}, "force audio codec", "codec" },
{ "deinterlace", OPT_BOOL | OPT_EXPERT, {(void*)&do_deinterlace},
"deinterlace pictures" },
{ "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark},
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
{ NULL, },
};
int main(int argc, char **argv)
{
int optindex, i;
const char *opt, *arg;
const OptionDef *po;
register_all();
if (argc <= 1)
show_help();
optindex = 1;
while (optindex < argc) {
opt = argv[optindex++];
if (opt[0] == '-' && opt[1] != '\0') {
po = options;
while (po->name != NULL) {
if (!strcmp(opt + 1, po->name))
break;
po++;
}
if (!po->name) {
fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt);
exit(1);
}
arg = NULL;
if (po->flags & HAS_ARG)
arg = argv[optindex++];
if (po->flags & OPT_STRING) {
char *str;
str = strdup(arg);
*po->u.str_arg = str;
} else if (po->flags & OPT_BOOL) {
*po->u.int_arg = 1;
} else {
po->u.func_arg(arg);
}
} else {
opt_output_file(opt);
}
}
if (nb_input_files == 0) {
if (nb_output_files != 1) {
fprintf(stderr, "Only one output file supported when grabbing\n");
exit(1);
}
av_grab(output_files[0]);
#else
fprintf(stderr, "Must supply at least one input file\n");
#endif
if (nb_output_files <= 0) {
fprintf(stderr, "Must supply at least one output file\n");
exit(1);
}
av_encode(output_files, nb_output_files, input_files, nb_input_files,
stream_maps, nb_stream_maps);
ti = getutime() - ti;
if (do_benchmark) {
printf("bench: utime=%0.3fs\n", ti / 1000000.0);
}
}
/* close files */
for(i=0;i<nb_output_files;i++) {
if (!(output_files[i]->format->flags & AVFMT_NOFILE))
url_fclose(&output_files[i]->pb);
}
for(i=0;i<nb_input_files;i++) {
if (!(input_files[i]->format->flags & AVFMT_NOFILE))
url_fclose(&input_files[i]->pb);
}
return 0;
}