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];
2678 os = output_files[i];
2686 for(i=0;i<nb_ostreams;i++) {
2699 ist = &input_streams[i];
2712 for(i=0;i<nb_ostreams;i++) {
2715 if (ost->
st->stream_copy)
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",
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;
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");
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);
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
int avio_open(AVIOContext **s, const char *url, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
static const char * video_rc_override_string
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
static int decode_interrupt_cb(void)
Number of sample formats. DO NOT USE if linking dynamically.
static int opt_me_threshold(const char *opt, const char *arg)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void assert_codec_experimental(AVCodecContext *c, int encoder)
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
void avcodec_register_all(void)
Register all the codecs, parsers and bitstream filters which were enabled at configuration time...
int64_t avio_size(AVIOContext *s)
Get the filesize.
static int opt_frame_aspect_ratio(const char *opt, const char *arg)
void avfilter_register_all(void)
Initialize the filter system.
static int opt_data_codec(const char *opt, const char *arg)
static int metadata_chapters_autocopy
static OutputStream * new_output_stream(AVFormatContext *oc, int file_idx, AVCodec *codec)
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
AVAudioConvert * reformat_ctx
int av_fifo_size(AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
uint64_t error[AV_NUM_DATA_POINTERS]
error
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
AVCodec * avcodec_find_encoder(enum CodecID id)
Find a registered encoder with a matching codec ID.
#define CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
static AVBitStreamFilterContext * video_bitstream_filters
int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
static void term_init(void)
static int opt_vstats_file(const char *opt, const char *arg)
static void print_report(AVFormatContext **output_files, OutputStream **ost_table, int nb_ostreams, int is_last_report)
enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, const char *filename, const char *mime_type, enum AVMediaType type)
Guess the codec ID based upon muxer and filename.
int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
static void new_data_stream(AVFormatContext *oc, int file_idx)
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
AVFrame * coded_frame
the picture in the bitstream
static int64_t timer_start
static char * subtitle_language
void show_banner(void)
Print the program banner to stderr.
int avpicture_deinterlace(AVPicture *dst, const AVPicture *src, enum PixelFormat pix_fmt, int width, int height)
static uint8_t * audio_buf
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
#define AV_LOG_WARNING
Something somehow does not look correct.
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
static unsigned int video_codec_tag
static int64_t audio_size
#define MAKE_SFMT_PAIR(a, b)
int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Scale the image slice in srcSlice and put the resulting scaled slice in the image in dst...
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
int index
stream index in AVFormatContext
static int copy_initial_nonkeyframes
static int opt_pad(const char *opt, const char *arg)
static int64_t getmaxrss(void)
static float audio_qscale
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
static double get_sync_ipts(const OutputStream *ost)
#define AVIO_FLAG_WRITE
write-only
Various defines for YUV<->RGB conversion.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
AVCodec * avcodec_find_decoder(enum CodecID id)
Find a registered decoder with a matching codec ID.
enum AVMediaType codec_type
static char * video_language
static int opt_streamid(const char *opt, const char *arg)
static int opt_format(const char *opt, const char *arg)
static int transcode(AVFormatContext **output_files, int nb_output_files, InputFile *input_files, int nb_input_files, StreamMap *stream_maps, int nb_stream_maps)
static int copy_chapters(int infile, int outfile)
static char * pass_logfilename_prefix
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
void avdevice_register_all(void)
Initialize libavdevice and register all the input and output devices.
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
#define FF_ARRAY_ELEMS(a)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static void check_inputs(int *has_video_ptr, int *has_audio_ptr, int *has_subtitle_ptr, int *has_data_ptr)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
static int nb_input_streams
static float mux_max_delay
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
Resize an AVFifoBuffer.
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
four components are given, that's all.
int av_parser_change(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
enum CodecID video_codec_id
Forced video codec_id.
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
const AVClass * sws_get_class(void)
Get the AVClass for swsContext.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
void init_pts_correction(PtsCorrectionContext *ctx)
Reset the state of the PtsCorrectionContext.
int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)
static int opt_pass(const char *opt, const char *arg)
static int opt_codec_tag(const char *opt, const char *arg)
static int opt_map_metadata(const char *opt, const char *arg)
static int audio_channels
static AVInputFormat * file_iformat
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
static int file_overwrite
static void assert_avoptions(AVDictionary *m)
int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
unsigned int nb_stream_indexes
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
int avio_check(const char *url, int flags)
Return AVIO_FLAG_* access flags corresponding to the access permissions of the resource in url...
static int opt_audio_codec(const char *opt, const char *arg)
static void opt_inter_matrix(const char *arg)
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
void audio_resample_close(ReSampleContext *s)
Free resample context.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
#define DEFAULT_PASS_LOGFILENAME_PREFIX
static void opt_intra_matrix(const char *arg)
static int opt_recording_timestamp(const char *opt, const char *arg)
enum AVSampleFormat sample_fmt
audio sample format
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
Trivial log callback.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Opaque data information usually continuous.
miscellaneous OS support macros and functions.
int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
static int video_stream_copy
static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void **bufp)
int id
unique ID to identify the chapter
#define AV_LOG_SKIP_REPEATED
Skip repeated messages, this requires the user app to use av_log() instead of (f)printf as the 2 woul...
int64_t pts
presentation timestamp in time_base units (time when frame should be shown to user) If AV_NOPTS_VALUE...
static int nb_streamid_map
static double psnr(double d)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void show_help_options(const OptionDef *options, const char *msg, int mask, int value)
void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance)
Compensate samplerate/timestamp drift.
void init_opts(void)
Initialize the cmdutils option system, in particular allocate the *_opts contexts.
static int opt_audio_channels(const char *opt, const char *arg)
static int64_t getutime(void)
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
static void new_video_stream(AVFormatContext *oc, int file_idx)
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
static char * audio_language
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
static uint8_t * audio_out
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
static double av_q2d(AVRational a)
Convert rational to double.
struct InputStream * sync_ist
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *, const char *))
static void parse_forced_key_frames(char *kf, OutputStream *ost, AVCodecContext *avctx)
static void new_subtitle_stream(AVFormatContext *oc, int file_idx)
unsigned int av_codec_get_tag(const struct AVCodecTag *const *tags, enum CodecID id)
Get the codec tag for the given codec id id.
static int64_t recording_time
int avformat_network_init(void)
Do global initialization of network components.
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
void av_free_packet(AVPacket *pkt)
Free a packet.
static int nb_input_files
static int opt_frame_crop(const char *opt, const char *arg)
static int opt_video_rc_override_string(const char *opt, const char *arg)
int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size)
Generate an SDP for an RTP session.
static MetadataMap(* meta_data_maps)[2]
int interlaced_frame
The content of the picture is interlaced.
static int opt_qscale(const char *opt, const char *arg)
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
void av_destruct_packet(AVPacket *pkt)
Default packet destructor.
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the '-loglevel' option in the command line args and apply it.
external api for the swscale stuff
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
struct OutputStream OutputStream
static int opt_video_codec(const char *opt, const char *arg)
enum AVDiscard discard
selects which program to discard and which to feed to the caller
char * stats_out
pass1 encoding statistics output buffer
static int64_t input_ts_offset
int av_get_bits_per_sample(enum CodecID codec_id)
Return codec bits per sample.
int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height)
Calculate the size in bytes that a picture of the given width and height would occupy if stored in th...
static uint64_t limit_filesize
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static int subtitle_stream_copy
struct AVBitStreamFilterContext * next
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
unsigned int * stream_index
#define CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
static int opt_audio_sample_fmt(const char *opt, const char *arg)
struct AVOutputFormat * oformat
static unsigned int allocated_audio_out_size
static int top_field_first
static void choose_sample_rate(AVStream *st, AVCodec *codec)
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Setup AVCodecContext options for avformat_find_stream_info().
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
static unsigned int audio_codec_tag
AVDictionary * format_opts
static AVFormatContext * output_files[MAX_FILES]
preferred ID for MPEG-1/2 video decoding
audio conversion routines
void(* destruct)(struct AVPacket *)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static int bit_buffer_size
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Main libavdevice API header.
static char * data_codec_name
static int opt_input_ts_scale(const char *opt, const char *arg)
static int opt_target(const char *opt, const char *arg)
static int64_t start_time
int has_b_frames
Size of the frame reordering buffer in the decoder.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
int av_audio_convert(AVAudioConvert *ctx, void *const out[6], const int out_stride[6], const void *const in[6], const int in_stride[6], int len)
Convert between audio sample formats.
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
static char * subtitle_codec_name
#define CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
AVBitStreamFilterContext * bitstream_filters
static uint16_t * inter_matrix
enum AVSampleFormat request_sample_fmt
Used to request a sample format from the decoder.
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
struct SwsContext * sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat, int dstW, int dstH, enum PixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Allocate and return an SwsContext.
int capabilities
Codec capabilities.
static int audio_sync_method
static int audio_sample_rate
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
static int opt_bsf(const char *opt, const char *arg)
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
int rc_max_rate
maximum bitrate
simple assert() macros that are a bit more flexible than ISO C assert().
static int data_stream_copy
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
AVBitStreamFilterContext * av_bitstream_filter_init(const char *name)
static int video_sync_method
static AVDictionary * metadata
const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB]
The array of all the pixel format descriptors.
AVRational avg_frame_rate
Average framerate.
New fields can be added to the end with minor version bumps.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
static char logfilename[1024]
static int opt_frame_pix_fmt(const char *opt, const char *arg)
void avfilter_uninit(void)
Uninitialize the filter system.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int flags
A combination of AV_PKT_FLAG values.
uint64_t channel_layout
Audio channel layout.
#define CODEC_FLAG_EMU_EDGE
Don't draw edges.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare 2 timestamps each in its own timebases.
uint32_t end_display_time
int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t reordered_pts, int64_t dts)
Attempt to guess proper monotonic timestamps for decoded video frames which might have incorrect time...
int64_t pts
Same as packet pts, in AV_TIME_BASE.
AVCodecContext * codec
codec context
int rc_buffer_size
decoder bitstream buffer size
int intra_dc_precision
precision of the intra DC coefficient - 8
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static int opt_frame_rate(const char *opt, const char *arg)
int file_index
1 is this mapping is disabled by a negative map
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
unsigned int nb_streams
A list of all streams in the file.
static void parse_matrix_coeffs(uint16_t *dest, const char *str)
struct AVRational AVRational
rational number numerator/denominator
int avfilter_poll_frame(AVFilterLink *link)
Poll a frame from the filter chain.
static int nb_frames_drop
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
static float frame_aspect_ratio
static int nb_output_files
static void generate_silence(uint8_t *buf, enum AVSampleFormat sample_fmt, size_t size)
int bit_rate
the average bitrate
static int64_t video_size
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
static int opt_new_stream(const char *opt, const char *arg)
char filename[1024]
input or output filename
static int opt_map_meta_data(const char *opt, const char *arg)
static int opt_subtitle_codec(const char *opt, const char *arg)
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
#define AV_TIME_BASE
Internal time base represented as integer.
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
struct AVStream::@65 * info
static int opt_audio_rate(const char *opt, const char *arg)
static unsigned int subtitle_codec_tag
static int intra_dc_precision
int width
picture width / height.
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
Copy the settings of the source AVCodecContext into the destination AVCodecContext.
static int opt_video_channel(const char *opt, const char *arg)
enum CodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the CodecID for the given codec tag tag.
static int metadata_global_autocopy
const char * av_get_pix_fmt_name(enum PixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
static StreamMap * stream_maps
static float video_qscale
static av_always_inline av_const long int lrintf(float x)
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
static void do_audio_out(AVFormatContext *s, OutputStream *ost, InputStream *ist, unsigned char *buf, int size)
AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
#define METADATA_CHECK_INDEX(index, nb_elems, desc)
static void term_exit(void)
Usually treated as AVMEDIA_TYPE_DATA.
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Opaque data information usually sparse.
static void opt_output_file(void *optctx, const char *filename)
static void show_usage(void)
const char program_name[]
program name, defined by the program for show_version().
static ChapterMap * chapter_maps
void show_pix_fmts(void)
Print a listing containing all the pixel formats supported by the program.
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
static void update_sample_fmt(AVCodecContext *dec, AVCodec *dec_codec, AVCodecContext *enc)
Update the requested input sample format based on the output sample format.
struct InputStream InputStream
int av_find_nearest_q_idx(AVRational q, const AVRational *q_list)
Find the nearest value in q_list to q.
AVFilterContext * filter_ctx
filter context associated to this input/output
RcOverride * rc_override
ratecontrol override, see RcOverride
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
AVOutputFormat * av_oformat_next(AVOutputFormat *f)
If f is NULL, returns the first registered output format, if f is non-NULL, returns the next register...
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
void avfilter_unref_buffer(AVFilterBufferRef *ref)
Remove a reference to a buffer.
static int opt_recording_time(const char *opt, const char *arg)
A linked-list of the inputs/outputs of the filter chain.
int64_t end
chapter start/end time in time_base units
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
A reference to an AVFilterBuffer.
static void new_audio_stream(AVFormatContext *oc, int file_idx)
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
int frame_size
Samples per packet, initialized when calling 'init'.
enum CodecID audio_codec_id
Forced audio codec_id.
static int opt_preset(const char *opt, const char *arg)
uint64_t error[AV_NUM_DATA_POINTERS]
error
static char * video_codec_name
int opt_timelimit(const char *opt, const char *arg)
Limit the execution time.
enum AVMediaType codec_type
static int do_deinterlace
int me_threshold
Motion estimation threshold below which no motion estimation is performed, but instead the user speci...
const AVRational * supported_framerates
array of supported framerates, or NULL if any, array is terminated by {0,0}
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
char * av_strdup(const char *s)
Duplicate the string s.
AVDictionary * filter_codec_opts(AVDictionary *opts, enum CodecID codec_id, AVFormatContext *s, AVStream *st)
Filter out options for given codec.
static int64_t extra_size
int sample_rate
samples per second
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
static int opt_vstats(const char *opt, const char *arg)
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
Show the obj options.
void av_log_set_flags(int arg)
static int nb_output_streams_for_file[MAX_FILES]
static const char * last_asked_format
main external API structure.
char * av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt)
Generate a string corresponding to the sample format with sample_fmt, or a header if sample_fmt is ne...
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
#define CODEC_FLAG_QSCALE
Use fixed qscale.
int64_t av_get_int(void *obj, const char *name, const AVOption **o_out)
static enum AVSampleFormat audio_sample_fmt
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
struct AVPicture AVPicture
four components are given, that's all.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
a very simple circular buffer FIFO implementation
static int opt_top_field_first(const char *opt, const char *arg)
static int opt_thread_count(const char *opt, const char *arg)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Replacements for frequently missing libm functions.
struct AVBitStreamFilter * filter
uint16_t * intra_matrix
custom intra quantization matrix
static int opt_input_ts_offset(const char *opt, const char *arg)
static InputFile * input_files
FILE * get_preset_file(char *filename, size_t filename_size, const char *preset_name, int is_path, const char *codec_name)
Get a file corresponding to a preset file.
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
Create and add a filter instance into an existing graph.
int get_filtered_video_frame(AVFilterContext *sink, AVFrame *frame, AVFilterBufferRef **picref, AVRational *pts_tb)
Extract a frame from sink.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Describe the class of an AVClass context structure.
ReSampleContext * av_audio_resample_init(int output_channels, int input_channels, int output_rate, int input_rate, enum AVSampleFormat sample_fmt_out, enum AVSampleFormat sample_fmt_in, int filter_length, int log2_phase_count, int linear, double cutoff)
Initialize audio resampling context.
#define CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec)
Set the fields of the given AVCodecContext to default values corresponding to the given codec (defaul...
static void do_video_out(AVFormatContext *s, OutputStream *ost, InputStream *ist, AVFrame *in_picture, int *frame_size, float quality)
int pad_idx
index of the filt_ctx pad to use for linking
#define FF_MIN_BUFFER_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
rational number numerator/denominator
enum CodecID subtitle_codec_id
Forced subtitle codec_id.
int avpicture_fill(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt, int width, int height)
Fill in the AVPicture fields.
struct ChapterMap ChapterMap
static float audio_drift_threshold
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
Parse a string specifying a time and return its corresponding value as a number of microseconds...
static int opt_map_chapters(const char *opt, const char *arg)
void * grow_array(void *array, int elem_size, int *size, int new_size)
Realloc array to hold new_size elements of elem_size.
static void do_subtitle_out(AVFormatContext *s, OutputStream *ost, InputStream *ist, AVSubtitle *sub, int64_t pts)
struct SwsContext * sws_opts
static int opt_map(const char *opt, const char *arg)
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static int audio_stream_copy
int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVFrame *pict)
Encode a video frame from pict into buf.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
static int opt_metadata(const char *opt, const char *arg)
struct SwsContext * img_resample_ctx
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
static unsigned int data_codec_tag
static int nb_meta_data_maps
uint16_t * inter_matrix
custom inter quantization matrix
int64_t pkt_pts
reordered pts from the last AVPacket that has been input into the decoder
double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
Parse a string and return its corresponding value as a double.
char * name
unique name for this input/output in the list
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
static volatile int received_nb_signals
static enum PixelFormat frame_pix_fmt
int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
Read the file with name filename, and put its content in a newly allocated 0-terminated buffer...
int global_quality
Global quality for codecs which cannot change it per frame.
#define CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
static AVDictionary * output_opts[MAX_FILES]
static const uint16_t scale[4]
discard useless packets like 0 size packets in avi
int64_t start_time
Decoding: position of the first frame of the component, in AV_TIME_BASE fractional seconds...
const AVClass * priv_class
AVClass for the private context.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int opt_frame_size(const char *opt, const char *arg)
enum PixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
static void print_sdp(AVFormatContext **avc, int n)
#define CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
static int read_avserver_streams(AVFormatContext *s, const char *filename)
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
static void choose_pixel_fmt(AVStream *st, AVCodec *codec)
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Audio format conversion routines.
int64_t pkt_dts
dts from the last AVPacket that has been input into the decoder
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
void print_error(const char *filename, int err)
Print an error message to stderr, indicating filename and a human readable description of the error c...
static int subtitle_disable
static uint8_t * bit_buffer
AVDictionary * codec_opts
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int main(int argc, char **argv)
static char * audio_codec_name
AVAudioConvert * av_audio_convert_alloc(enum AVSampleFormat out_fmt, int out_channels, enum AVSampleFormat in_fmt, int in_channels, const float *matrix, int flags)
Create an audio sample format converter context.
static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc)
static AVInputFormat * iformat
int avpicture_alloc(AVPicture *picture, enum PixelFormat pix_fmt, int width, int height)
Allocate memory for a picture.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
static int nb_stream_maps
struct StreamMap StreamMap
int disposition
AV_DISPOSITION_* bit field.
uint32_t start_display_time
static float dts_delta_threshold
AVSampleFormat
all in native-endian format
static char * forced_key_frames
static void show_help(void)
AVRational time_base
time base in which the start/end timestamps are specified
AVCodec * av_codec_next(AVCodec *c)
If c is NULL, returns the first registered codec, if c is non-NULL, returns the next registered codec...
static FILE * vstats_file
static int nb_chapter_maps
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents...
static AVBitStreamFilterContext * audio_bitstream_filters
struct AVInputFormat * iformat
Can only be iformat or oformat, not both at the same time.
AVInputFormat * av_iformat_next(AVInputFormat *f)
If f is NULL, returns the first registered input format, if f is non-NULL, returns the next registere...
CodecID
Identify the syntax and semantics of the bitstream.
static AVRational frame_rate
memory buffer source API for video
static void parse_meta_type(char *arg, char *type, int *index, char **endptr)
int top_field_first
If the content is interlaced, is top field displayed first.
static AVBitStreamFilterContext * subtitle_bitstream_filters
struct AVFrac pts
encoding: pts generation when outputting stream
int channels
number of audio channels
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0 ...
struct AVCodecParserContext * parser
int codec_info_nb_frames
Number of frames that have been demuxed during av_find_stream_info()
static InputStream * input_streams
static OutputStream ** output_streams_for_file[MAX_FILES]
static int output_packet(InputStream *ist, int ist_index, OutputStream **ost_table, int nb_ostreams, const AVPacket *pkt)
int key_frame
1 -> keyframe, 0-> not
static enum CodecID find_codec_or_die(const char *name, int type, int encoder)
int opt_default(const char *opt, const char *arg)
Fallback for options that are not explicitly handled, these will be parsed through AVOptions...
static unsigned int allocated_audio_buf_size
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int64_t pts, AVRational pixel_aspect)
static int opt_video_standard(const char *opt, const char *arg)
static int opt_verbose(const char *opt, const char *arg)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static void choose_sample_fmt(AVStream *st, AVCodec *codec)
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
const int program_birth_year
program birth year, defined by the program for show_banner()
int frame_number
audio or video frame number
int repeat_pict
This field is used for proper frame duration computation in lavf.
struct InputFile InputFile
int read_yesno(void)
Return a positive value if a line read from standard input starts with [yY], otherwise return 0...
static const OptionDef options[]
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
#define CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
#define AV_DICT_IGNORE_SUFFIX
void avcodec_get_frame_defaults(AVFrame *pic)
Set the fields of the given AVFrame to default values.
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
static char * vstats_filename
static volatile int received_sigterm
void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload, AVStream *st)
Send a nice dump of a packet to the log.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static int opt_start_time(const char *opt, const char *arg)
static int opt_input_file(const char *opt, const char *filename)
static int opt_codec(int *pstream_copy, char **pcodec_name, int codec_type, const char *arg)
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
AVRational r_frame_rate
Real base framerate of the stream.
struct MetadataMap MetadataMap
select an input file for an output file
int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut *inputs, AVFilterInOut *outputs, void *log_ctx)
Add a graph described by a string to a graph.
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
static int * streamid_map
void av_audio_convert_free(AVAudioConvert *ctx)
Free audio sample format converter context.
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
static int metadata_streams_autocopy
static void sigterm_handler(int sig)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static void do_video_stats(AVFormatContext *os, OutputStream *ost, int frame_size)
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
enum AVSampleFormat av_get_sample_fmt(const char *name)
Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE on error.
#define AV_NOPTS_VALUE
Undefined timestamp value.
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
enum PixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
preferred ID for decoding MPEG audio layer 1, 2 or 3
void exit_program(int ret)
Do all the necessary cleanup and abort.
static uint16_t * intra_matrix
ReSampleContext * resample
uint8_t * subtitle_header
Header containing style information for text subtitles.
int64_t av_gettime(void)
Get the current time in microseconds.