55 #if HAVE_SYS_RESOURCE_H
56 #include <sys/types.h>
58 #include <sys/resource.h>
59 #elif HAVE_GETPROCESSTIMES
62 #if HAVE_GETPROCESSMEMORYINFO
68 #include <sys/select.h>
104 #define MAX_FILES 100
136 static int max_frames[4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX};
156 static char *vfilters =
NULL;
161 #define QSCALE_NONE -99999
239 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
353 snprintf(args, 255,
"%d:%d:%d:%d:%d:%d:%d", ist->
st->
codec->
width,
355 sample_aspect_ratio.
num, sample_aspect_ratio.
den);
358 "src", args,
NULL, ost->graph);
362 "out",
NULL, &avsink_ctx, ost->graph);
365 last_filter = ost->input_video_filter;
368 snprintf(args, 255,
"%d:%d:flags=0x%X",
380 snprintf(args,
sizeof(args),
"flags=0x%X", ost->
sws_flags);
381 ost->graph->scale_sws_opts =
av_strdup(args);
393 inputs->
filter_ctx = ost->output_video_filter;
401 if ((ret =
avfilter_link(last_filter, 0, ost->output_video_filter, 0)) < 0)
408 codec->
width = ost->output_video_filter->inputs[0]->w;
409 codec->
height = ost->output_video_filter->inputs[0]->h;
413 ost->output_video_filter->inputs[0]->sample_aspect_ratio;
459 av_free(output_streams_for_file[i]);
463 av_close_input_file(input_files[i].ctx);
500 "Received signal %d: terminating.\n",
519 const char *codec_string = encoder ?
"encoder" :
"decoder";
524 "results.\nAdd '-strict experimental' if you want to use it.\n",
529 codec_string, codec->
name);
544 "Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n",
574 int min_dec = -1, min_inc = -1;
598 int best_dist=INT_MAX;
601 if(dist < best_dist){
631 "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
651 output_streams_for_file[file_idx] =
653 sizeof(*output_streams_for_file[file_idx]),
656 ost = output_streams_for_file[file_idx][idx] =
659 fprintf(stderr,
"Could not alloc output stream\n");
711 av_close_input_file(ic);
735 fprintf(stderr,
"%s failed for stream %d, codec %s",
754 #define MAX_AUDIO_PACKET_SIZE (128 * 1024)
759 unsigned char *buf,
int size)
762 int64_t audio_out_size, audio_buf_size;
763 int64_t allocated_for_size=
size;
765 int size_out, frame_bytes, ret, resample_changed;
773 audio_buf_size= (allocated_for_size + isize*dec->
channels - 1) / (isize*dec->
channels);
775 audio_buf_size= audio_buf_size*2 + 10000;
777 audio_buf_size*= osize*enc->
channels;
780 if(coded_bps > 8*osize)
781 audio_out_size= audio_out_size * coded_bps / (8*osize);
784 if(audio_out_size > INT_MAX || audio_buf_size > INT_MAX){
785 fprintf(stderr,
"Buffer sizes too large\n");
792 fprintf(stderr,
"Out of memory in do_audio_out\n");
804 if (resample_changed) {
805 av_log(
NULL,
AV_LOG_INFO,
"Input stream #%d.%d frame changed from rate:%d fmt:%s ch:%d to rate:%d fmt:%s ch:%d\n",
824 fprintf(stderr,
"Warning, using s16 intermediate sample format for resampling\n");
830 fprintf(stderr,
"Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n",
838 #define MAKE_SFMT_PAIR(a,b) ((a)+AV_SAMPLE_FMT_NB*(b))
846 fprintf(stderr,
"Cannot convert %s sample format to %s sample format\n",
858 int byte_delta= ((int)idelta)*2*dec->
channels;
861 if(fabs(delta) > 50){
864 byte_delta=
FFMAX(byte_delta, -size);
868 fprintf(stderr,
"discarding %d audio samples\n", (
int)-delta);
873 static uint8_t *input_tmp=
NULL;
874 input_tmp=
av_realloc(input_tmp, byte_delta + size);
876 if(byte_delta > allocated_for_size - size){
877 allocated_for_size= byte_delta + (int64_t)size;
882 memset(input_tmp, 0, byte_delta);
883 memcpy(input_tmp + byte_delta, buf, size);
887 fprintf(stderr,
"adding %d audio samples of silence\n", (
int)delta);
893 fprintf(stderr,
"compensating audio timestamp drift:%f compensation:%d in:%d\n", delta, comp, enc->
sample_rate);
905 (
short *)buftmp, (
short *)buf,
907 size_out = size_out * enc->
channels * osize;
914 const void *ibuf[6]= {buftmp};
916 int istride[6]= {isize};
917 int ostride[6]= {osize};
918 int len= size_out/istride[0];
920 printf(
"av_audio_convert() failed\n");
926 size_out = len*osize;
933 fprintf(stderr,
"av_fifo_realloc2() failed\n");
948 ret = avcodec_encode_audio(enc,
audio_out, audio_out_size,
951 fprintf(stderr,
"Audio encoding failed\n");
975 size_out = size_out*coded_bps/8;
977 if(size_out > audio_out_size){
978 fprintf(stderr,
"Internal error, buffer size too small\n");
983 ret = avcodec_encode_audio(enc,
audio_out, size_out,
986 fprintf(stderr,
"Audio encoding failed\n");
1019 picture2 = &picture_tmp;
1025 fprintf(stderr,
"Deinterlacing failed\n");
1034 if (picture != picture2)
1035 *picture = *picture2;
1040 #define AV_DELAY_MAX 0.100
1048 static uint8_t *subtitle_out =
NULL;
1049 int subtitle_out_max_size = 1024 * 1024;
1050 int subtitle_out_size, nb, i;
1055 fprintf(stderr,
"Subtitle packets must have a pts\n");
1063 if (!subtitle_out) {
1064 subtitle_out =
av_malloc(subtitle_out_max_size);
1075 for(i = 0; i < nb; i++) {
1082 subtitle_out_max_size, sub);
1083 if (subtitle_out_size < 0) {
1084 fprintf(stderr,
"Subtitle encoding failed\n");
1090 pkt.
data = subtitle_out;
1091 pkt.
size = subtitle_out_size;
1112 int *frame_size,
float quality)
1114 int nb_frames, i, ret, resample_changed;
1115 AVFrame *final_picture, *formatted_picture;
1130 double vdelta = sync_ipts - ost->
sync_opts;
1137 }
else if(vdelta>0.6)
1139 }
else if (vdelta > 1.1)
1140 nb_frames =
lrintf(vdelta);
1142 if (nb_frames == 0){
1145 fprintf(stderr,
"*** drop!\n");
1146 }
else if (nb_frames > 1) {
1149 fprintf(stderr,
"*** %d dup!\n", nb_frames-1);
1158 formatted_picture = in_picture;
1159 final_picture = formatted_picture;
1165 if (resample_changed) {
1167 "Input stream #%d.%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
1175 #if !CONFIG_AVFILTER
1178 if (resample_changed) {
1190 fprintf(stderr,
"Cannot get resampling context\n");
1200 for(i=0;i<nb_frames;i++) {
1211 pkt.
data= (uint8_t *)final_picture;
1221 big_picture= *final_picture;
1234 big_picture.
quality = quality;
1250 fprintf(stderr,
"Video encoding failed\n");
1282 return -10.0*log(d)/log(10.0);
1290 double ti1, bitrate, avg_bitrate;
1315 avg_bitrate = (double)(
video_size * 8) / ti1 / 1000.0;
1316 fprintf(
vstats_file,
"s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
1317 (
double)
video_size / 1024, ti1, bitrate, avg_bitrate);
1331 int frame_number, vid, i;
1332 double bitrate, ti1, pts;
1333 static int64_t last_time = -1;
1334 static int qp_histogram[52];
1336 if (!is_last_report) {
1340 if (last_time == -1) {
1344 if ((cur_time - last_time) < 500000)
1350 oc = output_files[0];
1359 for(i=0;i<nb_ostreams;i++) {
1366 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"q=%2.1f ", q);
1372 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"frame=%5d fps=%3d q=%3.1f ",
1373 frame_number, (t>1)?(
int)(frame_number/t+0.5) : 0, q);
1375 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"L");
1382 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%X", (
int)
lrintf(log(qp_histogram[j]+1)/log(2)));
1386 double error, error_sum=0;
1387 double scale, scale_sum=0;
1388 char type[3]= {
'Y',
'U',
'V'};
1389 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"PSNR=");
1392 error= enc->
error[j];
1393 scale= enc->
width*enc->
height*255.0*255.0*frame_number;
1401 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%c:%2.2f ", type[j],
psnr(error/scale));
1403 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"*:%2.2f ",
psnr(error_sum/scale_sum));
1409 if ((pts < ti1) && (pts > 0))
1415 if (
verbose > 0 || is_last_report) {
1416 bitrate = (double)(total_size * 8) / ti1 / 1000.0;
1418 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
1419 "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s",
1420 (
double)total_size / 1024, ti1, bitrate);
1423 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
" dup=%d drop=%d",
1427 fprintf(stderr,
"%s \r", buf);
1432 if (is_last_report &&
verbose >= 0){
1435 fprintf(stderr,
"video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n",
1439 100.0*(total_size - raw)/raw
1446 int fill_char = 0x00;
1449 memset(buf, fill_char, size);
1462 void *buffer_to_free =
NULL;
1463 static unsigned int samples_size= 0;
1467 int frame_available;
1493 while (avpkt.
size > 0 || (!pkt && got_output)) {
1494 uint8_t *data_buf, *decoded_data_buf;
1495 int data_size, decoded_data_size;
1506 decoded_data_buf =
NULL;
1507 decoded_data_size= 0;
1508 data_buf = avpkt.
data;
1509 data_size = avpkt.
size;
1510 subtitle_to_free =
NULL;
1514 if(pkt && samples_size <
FFMAX(pkt->
size*
sizeof(*
samples), AVCODEC_MAX_AUDIO_FRAME_SIZE)) {
1515 samples_size =
FFMAX(pkt->
size*
sizeof(*
samples), AVCODEC_MAX_AUDIO_FRAME_SIZE);
1519 decoded_data_size= samples_size;
1522 ret = avcodec_decode_audio3(ist->
st->
codec,
samples, &decoded_data_size,
1529 got_output = decoded_data_size > 0;
1536 decoded_data_buf = (uint8_t *)
samples;
1544 avpkt.
pts = pkt_pts;
1549 &picture, &got_output, &avpkt);
1555 goto discard_packet;
1565 buffer_to_free =
NULL;
1570 &subtitle, &got_output, &avpkt);
1574 goto discard_packet;
1576 subtitle_to_free = &subtitle;
1603 for (i = 0; i < nb_ostreams; i++) {
1605 if (ost->input_video_filter && ost->
source_index == ist_index) {
1625 for(i=0;i<(decoded_data_size /
sizeof(short));i++) {
1627 if (v < -32768) v = -32768;
1628 if (v > 32767) v = 32767;
1644 for(i=0;i<nb_ostreams;i++) {
1652 while (frame_available) {
1668 do_audio_out(os, ost, ist, decoded_data_buf, decoded_data_size);
1695 #if !CONFIG_AVFILTER
1725 opkt.
dts -= ost_tb_start_time;
1738 opkt.
data = data_buf;
1739 opkt.
size = data_size;
1760 if (subtitle_to_free) {
1762 subtitle_to_free =
NULL;
1769 for(i=0;i<nb_ostreams;i++) {
1792 if (fifo_bytes > 0) {
1815 fprintf(stderr,
"Audio encoding failed\n");
1824 fprintf(stderr,
"Video encoding failed\n");
1859 printf(
"SDP:\n%s\n", sdp);
1877 if (in_ch->
end < ts_off)
1886 out_ch->id = in_ch->
id;
1888 out_ch->start =
FFMAX(0, in_ch->
start - ts_off);
1889 out_ch->end =
FFMIN(rt, in_ch->
end - ts_off);
1910 for (p = kf; *p; p++)
1919 for (i = 0; i < n; i++) {
1920 p = i ? strchr(p,
',') + 1 : kf;
1935 int ret = 0, i, j, k, n, nb_ostreams = 0;
1943 int no_packet_count=0;
1952 os = output_files[i];
1954 av_dump_format(output_files[i], i, output_files[i]->filename, 1);
1955 fprintf(stderr,
"Output file #%d does not contain any stream\n", i);
1961 if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) {
1962 fprintf(stderr,
"Number of stream maps must match number of output streams\n");
1972 if (fi < 0 || fi > nb_input_files - 1 ||
1973 si < 0 || si > input_files[fi].nb_streams - 1) {
1974 fprintf(stderr,
"Could not find input stream #%d.%d\n", fi, si);
1980 if (fi < 0 || fi > nb_input_files - 1 ||
1981 si < 0 || si > input_files[fi].nb_streams - 1) {
1982 fprintf(stderr,
"Could not find sync stream #%d.%d\n", fi, si);
1993 os = output_files[k];
1996 ost = ost_table[n] = output_streams_for_file[k][i];
1997 if (nb_stream_maps > 0) {
2004 av_dump_format(output_files[i], i, output_files[i]->filename, 1);
2005 fprintf(stderr,
"Codec type mismatch for mapping #%d.%d -> #%d.%d\n",
2006 stream_maps[n].file_index, stream_maps[n].stream_index,
2012 int best_nb_frames=-1;
2017 ist = &input_streams[j];
2033 if(best_nb_frames < ist->st->codec_info_nb_frames){
2045 ist = &input_streams[j];
2055 av_dump_format(output_files[i], i, output_files[i]->filename, 1);
2056 fprintf(stderr,
"Could not find input stream matching output stream #%d.%d\n",
2064 ost->
sync_ist = (nb_stream_maps > 0) ?
2065 &input_streams[input_files[stream_maps[n].sync_file_index].ist_index +
2066 stream_maps[n].sync_stream_index] : ist;
2071 for(i=0;i<nb_ostreams;i++) {
2087 if (ost->
st->stream_copy) {
2090 if (extra_size > INT_MAX)
2122 fprintf(stderr,
"-acodec copy and -vol are incompatible (frames are not decoded)\n");
2183 icodec->request_channels = codec->
channels;
2196 fprintf(stderr,
"Video pixel format is unknown, stream cannot be encoded\n");
2209 #if !CONFIG_AVFILTER
2213 fprintf(stderr,
"Cannot allocate temp picture, check pix fmt\n");
2225 fprintf(stderr,
"Cannot get resampling context\n");
2247 if (configure_video_filters(ist, ost)) {
2248 fprintf(stderr,
"Error opening filters!\n");
2267 snprintf(logfilename,
sizeof(logfilename),
"%s-%d.log",
2271 f = fopen(logfilename,
"wb");
2273 fprintf(stderr,
"Cannot write log file '%s' for pass-1 encoding: %s\n", logfilename, strerror(errno));
2279 size_t logbuffer_size;
2281 fprintf(stderr,
"Error reading log file '%s' for pass-2 encoding\n", logfilename);
2297 fprintf(stderr,
"Cannot allocate %d bytes output buffer\n",
2304 for(i=0;i<nb_ostreams;i++) {
2310 snprintf(error,
sizeof(error),
"Encoder (codec id %d) not found for output stream #%d.%d",
2325 snprintf(error,
sizeof(error),
"Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height",
2334 "It takes bits/s as argument, not kbits/s\n");
2341 ist = &input_streams[i];
2347 snprintf(error,
sizeof(error),
"Decoder (codec id %d) not found for input stream #%d.%d",
2355 for (j = 0; j < nb_ostreams; j++) {
2364 snprintf(error,
sizeof(error),
"Error while opening decoder for input stream #%d.%d",
2377 ist = &input_streams[i];
2391 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
2392 if ((index) < 0 || (index) >= (nb_elems)) {\
2393 snprintf(error, sizeof(error), "Invalid %s index %d while processing metadata maps\n",\
2395 ret = AVERROR(EINVAL);\
2401 if (in_file_index < 0 || out_file_index < 0)
2406 files[0] = output_files[out_file_index];
2407 files[1] = input_files[in_file_index].
ctx;
2409 for (j = 0; j < 2; j++) {
2412 switch (map->
type) {
2438 av_dict_copy(&output_files[i]->metadata, input_files[0].ctx->metadata,
2444 int infile = chapter_maps[i].
in_file;
2447 if (infile < 0 || outfile < 0)
2449 if (infile >= nb_input_files) {
2450 snprintf(error,
sizeof(error),
"Invalid input file index %d in chapter mapping.\n", infile);
2454 if (outfile >= nb_output_files) {
2455 snprintf(error,
sizeof(error),
"Invalid output file index %d in chapter mapping.\n",outfile);
2463 if (!nb_chapter_maps)
2465 if (!input_files[i].ctx->nb_chapters)
2476 os = output_files[i];
2478 snprintf(error,
sizeof(error),
"Could not write header for output file #%d (incorrect codec parameters ?)", i);
2483 if (strcmp(output_files[i]->oformat->name,
"rtp")) {
2492 av_dump_format(output_files[i], i, output_files[i]->filename, 1);
2497 fprintf(stderr,
"Stream mapping:\n");
2498 for(i=0;i<nb_ostreams;i++) {
2500 fprintf(stderr,
" Stream #%d.%d -> #%d.%d",
2506 fprintf(stderr,
" [sync #%d.%d]",
2514 fprintf(stderr,
"%s\n", error);
2519 print_sdp(output_files, nb_output_files);
2523 fprintf(stderr,
"Press ctrl-c to stop encoding\n");
2529 int file_index, ist_index;
2541 for(i=0;i<nb_ostreams;i++) {
2549 ipts = (double)ist->
pts;
2551 if(ipts < ipts_min) {
2555 if(opts < opts_min) {
2566 if (file_index < 0) {
2567 if(no_packet_count){
2569 memset(no_packet, 0,
sizeof(no_packet));
2581 is = input_files[file_index].
ctx;
2584 no_packet[file_index]=1;
2597 memset(no_packet, 0,
sizeof(no_packet));
2606 goto discard_packet;
2608 ist = &input_streams[ist_index];
2610 goto discard_packet;
2632 fprintf(stderr,
"timestamp discontinuity %"PRId64
", new offset= %"PRId64
"\n",
2644 goto discard_packet;
2648 if (
output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) {
2651 fprintf(stderr,
"Error while decoding stream #%d.%d\n",
2668 ist = &input_streams[i];
2669 if (ist->decoding_needed) {
2678 os = output_files[i];
2686 for(i=0;i<nb_ostreams;i++) {
2688 if (ost->encoding_needed) {
2689 av_freep(&ost->st->codec->stats_in);
2699 ist = &input_streams[i];
2700 if (ist->decoding_needed) {
2712 for(i=0;i<nb_ostreams;i++) {
2715 if (ost->st->stream_copy)
2716 av_freep(&ost->st->codec->extradata);
2718 fclose(ost->logfile);
2719 ost->logfile =
NULL;
2723 av_freep(&ost->st->codec->subtitle_header);
2724 av_free(ost->pict_tmp.data[0]);
2726 if (ost->video_resample)
2730 if (ost->reformat_ctx)
2768 fprintf(stderr,
"Incorrect value for %s: %s\n", opt, arg);
2776 fprintf(stderr,
"Option '%s' has been removed, use the crop filter instead\n", opt);
2783 fprintf(stderr,
"Incorrect frame size\n");
2789 static int opt_pad(
const char *opt,
const char *arg) {
2790 fprintf(stderr,
"Option '%s' has been removed, use the pad filter instead\n", opt);
2796 if (strcmp(arg,
"list")) {
2799 fprintf(stderr,
"Unknown pixel format requested: %s\n", arg);
2816 p = strchr(arg,
':');
2818 x = strtol(arg, &end, 10);
2820 y = strtol(end+1, &end, 10);
2822 ar = (double)x / (
double)y;
2824 ar = strtod(arg,
NULL);
2827 fprintf(stderr,
"Incorrect aspect ratio specification.\n");
2836 char *mid= strchr(arg,
'=');
2839 fprintf(stderr,
"Missing =\n");
2853 fprintf(stderr,
"qscale must be > 0.0 and <= 255\n");
2870 fprintf(stderr,
"Warning: not compiled with thread support, using thread emulation\n");
2877 if (strcmp(arg,
"list")) {
2923 if (!strcmp(arg,
"copy")) {
2954 uint32_t *codec_tag;
2962 *codec_tag = strtol(arg, &tail, 0);
2969 static int opt_map(
const char *opt,
const char *arg)
3006 *index = strtol(++arg, endptr, 0);
3009 fprintf(stderr,
"Invalid metadata type %c.\n", *arg);
3025 m->
file = strtol(arg, &p, 0);
3031 m1->
file = strtol(p, &p, 0);
3034 if (m->
type ==
'g' || m1->
type ==
'g')
3036 if (m->
type ==
's' || m1->
type ==
's')
3038 if (m->
type ==
'c' || m1->
type ==
'c')
3046 fprintf(stderr,
"-map_meta_data is deprecated and will be removed soon. "
3047 "Use -map_metadata instead.\n");
3063 c->
in_file = strtol(p, &p, 0);
3069 unsigned int stream;
3073 stream = strtol(arg, &p, 0);
3076 scale= strtod(p, &p);
3099 struct tm time = *gmtime((time_t*)&recording_timestamp);
3100 strftime(buf,
sizeof(buf),
"creation_time=%FT%T%z", &time);
3104 "tag instead.\n", opt);
3116 const char *codec_string = encoder ?
"encoder" :
"decoder";
3125 fprintf(stderr,
"Unknown %s '%s'\n", codec_string, name);
3128 if(codec->
type != type) {
3129 fprintf(stderr,
"Invalid %s type '%s'\n", codec_string, name);
3139 int err, i, ret, rfps, rfps_base;
3143 int orig_nb_streams;
3153 if (!strcmp(filename,
"-"))
3157 !strcmp(filename,
"/dev/stdin");
3173 if (frame_rate.
num) {
3174 snprintf(buf,
sizeof(buf),
"%d/%d", frame_rate.
num, frame_rate.
den);
3218 fprintf(stderr,
"Specified program id not found\n");
3236 if (ret < 0 && verbose >= 0) {
3237 fprintf(stderr,
"%s: could not find codec parameters\n", filename);
3238 av_close_input_file(ic);
3251 fprintf(stderr,
"%s: could not seek to position %0.3f\n",
3266 input_streams =
grow_array(input_streams,
sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1);
3267 ist = &input_streams[nb_input_streams - 1];
3297 fprintf(stderr,
"\nSeems stream %d codec frame rate differs from container frame rate: %2.2f (%d/%d) -> %2.2f (%d/%d)\n",
3300 (
float)rfps / rfps_base, rfps, rfps_base);
3343 for (i = 0; i < orig_nb_streams; i++)
3356 int *has_subtitle_ptr,
3359 int has_video, has_audio, has_subtitle, has_data, i, j;
3368 ic = input_files[j].
ctx;
3391 *has_video_ptr = has_video;
3392 *has_audio_ptr = has_audio;
3393 *has_subtitle_ptr = has_subtitle;
3394 *has_data_ptr = has_data;
3421 ost->avfilter= vfilters;
3427 video_bitstream_filters=
NULL;
3431 video_enc = st->
codec;
3442 st->stream_copy = 1;
3473 int e=sscanf(p,
"%d,%d,%d", &start, &end, &q);
3475 fprintf(stderr,
"error parsing rc_override\n");
3549 audio_bitstream_filters=
NULL;
3553 audio_enc = st->
codec;
3563 st->stream_copy = 1;
3597 data_enc = st->
codec;
3599 fprintf(stderr,
"Data stream encoding not supported yet (only streamcopy)\n");
3612 st->stream_copy = 1;
3639 subtitle_enc = st->
codec;
3642 subtitle_bitstream_filters=
NULL;
3653 st->stream_copy = 1;
3671 int file_idx = nb_output_files - 1;
3672 if (nb_output_files <= 0) {
3673 fprintf(stderr,
"At least one output file must be specified\n");
3676 oc = output_files[file_idx];
3694 p = strchr(idx_str,
':');
3697 "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
3711 int err, use_video, use_audio, use_subtitle, use_data;
3712 int input_has_video, input_has_audio, input_has_subtitle, input_has_data;
3715 if (!strcmp(filename,
"-"))
3726 if (!file_oformat) {
3733 if (!file_oformat) {
3734 fprintf(stderr,
"Unable to find a suitable output format for '%s'\n",
3743 if (!strcmp(file_oformat->
name,
"ffm") &&
3761 &input_has_subtitle,
3764 if (!input_has_video)
3766 if (!input_has_audio)
3768 if (!input_has_subtitle)
3770 if (!input_has_data)
3789 output_files[nb_output_files++] = oc;
3802 (strchr(filename,
':') ==
NULL ||
3803 filename[1] ==
':' ||
3807 fprintf(stderr,
"File '%s' already exists. Overwrite ? [y/N] ", filename);
3810 fprintf(stderr,
"Not overwriting - exiting\n");
3815 fprintf(stderr,
"File '%s' already exists. Exiting.\n", filename);
3858 struct rusage rusage;
3860 getrusage(RUSAGE_SELF, &rusage);
3861 return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
3862 #elif HAVE_GETPROCESSTIMES
3864 FILETIME c, e, k, u;
3865 proc = GetCurrentProcess();
3866 GetProcessTimes(proc, &c, &e, &k, &u);
3867 return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
3875 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
3876 struct rusage rusage;
3877 getrusage(RUSAGE_SELF, &rusage);
3878 return (int64_t)rusage.ru_maxrss * 1024;
3879 #elif HAVE_GETPROCESSMEMORYINFO
3881 PROCESS_MEMORY_COUNTERS memcounters;
3882 proc = GetCurrentProcess();
3883 memcounters.cb =
sizeof(memcounters);
3884 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
3885 return memcounters.PeakPagefileUsage;
3894 const char *p = str;
3901 fprintf(stderr,
"Syntax error in matrix \"%s\" at coeff %d\n", str, i);
3922 printf(
"Hyper fast Audio and Video encoder\n");
3923 printf(
"usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...\n");
3999 enum {
PAL,
NTSC, FILM, UNKNOWN } norm = UNKNOWN;
4000 static const char *
const frame_rates[] = {
"25",
"30000/1001",
"24000/1001"};
4002 if(!strncmp(arg,
"pal-", 4)) {
4005 }
else if(!strncmp(arg,
"ntsc-", 5)) {
4008 }
else if(!strncmp(arg,
"film-", 5)) {
4014 fr = (int)(frame_rate.
num * 1000.0 / frame_rate.
den);
4017 }
else if((fr == 29970) || (fr == 23976)) {
4032 }
else if((fr == 29970) || (fr == 23976)) {
4042 if(
verbose > 0 && norm != UNKNOWN)
4043 fprintf(stderr,
"Assuming %s for target.\n", norm ==
PAL ?
"PAL" :
"NTSC");
4046 if(norm == UNKNOWN) {
4047 fprintf(stderr,
"Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
4048 fprintf(stderr,
"Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
4049 fprintf(stderr,
"or set a framerate with \"-r xxx\".\n");
4053 if(!strcmp(arg,
"vcd")) {
4080 }
else if(!strcmp(arg,
"svcd")) {
4102 }
else if(!strcmp(arg,
"dvd")) {
4123 }
else if(!strncmp(arg,
"dv", 2)) {
4129 norm ==
PAL ?
"yuv420p" :
"yuv411p");
4136 fprintf(stderr,
"Unknown target: %s\n", arg);
4153 struct tm *today = localtime(&today2);
4155 snprintf(filename,
sizeof(filename),
"vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
4160 static int opt_bsf(
const char *opt,
const char *arg)
4166 fprintf(stderr,
"Unknown bitstream filter %s\n", arg);
4170 bsfp= *opt ==
'v' ? &video_bitstream_filters :
4171 *opt ==
'a' ? &audio_bitstream_filters :
4174 bsfp= &(*bsfp)->
next;
4184 char filename[1000], tmp[1000], tmp2[1000],
line[1000];
4189 if (!(f =
get_preset_file(filename,
sizeof(filename), arg, *opt ==
'f', codec_name))) {
4190 fprintf(stderr,
"File for preset '%s' not found\n", arg);
4195 int e= fscanf(f,
"%999[^\n]\n", line) - 1;
4196 if(line[0] ==
'#' && !e)
4198 e|= sscanf(line,
"%999[^=]=%999[^\n]\n", tmp, tmp2) - 2;
4200 fprintf(stderr,
"%s: Invalid syntax: '%s'\n", filename, line);
4203 if(!strcmp(tmp,
"acodec")){
4205 }
else if(!strcmp(tmp,
"vcodec")){
4207 }
else if(!strcmp(tmp,
"scodec")){
4209 }
else if(!strcmp(tmp,
"dcodec")){
4212 fprintf(stderr,
"%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2);
4228 {
"map",
HAS_ARG |
OPT_EXPERT, {(
void*)
opt_map},
"set input stream mapping",
"file.stream[:syncfile.syncstream]" },
4230 "outfile[,metadata]:infile[,metadata]" },
4232 "outfile[,metadata]:infile[,metadata]" },
4243 "add timings for benchmarking" },
4246 "dump each input packet" },
4248 "when dumping packets, also dump the payload" },
4253 {
"target",
HAS_ARG, {(
void*)
opt_target},
"specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)",
"type" },
4289 "use same quantizer as source (implies VBR)" },
4293 "deinterlace pictures" },
4298 {
"vf",
OPT_STRING |
HAS_ARG, {(
void*)&vfilters},
"video filters",
"filter list" },
4380 "The ffmpeg program is only provided for script compatibility and will be removed\n"
4381 "in a future release. It has been deprecated in the Libav project to allow for\n"
4382 "incompatible command line syntax improvements in its replacement called avconv\n"
4383 "(see Changelog for details). Please use avconv instead.\n");
4390 fprintf(stderr,
"Use -h to get full help or, even better, run 'man ffmpeg'\n");
4395 if (nb_output_files <= 0) {
4396 fprintf(stderr,
"At least one output file must be specified\n");
4401 fprintf(stderr,
"At least one input file must be specified\n");
4412 printf(
"bench: utime=%0.3fs maxrss=%ikB\n", ti / 1000000.0, maxrss);