57 #if HAVE_SYS_RESOURCE_H
58 #include <sys/types.h>
60 #include <sys/resource.h>
61 #elif HAVE_GETPROCESSTIMES
64 #if HAVE_GETPROCESSMEMORYINFO
70 #include <sys/select.h>
80 #define VSYNC_PASSTHROUGH 0
146 #define DEFAULT_PASS_LOGFILENAME_PREFIX "av2pass"
371 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
374 for (i = 0; i < o->nb_ ## name; i++) {\
375 char *spec = o->name[i].specifier;\
376 if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0)\
377 outvar = o->name[i].u.type;\
389 void *dst = (uint8_t*)o + po->
u.
off;
393 int i, *count = (
int*)(so + 1);
394 for (i = 0; i < *count; i++) {
410 memset(o, 0,
sizeof(*o));
427 int h_chroma_shift, v_chroma_shift;
450 memset(buf->
base[0], 128, ret);
454 const int h_shift = i==0 ? 0 : h_chroma_shift;
455 const int v_shift = i==0 ? 0 : v_chroma_shift;
458 else if (buf->
base[i])
461 (pixel_size*edge >> h_shift), 32);
566 snprintf(args, 255,
"%d:%d:%d:%d:%d:%d:%d", ist->
st->
codec->
width,
568 sample_aspect_ratio.
num, sample_aspect_ratio.
den);
571 "src", args,
NULL, ost->graph);
575 "out",
NULL, &avsink_ctx, ost->graph);
578 last_filter = ost->input_video_filter;
581 snprintf(args, 255,
"%d:%d:flags=0x%X",
593 snprintf(args,
sizeof(args),
"flags=0x%X", (
unsigned)ost->
sws_flags);
594 ost->graph->scale_sws_opts =
av_strdup(args);
606 inputs->
filter_ctx = ost->output_video_filter;
613 if ((ret =
avfilter_link(last_filter, 0, ost->output_video_filter, 0)) < 0)
620 codec->
width = ost->output_video_filter->inputs[0]->w;
621 codec->
height = ost->output_video_filter->inputs[0]->h;
625 ost->output_video_filter->inputs[0]->sample_aspect_ratio;
642 received_sigterm = sig;
643 received_nb_signals++;
658 return received_nb_signals > 1;
684 if (output_streams[i].output_frame) {
691 av_freep(&output_streams[i].forced_keyframes);
693 av_freep(&output_streams[i].avfilter);
700 av_freep(&input_streams[i].decoded_frame);
701 av_freep(&input_streams[i].filtered_frame);
724 if (received_sigterm) {
726 (
int) received_sigterm);
744 const char *codec_string = encoder ?
"encoder" :
"decoder";
749 "results.\nAdd '-strict experimental' if you want to use it.\n",
754 codec_string, codec->
name);
763 for (; *p != -1; p++) {
769 "Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n",
799 int min_dec = -1, min_inc = -1;
823 int best_dist = INT_MAX;
826 if (dist < best_dist) {
857 "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
924 int fill_char = 0x00;
927 memset(buf, fill_char, size);
931 const uint8_t *buf,
int buf_size)
958 buf, buf_size, 1)) < 0) {
992 int64_t audio_buf_size;
994 int size_out, frame_bytes, resample_changed;
999 uint8_t *buf = decoded_frame->
data[0];
1001 int64_t allocated_for_size =
size;
1004 audio_buf_size = (allocated_for_size + isize * dec->
channels - 1) / (isize * dec->
channels);
1006 audio_buf_size = audio_buf_size * 2 + 10000;
1008 audio_buf_size *= osize * enc->
channels;
1010 if (audio_buf_size > INT_MAX) {
1029 if (resample_changed) {
1030 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",
1063 #define MAKE_SFMT_PAIR(a,b) ((a)+AV_SAMPLE_FMT_NB*(b))
1083 int byte_delta = idelta * isize * dec->
channels;
1086 if (fabs(delta) > 50) {
1088 if (byte_delta < 0) {
1089 byte_delta =
FFMAX(byte_delta, -size);
1093 -byte_delta / (isize * dec->
channels));
1098 static uint8_t *input_tmp =
NULL;
1099 input_tmp =
av_realloc(input_tmp, byte_delta + size);
1101 if (byte_delta > allocated_for_size - size) {
1102 allocated_for_size = byte_delta + (int64_t)size;
1108 memcpy(input_tmp + byte_delta, buf, size);
1129 (
short *)buftmp, (
short *)buf,
1131 size_out = size_out * enc->
channels * osize;
1138 const void *ibuf[6] = { buftmp };
1140 int istride[6] = { isize };
1141 int ostride[6] = { osize };
1142 int len = size_out / istride[0];
1144 printf(
"av_audio_convert() failed\n");
1150 size_out = len * osize;
1192 picture2 = &picture_tmp;
1207 if (picture != picture2)
1208 *picture = *picture2;
1218 static uint8_t *subtitle_out =
NULL;
1219 int subtitle_out_max_size = 1024 * 1024;
1220 int subtitle_out_size, nb, i;
1233 if (!subtitle_out) {
1234 subtitle_out =
av_malloc(subtitle_out_max_size);
1245 for (i = 0; i < nb; i++) {
1252 subtitle_out_max_size, sub);
1253 if (subtitle_out_size < 0) {
1260 pkt.
data = subtitle_out;
1261 pkt.
size = subtitle_out_size;
1278 #if !CONFIG_AVFILTER
1284 int resample_changed = 0;
1285 *out_picture = in_picture;
1291 if (resample_changed) {
1293 "Input stream #%d:%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
1303 if (resample_changed) {
1320 0, ost->
resample_height, (*out_picture)->data, (*out_picture)->linesize);
1322 if (resample_changed) {
1335 int *frame_size,
float quality)
1337 int nb_frames, i, ret, format_video_sync;
1357 double vdelta = sync_ipts - ost->
sync_opts;
1361 else if (format_video_sync ==
VSYNC_VFR) {
1362 if (vdelta <= -0.6) {
1364 }
else if (vdelta > 0.6)
1366 }
else if (vdelta > 1.1)
1367 nb_frames =
lrintf(vdelta);
1369 if (nb_frames == 0) {
1372 }
else if (nb_frames > 1) {
1383 #if !CONFIG_AVFILTER
1386 final_picture = in_picture;
1390 for (i = 0; i < nb_frames; i++) {
1402 pkt.
data = (uint8_t *)final_picture;
1411 big_picture = *final_picture;
1424 big_picture.
quality = quality;
1437 bit_buffer, bit_buffer_size,
1478 return -10.0 * log(d) / log(10.0);
1486 double ti1, bitrate, avg_bitrate;
1511 avg_bitrate = (double)(
video_size * 8) / ti1 / 1000.0;
1512 fprintf(
vstats_file,
"s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
1513 (
double)
video_size / 1024, ti1, bitrate, avg_bitrate);
1527 int frame_number, vid, i;
1528 double bitrate, ti1, pts;
1529 static int64_t last_time = -1;
1530 static int qp_histogram[52];
1535 if (!is_last_report) {
1539 if (last_time == -1) {
1543 if ((cur_time - last_time) < 500000)
1549 oc = output_files[0].
ctx;
1558 for (i = 0; i < nb_ostreams; i++) {
1560 ost = &ost_table[i];
1565 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"q=%2.1f ", q);
1571 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"frame=%5d fps=%3d q=%3.1f ",
1572 frame_number, (t > 1) ? (
int)(frame_number / t + 0.5) : 0, q);
1574 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"L");
1580 for (j = 0; j < 32; j++)
1581 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%X", (
int)
lrintf(log(qp_histogram[j] + 1) / log(2)));
1585 double error, error_sum = 0;
1586 double scale, scale_sum = 0;
1587 char type[3] = {
'Y',
'U',
'V' };
1588 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"PSNR=");
1589 for (j = 0; j < 3; j++) {
1590 if (is_last_report) {
1591 error = enc->
error[j];
1592 scale = enc->
width * enc->
height * 255.0 * 255.0 * frame_number;
1601 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%c:%2.2f ", type[j],
psnr(error / scale));
1603 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"*:%2.2f ",
psnr(error_sum / scale_sum));
1609 if ((pts < ti1) && (pts > 0))
1615 bitrate = (double)(total_size * 8) / ti1 / 1000.0;
1617 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
1618 "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s",
1619 (
double)total_size / 1024, ti1, bitrate);
1622 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
" dup=%d drop=%d",
1629 if (is_last_report) {
1632 av_log(
NULL,
AV_LOG_INFO,
"video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n",
1635 extra_size / 1024.0,
1636 100.0 * (total_size - raw) / raw
1645 for (i = 0; i < nb_ostreams; i++) {
1649 int stop_encoding = 0;
1669 if (fifo_bytes > 0) {
1671 int frame_bytes = fifo_bytes;
1779 opkt.
dts -= ost_tb_start_time;
1852 for (i = 0; i < (decoded_data_size /
sizeof(*volp)); i++) {
1854 *volp++ = av_clip_uint8(v);
1861 for (i = 0; i < (decoded_data_size /
sizeof(*volp)); i++) {
1863 *volp++ = av_clip_int16(v);
1870 for (i = 0; i < (decoded_data_size /
sizeof(*volp)); i++) {
1872 *volp++ = av_clipl_int32(v);
1880 for (i = 0; i < (decoded_data_size /
sizeof(*volp)); i++) {
1889 for (i = 0; i < (decoded_data_size /
sizeof(*volp)); i++) {
1896 "Audio volume adjustment on sample format %s is not supported.\n",
1918 void *buffer_to_free =
NULL;
1922 int frame_available = 1;
1930 pkt->
pts = *pkt_pts;
1935 decoded_frame, got_output, pkt);
1962 int frame_size, resample_changed;
1971 if (resample_changed) {
1973 "Input stream #%d:%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
1979 if (configure_video_filters(ist, ost)) {
2018 while (frame_available) {
2020 if (ost->output_video_filter)
2027 filtered_frame = decoded_frame;
2035 frame_available = ost->output_video_filter &&
avfilter_poll_frame(ost->output_video_filter->inputs[0]);
2050 &subtitle, got_output, pkt);
2108 "Multiple frames in a packet from stream %d\n", pkt->
stream_index);
2157 for (i = 0; pkt && i < nb_ostreams; i++) {
2177 for (i = 0; i < n; i++)
2178 avc[i] = output_files[i].ctx;
2181 printf(
"SDP:\n%s\n", sdp);
2187 char *error,
int error_len)
2194 snprintf(error, error_len,
"Decoder (codec id %d) not found for input stream #%d:%d",
2218 snprintf(error, error_len,
"Error while opening decoder for input stream #%d:%d",
2241 for (p = kf; *p; p++)
2252 for (i = 0; i < n; i++) {
2253 char *next = strchr(p,
',');
2270 int ret = 0, i, j, k;
2288 oc = output_files[i].
ctx;
2298 ost = &output_streams[i];
2315 if (extra_size > INT_MAX) {
2415 icodec->request_channels = codec-> channels;
2439 #if !CONFIG_AVFILTER
2475 if (configure_video_filters(ist, ost)) {
2495 snprintf(logfilename,
sizeof(logfilename),
"%s-%d.log",
2498 if (!strcmp(ost->
enc->
name,
"libx264")) {
2502 f = fopen(logfilename,
"wb");
2505 logfilename, strerror(errno));
2511 size_t logbuffer_size;
2524 bit_buffer_size =
FFMAX(bit_buffer_size, 6 * size + 200);
2529 bit_buffer =
av_malloc(bit_buffer_size);
2538 ost = &output_streams[i];
2543 snprintf(error,
sizeof(error),
"Encoder (codec id %d) not found for output stream #%d:%d",
2560 snprintf(error,
sizeof(error),
"Error while opening encoder for output stream #%d:%d - maybe incorrect parameters such as bit_rate, rate, width or height",
2569 "It takes bits/s as argument, not kbits/s\n");
2579 if ((ret =
init_input_stream(i, output_streams, nb_output_streams, error,
sizeof(error))) < 0)
2600 oc = output_files[i].
ctx;
2603 snprintf(error,
sizeof(error),
"Could not write header for output file #%d (incorrect codec parameters ?)", i);
2617 av_dump_format(output_files[i].ctx, i, output_files[i].ctx->filename, 1);
2623 ost = &output_streams[i];
2655 print_sdp(output_files, nb_output_files);
2674 int no_packet_count = 0;
2677 if (!(no_packet =
av_mallocz(nb_input_files)))
2680 ret =
transcode_init(output_files, nb_output_files, input_files, nb_input_files);
2689 for (; received_sigterm == 0;) {
2690 int file_index, ist_index;
2705 ost = &output_streams[i];
2717 if (ipts < ipts_min) {
2722 if (opts < opts_min) {
2735 if (file_index < 0) {
2736 if (no_packet_count) {
2737 no_packet_count = 0;
2738 memset(no_packet, 0, nb_input_files);
2746 is = input_files[file_index].
ctx;
2749 no_packet[file_index] = 1;
2761 no_packet_count = 0;
2762 memset(no_packet, 0, nb_input_files);
2771 goto discard_packet;
2773 ist = &input_streams[ist_index];
2775 goto discard_packet;
2798 "timestamp discontinuity %"PRId64
", new offset= %"PRId64
"\n",
2807 if (
output_packet(ist, output_streams, nb_output_streams, &pkt) < 0) {
2821 print_report(output_files, output_streams, nb_output_streams, 0, timer_start);
2826 ist = &input_streams[i];
2837 os = output_files[i].
ctx;
2846 ost = &output_streams[i];
2858 ist = &input_streams[i];
2871 if (output_streams) {
2873 ost = &output_streams[i];
2906 p = strchr(arg,
':');
2908 x = strtol(arg, &end, 10);
2910 y = strtol(end + 1, &end, 10);
2912 ar = (double)x / (
double)y;
2914 ar = strtod(arg,
NULL);
2946 int i, negative = 0, file_idx;
2947 int sync_file_idx = -1, sync_stream_idx;
2958 if (sync = strchr(map,
',')) {
2960 sync_file_idx = strtol(sync + 1, &sync, 0);
2967 for (i = 0; i < input_files[sync_file_idx].
nb_streams; i++)
2969 input_files[sync_file_idx].ctx->streams[i], sync) == 1) {
2970 sync_stream_idx = i;
2973 if (i == input_files[sync_file_idx].nb_streams) {
2975 "match any streams.\n", arg);
2981 file_idx = strtol(map, &p, 0);
2993 *p ==
':' ? p + 1 : p) > 0)
2997 for (i = 0; i < input_files[file_idx].
nb_streams; i++) {
2999 *p ==
':' ? p + 1 : p) <= 0)
3008 if (sync_file_idx >= 0) {
3048 if (*(++arg) && *arg !=
':') {
3052 *stream_spec = *arg ==
':' ? arg + 1 :
"";
3056 if (*(++arg) ==
':')
3057 *index = strtol(++arg,
NULL, 0);
3072 char type_in, type_out;
3073 const char *istream_spec =
NULL, *ostream_spec =
NULL;
3074 int idx_in = 0, idx_out = 0;
3079 if (type_in ==
'g' || type_out ==
'g')
3081 if (type_in ==
's' || type_out ==
's')
3083 if (type_in ==
'c' || type_out ==
'c')
3086 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
3087 if ((index) < 0 || (index) >= (nb_elems)) {\
3088 av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\
3093 #define SET_DICT(type, meta, context, index)\
3096 meta = &context->metadata;\
3099 METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\
3100 meta = &context->chapters[index]->metadata;\
3103 METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
3104 meta = &context->programs[index]->metadata;\
3110 SET_DICT(type_in, meta_in, ic, idx_in);
3111 SET_DICT(type_out, meta_out, oc, idx_out);
3114 if (type_in ==
's') {
3128 if (type_out ==
's') {
3144 const char *codec_string = encoder ?
"encoder" :
"decoder";
3154 if (codec->
type != type) {
3163 char *codec_name =
NULL;
3234 (strchr(filename,
':') ==
NULL || filename[1] ==
':' ||
3238 fprintf(stderr,
"File '%s' already exists. Overwrite ? [y/N] ", filename);
3241 fprintf(stderr,
"Not overwriting - exiting\n");
3246 fprintf(stderr,
"File '%s' already exists. Exiting.\n", filename);
3265 filename = e->
value;
3293 int orig_nb_streams;
3302 if (!strcmp(filename,
"-"))
3306 !strcmp(filename,
"/dev/stdin");
3397 for (i = 0; i < orig_nb_streams; i++)
3416 while ((c =
avio_r8(s)) && c !=
'\n')
3427 char filename[1000];
3428 const char *base[3] = { getenv(
"AVCONV_DATADIR"),
3437 snprintf(filename,
sizeof(filename),
"%s%s/%s-%s.avpreset", base[i],
3438 i != 1 ?
"" :
"/.avconv", codec_name, preset_name);
3442 snprintf(filename,
sizeof(filename),
"%s%s/%s.avpreset", base[i],
3443 i != 1 ?
"" :
"/.avconv", preset_name);
3452 char *codec_name =
NULL;
3459 }
else if (!strcmp(codec_name,
"copy"))
3472 char *bsf =
NULL, *next, *codec_tag =
NULL;
3502 if (!buf[0] || buf[0] ==
'#') {
3506 if (!(arg = strchr(buf,
'='))) {
3518 "Preset %s specified for stream %d:%d, but could not be opened.\n",
3532 if (next = strchr(bsf,
','))
3539 bsfc_prev->
next = bsfc;
3549 uint32_t
tag = strtol(codec_tag, &next, 0);
3571 const char *p = str;
3593 video_enc = st->
codec;
3596 const char *p =
NULL;
3615 if (frame_aspect_ratio)
3643 for (i = 0; p; i++) {
3645 int e = sscanf(p,
"%d,%d,%d", &start, &end, &q);
3708 audio_enc = st->
codec;
3712 char *sample_fmt =
NULL;
3757 subtitle_enc = st->
codec;
3772 p = strchr(idx_str,
':');
3775 "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
3800 if (in_ch->
end < ts_off)
3809 out_ch->id = in_ch->
id;
3811 out_ch->start =
FFMAX(0, in_ch->
start - ts_off);
3812 out_ch->end =
FFMIN(rt, in_ch->
end - ts_off);
3835 if (!strcmp(filename,
"-"))
3846 if (!file_oformat) {
3852 if (!file_oformat) {
3865 #define NEW_STREAM(type, index)\
3867 ost = new_ ## type ## _stream(o, oc);\
3868 ost->source_index = index;\
3869 ost->sync_ist = &input_streams[index];\
3870 input_streams[index].discard = 0;\
3875 int area = 0, idx = -1;
3877 ist = &input_streams[i];
3889 int channels = 0, idx = -1;
3891 ist = &input_streams[i];
3940 uint8_t *attachment;
4015 if (in_file_index < 0)
4018 av_log(
NULL,
AV_LOG_FATAL,
"Invalid input file index %d while processing metadata maps\n", in_file_index);
4030 if (input_files[i].ctx->nb_chapters) {
4051 if (output_streams[i].source_index < 0)
4061 const char *stream_spec;
4062 int index = 0, j, ret;
4080 printf(
"ret %d, stream_spec %s\n", ret, stream_spec);
4115 struct rusage rusage;
4117 getrusage(RUSAGE_SELF, &rusage);
4118 return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
4119 #elif HAVE_GETPROCESSTIMES
4121 FILETIME c, e, k, u;
4122 proc = GetCurrentProcess();
4123 GetProcessTimes(proc, &c, &e, &k, &u);
4124 return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
4132 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
4133 struct rusage rusage;
4134 getrusage(RUSAGE_SELF, &rusage);
4135 return (int64_t)rusage.ru_maxrss * 1024;
4136 #elif HAVE_GETPROCESSMEMORYINFO
4138 PROCESS_MEMORY_COUNTERS memcounters;
4139 proc = GetCurrentProcess();
4140 memcounters.cb =
sizeof(memcounters);
4141 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
4142 return memcounters.PeakPagefileUsage;
4155 printf(
"Hyper fast Audio and Video encoder\n");
4156 printf(
"usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n",
program_name);
4196 enum {
PAL,
NTSC, FILM, UNKNOWN } norm = UNKNOWN;
4197 static const char *
const frame_rates[] = {
"25",
"30000/1001",
"24000/1001" };
4199 if (!strncmp(arg,
"pal-", 4)) {
4202 }
else if (!strncmp(arg,
"ntsc-", 5)) {
4205 }
else if (!strncmp(arg,
"film-", 5)) {
4213 for (i = 0; i < input_files[j].
nb_streams; i++) {
4222 }
else if ((fr == 29970) || (fr == 23976)) {
4227 if (norm != UNKNOWN)
4231 if (norm != UNKNOWN)
4235 if (norm == UNKNOWN) {
4242 if (!strcmp(arg,
"vcd")) {
4269 }
else if (!strcmp(arg,
"svcd")) {
4291 }
else if (!strcmp(arg,
"dvd")) {
4312 }
else if (!strncmp(arg,
"dv", 2)) {
4317 parse_option(o,
"pix_fmt", !strncmp(arg,
"dv50", 4) ?
"yuv422p" :
4318 norm ==
PAL ?
"yuv420p" :
"yuv411p", options);
4342 struct tm *today = localtime(&today2);
4344 snprintf(filename,
sizeof(filename),
"vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
4395 #define OFFSET(x) offsetof(OptionsContext, x)
4405 {
"map",
HAS_ARG |
OPT_EXPERT |
OPT_FUNC2, {(
void*)
opt_map},
"set input stream mapping",
"[-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]]" },
4407 "outfile[,metadata]:infile[,metadata]" },
4417 "add timings for benchmarking" },
4420 "dump each input packet" },
4422 "when dumping packets, also dump the payload" },
4424 {
"target",
HAS_ARG |
OPT_FUNC2, {(
void*)
opt_target},
"specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)",
"type" },
4456 "use same quantizer as source (implies VBR)" },
4460 "deinterlace pictures" },
4541 fprintf(stderr,
"At least one output file must be specified\n");
4556 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.
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
static int nb_input_files
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 ...
int(* get_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of each frame to get a buffer for it.
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...
static int check_output_constraints(InputStream *ist, OutputStream *ost)
int64_t avio_size(AVIOContext *s)
Get the filesize.
static int nb_input_streams
void avfilter_register_all(void)
Initialize the filter system.
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.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o)
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.
static void parse_matrix_coeffs(uint16_t *dest, const char *str)
#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)
static void do_video_resample(OutputStream *ost, InputStream *ist, AVFrame *in_picture, AVFrame **out_picture)
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.
static OutputStream * new_data_stream(OptionsContext *o, AVFormatContext *oc)
#define CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
static int init_input_stream(int ist_index, OutputStream *output_streams, int nb_output_streams, char *error, int error_len)
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
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 avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
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.
SpecifierOpt * copy_initial_nonkeyframes
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
static void reset_options(OptionsContext *o)
static void show_usage(void)
Memory buffer source API.
AVFrame * coded_frame
the picture in the bitstream
static int64_t timer_start
int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Decode the audio frame of size avpkt->size from avpkt->data into frame.
void show_banner(void)
Print the program banner to stderr.
static void term_exit(void)
int avpicture_deinterlace(AVPicture *dst, const AVPicture *src, enum PixelFormat pix_fmt, int width, int height)
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.
static int nb_frames_drop
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
void * opaque
for some private data of the user
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
#define AVIO_FLAG_READ
read-only
static int sync(AVFormatContext *s, uint8_t *header)
Read input until we find the next ident.
SpecifierOpt * sample_fmts
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
void * priv
private data to be used by a custom free function
#define AVIO_FLAG_WRITE
write-only
static char * pass_logfilename_prefix
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.
static void choose_pixel_fmt(AVStream *st, AVCodec *codec)
A reference-counted buffer data type used by the filter system.
static int transcode_init(OutputFile *output_files, int nb_output_files, InputFile *input_files, int nb_input_files)
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 choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *ost)
static float dts_delta_threshold
static void flush_encoders(OutputStream *ost_table, int nb_ostreams)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
static float mux_max_delay
static OutputStream * new_video_stream(OptionsContext *o, AVFormatContext *oc)
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)
static volatile int received_sigterm
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
const AVClass * sws_get_class(void)
Get the AVClass for swsContext.
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
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.
int is_past_recording_time
static int alloc_buffer(InputStream *ist, FrameBuffer **pbuf)
static int opt_video_codec(OptionsContext *o, const char *opt, const char *arg)
void init_pts_correction(PtsCorrectionContext *ctx)
Reset the state of the PtsCorrectionContext.
int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)
SpecifierOpt * frame_pix_fmts
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.
SpecifierOpt * intra_matrices
struct InputStream InputStream
static int opt_streamid(OptionsContext *o, const char *opt, const char *arg)
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)
#define AV_PERM_READ
can read from the buffer
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...
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.
static const uint8_t frame_sizes[]
RTP Depacketization of QCELP/PureVoice, RFC 2658 Copyright (c) 2010 Martin Storsjo.
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
int copy_initial_nonkeyframes
static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
struct FrameBuffer * next
enum AVSampleFormat sample_fmt
audio sample format
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
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.
static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
miscellaneous OS support macros and functions.
int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
int id
unique ID to identify the chapter
int id
format-specific stream ID
struct StreamMap StreamMap
#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...
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.
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.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
static void opt_output_file(void *optctx, const char *filename)
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 term_init(void)
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 void pre_process_video_frame(InputStream *ist, AVPicture *picture, void **bufp)
static void dump_attachment(AVStream *st, const char *filename)
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 void do_video_stats(AVFormatContext *os, OutputStream *ost, int frame_size)
SpecifierOpt * bitstream_filters
int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size)
Generate an SDP for an RTP session.
int interlaced_frame
The content of the picture is interlaced.
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
void av_destruct_packet(AVPacket *pkt)
Default packet destructor.
static void assert_codec_experimental(AVCodecContext *c, int encoder)
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.
static void do_audio_out(AVFormatContext *s, OutputStream *ost, InputStream *ist, AVFrame *decoded_frame)
enum AVDiscard discard
selects which program to discard and which to feed to the caller
char * stats_out
pass1 encoding statistics output buffer
static FILE * vstats_file
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
static int64_t input_ts_offset
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...
#define MAKE_SFMT_PAIR(a, b)
static uint64_t limit_filesize
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
struct AVBitStreamFilterContext * next
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
unsigned int * stream_index
static int decode_interrupt_cb(void *ctx)
static void choose_sample_rate(AVStream *st, AVCodec *codec)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
static char * vstats_filename
struct AVOutputFormat * oformat
static int top_field_first
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.
int64_t pts
presentation timestamp.
AVDictionary * format_opts
preferred ID for MPEG-1/2 video decoding
audio conversion routines
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
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.
int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src)
Copy the frame properties of src to dst, without copying the actual image data.
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
static int opt_subtitle_tag(OptionsContext *o, const char *opt, const char *arg)
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.
Callback for checking whether to abort blocking functions.
static int64_t start_time
int width
width and height of the video frame
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.
#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.
static int64_t extra_size
AVBitStreamFilterContext * bitstream_filters
static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata)
struct OutputStream OutputStream
static uint16_t * inter_matrix
static int output_packet(InputStream *ist, OutputStream *ost_table, int nb_ostreams, const AVPacket *pkt)
AVFilterBuffer * buf
the buffer that this is a reference to
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.
uint8_t * base[AV_NUM_DATA_POINTERS]
pointer to the first allocated byte of the picture.
static int audio_sample_rate
static void update_sample_fmt(AVCodecContext *dec, AVCodec *dec_codec, AVCodecContext *enc)
Update the requested input sample format based on the output sample format.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
static int do_deinterlace
static int opt_input_file(OptionsContext *o, const char *opt, const char *filename)
#define FF_BUFFER_TYPE_USER
direct rendering buffers (image is (de)allocated by user)
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
Parse one given option.
SpecifierOpt * codec_tags
int rc_max_rate
maximum bitrate
#define CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
SpecifierOpt * rc_overrides
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
int main(int argc, char **argv)
const char * name
Name of the codec implementation.
static unsigned int allocated_audio_buf_size
struct OptionsContext OptionsContext
AVBitStreamFilterContext * av_bitstream_filter_init(const char *name)
static void rate_emu_sleep(InputStream *ist)
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]
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
static int nb_output_streams
int avio_r8(AVIOContext *s)
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.
int file_index
1 is this mapping is disabled by a negative map
MetadataMap(* meta_data_maps)[2]
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
unsigned int nb_streams
A list of all streams in the file.
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
struct AVRational AVRational
rational number numerator/denominator
int avfilter_poll_frame(AVFilterLink *link)
Poll a frame from the filter chain.
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
int bit_rate
the average bitrate
static int64_t audio_size
int void avio_flush(AVIOContext *s)
int av_image_alloc(uint8_t *pointers[4], int linesizes[4], int w, int h, enum PixelFormat pix_fmt, int align)
Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordi...
static OutputStream * new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type)
static uint8_t * bit_buffer
int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, enum AVSampleFormat sample_fmt, const uint8_t *buf, int buf_size, int align)
Fill audio frame data and linesize.
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
Add all the streams from the given input file to the global list of input streams.
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
static const AVIOInterruptCB int_cb
static InputStream * input_streams
char filename[1024]
input or output filename
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.
SpecifierOpt * audio_channels
struct FrameBuffer FrameBuffer
int av_strcasecmp(const char *a, const char *b)
static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_t *pkt_pts)
int metadata_chapters_manual
int width
picture width / height.
int type
type of the buffer (to keep track of who has to deallocate data[*])
SpecifierOpt * audio_sample_rate
enum CodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the CodecID for the given codec tag tag.
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.
SpecifierOpt * dump_attachment
static int opt_audio_codec(OptionsContext *o, const char *opt, const char *arg)
static av_always_inline av_const long int lrintf(float x)
static OutputStream * new_attachment_stream(OptionsContext *o, AVFormatContext *oc)
SpecifierOpt * metadata_map
static int opt_audio_frames(OptionsContext *o, const char *opt, const char *arg)
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
static void do_subtitle_out(AVFormatContext *s, OutputStream *ost, InputStream *ist, AVSubtitle *sub, int64_t pts)
void exit_program(int ret)
Do all the necessary cleanup and abort.
char * specifier
stream/chapter/program/...
static volatile int received_nb_signals
static AVCodec * choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st)
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.
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 filter_release_buffer(AVFilterBuffer *fb)
SpecifierOpt * frame_aspect_ratios
SpecifierOpt * frame_sizes
static int bit_buffer_size
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.
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
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
void(* free)(struct AVFilterBuffer *buf)
A pointer to the function to deallocate this buffer if the default function is not sufficient...
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.
A linked-list of the inputs/outputs of the filter chain.
static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
int64_t end
chapter start/end time in time_base units
int format
format of the frame, -1 if unknown or unset Values correspond to enum PixelFormat for video frames...
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
A reference to an AVFilterBuffer.
static uint8_t * get_line(AVIOContext *s)
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
int frame_size
Samples per packet, initialized when calling 'init'.
int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of audio.
static void show_help(void)
static void parse_forced_key_frames(char *kf, OutputStream *ost, AVCodecContext *avctx)
SpecifierOpt * frame_rates
static int opt_subtitle_codec(OptionsContext *o, const char *opt, const char *arg)
void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift)
static int64_t getmaxrss(void)
uint64_t error[AV_NUM_DATA_POINTERS]
error
static OutputStream * new_audio_stream(OptionsContext *o, AVFormatContext *oc)
static OutputStream * new_subtitle_stream(OptionsContext *o, AVFormatContext *oc)
int opt_timelimit(const char *opt, const char *arg)
Limit the execution time.
enum AVMediaType codec_type
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 DEFAULT_PASS_LOGFILENAME_PREFIX
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
char * av_strdup(const char *s)
Duplicate the string s.
static void free_buffer_pool(InputStream *ist)
AVDictionary * filter_codec_opts(AVDictionary *opts, enum CodecID codec_id, AVFormatContext *s, AVStream *st)
Filter out options for given codec.
int sample_rate
samples per second
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
void av_log_set_flags(int arg)
static int opt_video_filters(OptionsContext *o, const char *opt, const char *arg)
static const OptionDef options[]
void avio_w8(AVIOContext *s, int b)
main external API structure.
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
#define CODEC_FLAG_QSCALE
Use fixed qscale.
static int codec_get_buffer(AVCodecContext *s, AVFrame *frame)
static double psnr(double d)
AVRational sample_aspect_ratio
sample aspect ratio for the video frame, 0/1 if unknown
const int program_birth_year
program birth year, defined by the program for show_banner()
int metadata_streams_manual
const char * attachment_filename
#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 InputFile * input_files
static int opt_vstats(const char *opt, const char *arg)
static uint8_t * audio_buf
static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
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.
SpecifierOpt * top_field_first
struct AVBitStreamFilter * filter
uint16_t * intra_matrix
custom intra quantization matrix
static void choose_sample_fmt(AVStream *st, AVCodec *codec)
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 ...
static int video_sync_method
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 OutputFile * output_files
int pad_idx
index of the filt_ctx pad to use for linking
rational number numerator/denominator
const char program_name[]
program name, defined by the program for show_version().
int metadata_global_manual
int avpicture_fill(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt, int width, int height)
Fill in the AVPicture fields.
static struct PPFilter filters[]
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...
void * grow_array(void *array, int elem_size, int *size, int new_size)
Realloc array to hold new_size elements of elem_size.
struct SwsContext * sws_opts
uint16_t step_minus1
Number of elements between 2 horizontally consecutive pixels minus 1.
static int64_t getutime(void)
static OutputStream * output_streams
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
static double parse_frame_aspect_ratio(const char *arg)
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
AVFilterBufferRef * avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms, int w, int h, enum PixelFormat format)
Create a buffer reference wrapped around an already allocated image buffer.
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_target(OptionsContext *o, const char *opt, const char *arg)
static int transcode(OutputFile *output_files, int nb_output_files, InputFile *input_files, int nb_input_files)
struct SwsContext * img_resample_ctx
static float audio_drift_threshold
static int audio_sync_method
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
static int opt_pass(const char *opt, const char *arg)
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.
#define VSYNC_PASSTHROUGH
char * name
unique name for this input/output in the list
static void print_sdp(OutputFile *output_files, int n)
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
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 AV_PERM_PRESERVE
nobody else can overwrite the buffer
#define CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
void av_bitstream_filter_close(AVBitStreamFilterContext *bsf)
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...
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
enum PixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
#define CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
Audio format conversion routines.
int64_t pkt_dts
dts from the last AVPacket that has been input into the decoder
AVPacket * pkt
Current packet as passed into the decoder, to avoid having to pass the packet into every function...
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
struct OutputFile OutputFile
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 void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec)
Parse a metadata specifier in arg.
static int opt_video_frames(OptionsContext *o, const char *opt, const char *arg)
AVDictionary * codec_opts
static int opt_audio_qscale(OptionsContext *o, const char *opt, const char *arg)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int opt_attach(OptionsContext *o, const char *opt, const char *arg)
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.
SpecifierOpt * inter_matrices
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 intra_dc_precision
static int opt_map(OptionsContext *o, const char *opt, const char *arg)
#define SET_DICT(type, meta, context, index)
int disposition
AV_DISPOSITION_* bit field.
uint32_t start_display_time
static int opt_vstats_file(const char *opt, const char *arg)
AVSampleFormat
all in native-endian format
SpecifierOpt * forced_key_frames
static char * forced_key_frames
const char ** attachments
AVRational time_base
time base in which the start/end timestamps are specified
static double get_sync_ipts(const OutputStream *ost)
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents...
static int opt_data_frames(OptionsContext *o, const char *opt, const char *arg)
struct AVInputFormat * iformat
Can only be iformat or oformat, not both at the same time.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
static int file_overwrite
static AVRational frame_rate
memory buffer source API for video
static void unref_buffer(InputStream *ist, FrameBuffer *buf)
static void codec_release_buffer(AVCodecContext *s, AVFrame *frame)
static void print_report(OutputFile *output_files, OutputStream *ost_table, int nb_ostreams, int is_last_report, int64_t timer_start)
int eof_reached
true if eof reached
int top_field_first
If the content is interlaced, is top field displayed first.
struct MetadataMap MetadataMap
select an input file for an output file
struct AVFrac pts
encoding: pts generation when outputting stream
struct InputFile InputFile
int channels
number of audio channels
static int64_t video_size
#define NEW_STREAM(type, index)
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0 ...
struct AVCodecParserContext * parser
SpecifierOpt * max_frames
static int opt_vsync(const char *opt, const char *arg)
int key_frame
1 -> keyframe, 0-> not
int opt_default(const char *opt, const char *arg)
Fallback for options that are not explicitly handled, these will be parsed through AVOptions...
int nb_copy_initial_nonkeyframes
#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)
void show_help_children(const AVClass *class, int flags)
Show help for all options with given flags in class and all its children.
static int nb_output_files
SpecifierOpt * codec_names
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
static int opt_data_codec(OptionsContext *o, const char *opt, const char *arg)
int frame_number
audio or video frame number
int repeat_pict
This field is used for proper frame duration computation in lavf.
int read_yesno(void)
Return a positive value if a line read from standard input starts with [yY], otherwise return 0...
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
enum AVFieldOrder field_order
Field order.
#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.
static void do_video_out(AVFormatContext *s, OutputStream *ost, InputStream *ist, AVFrame *in_picture, int *frame_size, float quality)
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
Add a buffer to the filtergraph s.
static void sigterm_handler(int sig)
static AVCodec * find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
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.
static int opt_audio_tag(OptionsContext *o, const char *opt, const char *arg)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static void generate_silence(uint8_t *buf, enum AVSampleFormat sample_fmt, size_t size)
uint8_t ** extended_data
pointers to the data planes/channels.
void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
Modify width and height values so that they will result in a memory buffer that is acceptable for the...
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.
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.
void av_audio_convert_free(AVAudioConvert *ctx)
Free audio sample format converter context.
int nb_samples
number of audio samples (per channel) described by this frame
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
static void assert_avoptions(AVDictionary *m)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void * opaque
Private data of the user, can be used to carry app specific stuff.
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.
static int opt_video_tag(OptionsContext *o, const char *opt, const char *arg)
#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.
static void assert_file_overwrite(const char *filename)
int nb_frame_aspect_ratios
static uint16_t * intra_matrix
ReSampleContext * resample
uint8_t * subtitle_header
Header containing style information for text subtitles.
static int encode_audio_frame(AVFormatContext *s, OutputStream *ost, const uint8_t *buf, int buf_size)
int64_t av_gettime(void)
Get the current time in microseconds.