71 #if HAVE_SYS_RESOURCE_H
73 #include <sys/types.h>
74 #include <sys/resource.h>
75 #elif HAVE_GETPROCESSTIMES
78 #if HAVE_GETPROCESSMEMORYINFO
84 #include <sys/select.h>
89 #include <sys/ioctl.h>
135 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
153 static struct termios oldtty;
154 static int restore_tty;
158 static void free_input_threads(
void);
184 uint32_t *pal, *dst2;
192 if (r->
x < 0 || r->
x + r->
w > w || r->
y < 0 || r->
y + r->
h > h) {
197 dst += r->
y * dst_linesize + r->
x * 4;
200 for (y = 0; y < r->
h; y++) {
201 dst2 = (uint32_t *)dst;
203 for (x = 0; x < r->
w; x++)
204 *(dst2++) = pal[*(src2++)];
230 int64_t
pts, end_pts;
247 "Impossible to get a blank canvas.\n");
250 dst = frame->
data [0];
252 for (i = 0; i < num_rects; i++)
276 if (pts2 <= ist2->sub2video.last_pts)
280 for (j = 0, nb_reqs = 0; j < ist2->
nb_filters; j++)
303 tcsetattr (0, TCSANOW, &oldtty);
335 istty = isatty(0) && isatty(2);
337 if (istty && tcgetattr (0, &tty) == 0) {
341 tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
342 |INLCR|IGNCR|ICRNL|IXON);
343 tty.c_oflag |= OPOST;
344 tty.c_lflag &= ~(
ECHO|ECHONL|ICANON|IEXTEN);
345 tty.c_cflag &= ~(CSIZE|PARENB);
350 tcsetattr (0, TCSANOW, &tty);
376 n = select(1, &rfds,
NULL,
NULL, &tv);
385 # if HAVE_PEEKNAMEDPIPE
387 static HANDLE input_handle;
390 input_handle = GetStdHandle(STD_INPUT_HANDLE);
391 is_pipe = !GetConsoleMode(input_handle, &dw);
394 if (stdin->_cnt > 0) {
400 if (!PeekNamedPipe(input_handle,
NULL, 0,
NULL, &nchars,
NULL)) {
432 printf(
"bench: maxrss=%ikB\n", maxrss);
494 free_input_threads();
572 printf(
"bench: %8"PRIu64
" %s \n", t -
current_time, buf);
583 ost2->
finished |= ost == ost2 ? this_stream : others;
636 memcpy(t, new_pkt.
data, new_pkt.
size);
653 av_log(NULL,
AV_LOG_ERROR,
"Failed to open bitstream filter %s for stream %d with codec %s",
669 av_log(s,
AV_LOG_WARNING,
"Invalid DTS: %"PRId64
" PTS: %"PRId64
" in output stream %d:%d, replacing by guess\n",
682 if (pkt->
dts < max) {
684 av_log(s, loglevel,
"Non-monotonous DTS in output stream "
685 "%d:%d; previous: %"PRId64
", current: %"PRId64
"; ",
691 av_log(s, loglevel,
"changing to %"PRId64
". This may result "
692 "in incorrect timestamps in the output file.\n",
709 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s size:%d\n",
774 "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
790 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
804 int subtitle_out_max_size = 1024 * 1024;
805 int subtitle_out_size, nb, i;
839 for (i = 0; i < nb; i++) {
840 unsigned save_num_rects = sub->
num_rects;
857 subtitle_out_max_size, sub);
860 if (subtitle_out_size < 0) {
867 pkt.
size = subtitle_out_size;
874 pkt.
pts += 90 * sub->start_display_time;
876 pkt.
pts += 90 * sub->end_display_time;
888 int ret, format_video_sync;
892 int nb_frames, nb0_frames, i;
893 double delta, delta0;
951 double cor =
FFMIN(-delta0, duration);
961 switch (format_video_sync) {
963 if (ost->
frame_number == 0 && delta - duration >= 0.5) {
973 }
else if (delta < -1.1)
975 else if (delta > 1.1) {
976 nb_frames =
lrintf(delta);
978 nb0_frames =
lrintf(delta0 - 0.6);
984 else if (delta > 0.6)
997 nb0_frames =
FFMIN(nb0_frames, nb_frames);
1007 "*** dropping frame %d from stream %d at ts %"PRId64
"\n",
1010 if (nb_frames > (nb0_frames && ost->
last_droped) + (nb_frames > nb0_frames)) {
1019 ost->
last_droped = nb_frames == nb0_frames && next_picture;
1022 for (i = 0; i < nb_frames; i++) {
1028 if (i < nb0_frames && ost->last_frame) {
1031 in_picture = next_picture;
1061 int got_packet, forced_keyframe = 0;
1084 forced_keyframe = 1;
1090 av_dlog(
NULL,
"force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n",
1098 forced_keyframe = 1;
1110 forced_keyframe = 1;
1113 if (forced_keyframe) {
1121 "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
1138 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
1150 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
1155 frame_size = pkt.
size;
1185 return -10.0 * log(d) / log(10.0);
1192 double ti1, bitrate, avg_bitrate;
1217 avg_bitrate = (double)(ost->
data_size * 8) / ti1 / 1000.0;
1218 fprintf(
vstats_file,
"s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
1219 (
double)ost->
data_size / 1024, ti1, bitrate, avg_bitrate);
1272 "Error in av_buffersink_get_frame_flags(): %s\n",
av_err2str(ret));
1294 float_pts +=
FFSIGN(float_pts) * 1.0 / (1<<17);
1296 filtered_frame->
pts =
1321 "Audio filter graph output is not normalized and encoder does not support parameter changes\n");
1340 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
1341 uint64_t subtitle_size = 0;
1342 uint64_t data_size = 0;
1343 float percent = -1.0;
1353 default: other_size += ost->
data_size;
break;
1362 if (data_size && total_size>0 && total_size >= data_size)
1363 percent = 100.0 * (total_size - data_size) / data_size;
1365 av_log(
NULL,
AV_LOG_INFO,
"video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ",
1366 video_size / 1024.0,
1367 audio_size / 1024.0,
1368 subtitle_size / 1024.0,
1369 other_size / 1024.0,
1370 extra_size / 1024.0);
1380 uint64_t total_packets = 0, total_size = 0;
1409 total_packets, total_size);
1414 uint64_t total_packets = 0, total_size = 0;
1443 total_packets, total_size);
1445 if(video_size + data_size + audio_size + subtitle_size + extra_size == 0){
1458 AVBPrint buf_script;
1463 int frame_number, vid, i;
1465 int64_t
pts = INT64_MIN;
1466 static int64_t last_time = -1;
1467 static int qp_histogram[52];
1468 int hours, mins, secs, us;
1470 if (!
print_stats && !is_last_report && !progress_avio)
1473 if (!is_last_report) {
1474 if (last_time == -1) {
1478 if ((cur_time - last_time) < 500000)
1484 oc = output_files[0]->
ctx;
1487 if (total_size <= 0)
1495 ost = output_streams[i];
1500 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"q=%2.1f ", q);
1501 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
1505 float fps, t = (cur_time-timer_start) / 1000000.0;
1508 fps = t > 1 ? frame_number / t : 0;
1509 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"frame=%5d fps=%3.*f q=%3.1f ",
1510 frame_number, fps < 9.95, fps, q);
1511 av_bprintf(&buf_script,
"frame=%d\n", frame_number);
1513 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
1516 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"L");
1522 for (j = 0; j < 32; j++)
1523 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%X", (
int)
lrintf(
log2(qp_histogram[j] + 1)));
1527 double error, error_sum = 0;
1528 double scale, scale_sum = 0;
1530 char type[3] = {
'Y',
'U',
'V' };
1531 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"PSNR=");
1532 for (j = 0; j < 3; j++) {
1533 if (is_last_report) {
1534 error = enc->
error[j];
1535 scale = enc->
width * enc->
height * 255.0 * 255.0 * frame_number;
1544 p =
psnr(error / scale);
1545 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%c:%2.2f ", type[j], p);
1546 av_bprintf(&buf_script,
"stream_%d_%d_psnr_%c=%2.2f\n",
1549 p =
psnr(error_sum / scale_sum);
1550 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"*:%2.2f ",
psnr(error_sum / scale_sum));
1551 av_bprintf(&buf_script,
"stream_%d_%d_psnr_all=%2.2f\n",
1571 bitrate = pts && total_size >= 0 ? total_size * 8 / (pts / 1000.0) : -1;
1573 if (total_size < 0)
snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
1575 else snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
1576 "size=%8.0fkB time=", total_size / 1024.0);
1578 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"-");
1579 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
1580 "%02d:%02d:%02d.%02d ", hours, mins, secs,
1584 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"bitrate=N/A");
1587 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"bitrate=%6.1fkbits/s", bitrate);
1588 av_bprintf(&buf_script,
"bitrate=%6.1fkbits/s\n", bitrate);
1591 if (total_size < 0)
av_bprintf(&buf_script,
"total_size=N/A\n");
1592 else av_bprintf(&buf_script,
"total_size=%"PRId64
"\n", total_size);
1593 av_bprintf(&buf_script,
"out_time_ms=%"PRId64
"\n", pts);
1594 av_bprintf(&buf_script,
"out_time=%02d:%02d:%02d.%06d\n",
1595 hours, mins, secs, us);
1598 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
" dup=%d drop=%d",
1604 const char end = is_last_report ?
'\n' :
'\r';
1606 fprintf(stderr,
"%s %c", buf, end);
1613 if (progress_avio) {
1615 is_last_report ?
"end" :
"continue");
1617 FFMIN(buf_script.len, buf_script.size - 1));
1620 if (is_last_report) {
1637 int stop_encoding = 0;
1673 ret = encode(enc, &pkt,
NULL, &got_packet);
1691 pkt_size = pkt.
size;
1779 opkt.
dts -= ost_tb_start_time;
1800 &opkt.data, &opkt.size,
1815 avpicture_fill(&pict, opkt.data, ost->st->codec->pix_fmt, ost->st->codec->width, ost->st->codec->height);
1829 char layout_name[256];
1848 int i,
ret, err = 0, resample_changed;
1866 if (*got_output || ret<0 || pkt->
size)
1869 if (!*got_output || ret < 0) {
1897 if (resample_changed) {
1898 char layout1[64], layout2[64];
1902 "layout for Input Stream #%d.%d\n", ist->
file_index,
1914 "Input stream #%d:%d frame changed from rate:%d fmt:%s ch:%d chl:%s to rate:%d fmt:%s ch:%d chl:%s\n",
1945 decoded_frame->
pts = pkt->
pts;
1948 decoded_frame->
pts = ist->
dts;
1956 for (i = 0; i < ist->nb_filters; i++) {
1957 if (i < ist->nb_filters - 1) {
1958 f = ist->filter_frame;
1975 return err < 0 ? err :
ret;
1981 int i,
ret = 0, err = 0, resample_changed;
1982 int64_t best_effort_timestamp;
1994 decoded_frame, got_output, pkt);
2005 "has_b_frames is larger in decoder than demuxer %d > %d ",
2011 if (*got_output || ret<0 || pkt->
size)
2014 if (*got_output && ret >= 0) {
2019 decoded_frame->
width,
2028 if (!*got_output || ret < 0) {
2058 "frame_pts:%s frame_pts_time:%s best_effort_ts:%"PRId64
" best_effort_ts_time:%s keyframe:%d frame_type:%d time_base:%d/%d\n",
2061 best_effort_timestamp,
2075 if (resample_changed) {
2077 "Input stream #%d:%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
2097 if (!frame_sample_aspect->
num)
2100 if (i < ist->nb_filters - 1) {
2110 }
else if (ret < 0) {
2112 "Failed to inject frame into filter network: %s\n",
av_err2str(ret));
2120 return err < 0 ? err :
ret;
2127 &subtitle, got_output, pkt);
2129 if (*got_output || ret<0 || pkt->
size)
2132 if (ret < 0 || !*got_output) {
2143 if (end < ist->prev_sub.subtitle.end_display_time) {
2145 "Subtitle duration reduced from %d to %d%s\n",
2147 end <= 0 ?
", dropping it" :
"");
2232 "Multiple frames in a packet from stream %d\n", pkt->
stream_index);
2283 if (got_output && !pkt)
2337 if (!strcmp(output_files[i]->ctx->oformat->name,
"rtp")) {
2338 avc[j] = output_files[i]->
ctx;
2346 printf(
"SDP:\n%s\n", sdp);
2365 if (
hwaccels[i].pix_fmt == pix_fmt)
2376 for (p = pix_fmts; *p != -1; p++) {
2389 ret = hwaccel->
init(s);
2393 "%s hwaccel requested for input stream #%d:%d, "
2394 "but cannot be initialized.\n", hwaccel->
name,
2426 snprintf(error, error_len,
"Decoder (codec %s) not found for input stream #%d:%d",
2441 av_log(
NULL,
AV_LOG_WARNING,
"Warning using DVB subtitles for filtering and output at the same time is not fully supported, also see -compute_edt [0|1]\n");
2451 "Error while opening decoder for input stream "
2474 int64_t va = *(int64_t *)a, vb = *(int64_t *)
b;
2475 return va < vb ? -1 : va > vb ? +1 : 0;
2485 for (p = kf; *p; p++)
2496 for (i = 0; i <
n; i++) {
2497 char *next = strchr(p,
',');
2502 if (!memcmp(p,
"chapters", 8)) {
2511 "Could not allocate forced key frames array.\n");
2543 InputFile *file = input_files[input_index];
2549 "New %s stream %d:%d at pos:%"PRId64
" and DTS:%ss\n",
2561 int encoder_string_len;
2562 int format_flags = 0;
2584 encoder_string =
av_mallocz(encoder_string_len);
2585 if (!encoder_string)
2591 av_strlcpy(encoder_string,
"Lavc ", encoder_string_len);
2599 int ret = 0, i, j, k;
2603 char error[1024] = {0};
2615 if (fg->
inputs[0]->
ist == input_streams[k])
2631 oc = output_files[i]->
ctx;
2648 ost = output_streams[i];
2676 uint64_t extra_size;
2682 if (extra_size > INT_MAX) {
2691 unsigned int codec_tag;
2740 if( copy_tb<0 && dec_ctx->time_base.den
2802 #if FF_API_AUDIOENC_DELAY
2820 "with stream copy may produce invalid files\n");
2846 snprintf(error,
sizeof(error),
"Encoder (codec %s) not found for output stream #%d:%d",
2880 "about the input framerate is available. Falling "
2881 "back to a default value of 25fps for output stream #%d:%d. Use the -r option "
2882 "if you want a different framerate.\n",
2897 switch (enc_ctx->codec_type) {
2903 enc_ctx->time_base = (
AVRational){ 1, enc_ctx->sample_rate };
2907 if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
2912 "Please consider specifying a lower framerate, a different muxer or -vsync 2\n");
2917 enc_ctx->time_base);
2925 if (!strncmp(ost->
enc->
name,
"libx264", 7) &&
2929 "No pixel format specified, %s for H.264 encoding chosen.\n"
2930 "Use -pix_fmt yuv420p for compatibility with outdated media players.\n",
2932 if (!strncmp(ost->
enc->
name,
"mpeg2video", 10) &&
2936 "No pixel format specified, %s for MPEG-2 encoding chosen.\n"
2937 "Use -pix_fmt yuv420p for compatibility with outdated media players.\n",
2973 if (!enc_ctx->width) {
2986 char logfilename[1024];
2989 snprintf(logfilename,
sizeof(logfilename),
"%s-%d.log",
2993 if (!strcmp(ost->
enc->
name,
"libx264")) {
2998 size_t logbuffer_size;
3004 enc_ctx->stats_in = logbuffer;
3010 logfilename, strerror(errno));
3019 if (ost->disposition) {
3021 {
"disposition" ,
NULL, 0,
AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
3037 static const AVClass class = {
3043 const AVClass *pclass = &
class;
3053 ost = output_streams[i];
3054 if (ost->encoding_needed) {
3063 if (!ost->enc_ctx->subtitle_header) {
3071 av_dict_set(&ost->encoder_opts,
"threads",
"auto", 0);
3072 av_dict_set(&ost->encoder_opts,
"side_data_only_packets",
"1", 0);
3077 snprintf(error,
sizeof(error),
"Error while opening encoder for output stream #%d:%d - maybe incorrect parameters such as bit_rate, rate, width or height",
3078 ost->file_index, ost->index);
3084 ost->enc_ctx->frame_size);
3086 if (ost->enc_ctx->bit_rate && ost->enc_ctx->bit_rate < 1000)
3088 " It takes bits/s as argument, not kbits/s\n");
3093 "Error initializing the output stream codec context.\n");
3099 ost->st->codec->codec= ost->enc_ctx->codec;
3104 "Error setting up codec context options.\n");
3116 ost = output_streams[i];
3140 oc = output_files[i]->
ctx;
3144 "Could not write header for output file #%d "
3145 "(incorrect codec parameters ?): %s",
3151 if (strcmp(oc->oformat->name,
"rtp")) {
3160 av_dump_format(output_files[i]->ctx, i, output_files[i]->ctx->filename, 1);
3166 ist = input_streams[i];
3168 for (j = 0; j < ist->nb_filters; j++) {
3169 if (ist->filters[j]->graph->graph_desc) {
3171 ist->file_index, ist->st->index, ist->dec ? ist->dec->name :
"?",
3172 ist->filters[j]->name);
3181 ost = output_streams[i];
3183 if (ost->attachment_filename) {
3186 ost->attachment_filename, ost->file_index, ost->index);
3190 if (ost->filter && ost->filter->graph->graph_desc) {
3197 ost->index, ost->enc ? ost->enc->name :
"?");
3202 input_streams[ost->source_index]->
file_index,
3203 input_streams[ost->source_index]->
st->
index,
3206 if (ost->sync_ist != input_streams[ost->source_index])
3208 ost->sync_ist->file_index,
3209 ost->sync_ist->st->index);
3210 if (ost->stream_copy)
3213 const AVCodec *in_codec = input_streams[ost->source_index]->
dec;
3214 const AVCodec *out_codec = ost->enc;
3215 const char *decoder_name =
"?";
3216 const char *in_codec_name =
"?";
3217 const char *encoder_name =
"?";
3218 const char *out_codec_name =
"?";
3222 decoder_name = in_codec->
name;
3225 in_codec_name = desc->
name;
3226 if (!strcmp(decoder_name, in_codec_name))
3227 decoder_name =
"native";
3231 encoder_name = out_codec->
name;
3234 out_codec_name = desc->
name;
3235 if (!strcmp(encoder_name, out_codec_name))
3236 encoder_name =
"native";
3240 in_codec_name, decoder_name,
3241 out_codec_name, encoder_name);
3294 int64_t opts_min = INT64_MAX;
3301 if (!ost->
finished && opts < opts_min) {
3312 static int64_t last_time;
3335 if (key ==
'c' || key ==
'C'){
3339 fprintf(stderr,
"\nEnter command: <target>|all <time>|-1 <command>[ <argument>]\n");
3341 while ((k =
read_key()) !=
'\n' && k !=
'\r' && i <
sizeof(buf)-1)
3346 (n = sscanf(buf,
"%63[^ ] %lf %255[^ ] %255[^\n]", target, &time, command, arg)) >= 3) {
3348 target, time, command, arg);
3355 fprintf(stderr,
"Command reply for stream %d: ret:%d res:\n%s", i, ret, buf);
3356 }
else if (key ==
'c') {
3357 fprintf(stderr,
"Queing commands only on filters supporting the specific command is unsupported\n");
3362 fprintf(stderr,
"Queing command failed with error %s\n",
av_err2str(ret));
3368 "Parse error, at least 3 arguments were expected, "
3369 "only %d given in string '%s'\n", n, buf);
3372 if (key ==
'd' || key ==
'D'){
3376 if(!debug) debug = 1;
3380 if(scanf(
"%d", &debug)!=1)
3381 fprintf(stderr,
"error parsing debug value\n");
3390 fprintf(stderr,
"debug=%d\n", debug);
3393 fprintf(stderr,
"key function\n"
3394 "? show this help\n"
3395 "+ increase verbosity\n"
3396 "- decrease verbosity\n"
3397 "c Send command to first matching filter supporting it\n"
3398 "C Send/Que command to all matching filters\n"
3399 "D cycle through available debug modes\n"
3400 "h dump packets/hex press to cycle through the 3 states\n"
3402 "s Show QP histogram\n"
3409 static void *input_thread(
void *
arg)
3429 if (flags && ret ==
AVERROR(EAGAIN)) {
3433 "Thread message queue blocking; consider raising the "
3434 "thread_queue_size option (current value: %d)\n",
3435 f->thread_queue_size);
3440 "Unable to send packet to main thread: %s\n",
3451 static void free_input_threads(
void)
3459 if (!f->in_thread_queue)
3471 static int init_input_threads(
void)
3475 if (nb_input_files == 1)
3483 f->non_blocking = 1;
3485 f->thread_queue_size,
sizeof(
AVPacket));
3490 av_log(
NULL,
AV_LOG_ERROR,
"pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
3520 if (nb_input_files > 1)
3521 return get_input_packet_mt(f, pkt);
3530 if (output_streams[i]->unavailable)
3539 input_files[i]->eagain = 0;
3541 output_streams[i]->unavailable = 0;
3553 InputFile *ifile = input_files[file_index];
3574 ist = input_streams[ifile->
ist_index + i];
3605 goto discard_packet;
3614 goto discard_packet;
3618 "next_dts:%s next_dts_time:%s next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%s off_time:%s\n",
3629 int64_t stime, stime2;
3636 int64_t new_start_time = INT64_MAX;
3680 memcpy(dst_data, src_sd->
data, src_sd->
size);
3704 "Inter stream timestamp discontinuity %"PRId64
", new offset= %"PRId64
"\n",
3724 "timestamp discontinuity %"PRId64
", new offset= %"PRId64
"\n",
3752 av_log(
NULL,
AV_LOG_INFO,
"demuxer+ffmpeg -> ist_index:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%s off_time:%s\n",
3786 int nb_requests, nb_requests_max = 0;
3804 for (i = 0; i < graph->
nb_inputs; i++) {
3805 ifilter = graph->
inputs[i];
3811 if (nb_requests > nb_requests_max) {
3812 nb_requests_max = nb_requests;
3878 int64_t timer_start;
3891 if ((ret = init_input_threads()) < 0)
3926 free_input_threads();
3931 ist = input_streams[i];
3942 os = output_files[i]->
ctx;
3951 ost = output_streams[i];
3959 ist = input_streams[i];
3972 free_input_threads();
3975 if (output_streams) {
3977 ost = output_streams[i];
4000 struct rusage rusage;
4002 getrusage(RUSAGE_SELF, &rusage);
4003 return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
4004 #elif HAVE_GETPROCESSTIMES
4006 FILETIME
c, e, k,
u;
4007 proc = GetCurrentProcess();
4008 GetProcessTimes(proc, &c, &e, &k, &u);
4009 return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
4017 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
4018 struct rusage rusage;
4019 getrusage(RUSAGE_SELF, &rusage);
4020 return (int64_t)rusage.ru_maxrss * 1024;
4021 #elif HAVE_GETPROCESSMEMORYINFO
4023 PROCESS_MEMORY_COUNTERS memcounters;
4024 proc = GetCurrentProcess();
4025 memcounters.cb =
sizeof(memcounters);
4026 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
4027 return memcounters.PeakPagefileUsage;
4044 setvbuf(stderr,
NULL,_IONBF,0);
4049 if(argc>1 && !strcmp(argv[1],
"-d")){
4073 if (nb_output_files <= 0 && nb_input_files == 0) {
4080 if (nb_output_files <= 0) {
4095 printf(
"bench: utime=%0.3fs\n", ti / 1000000.0);
unsigned int nb_chapters
Number of chapters in AVChapter array.
#define FF_DEBUG_DCT_COEFF
static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
int64_t first_dts
Timestamp corresponding to the last dts sync point.
int guess_input_channel_layout(InputStream *ist)
const struct AVCodec * codec
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static enum AVPixelFormat pix_fmt
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
int64_t avio_size(AVIOContext *s)
Get the filesize.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
int64_t av_frame_get_pkt_duration(const AVFrame *frame)
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
void av_free_packet(AVPacket *pkt)
Free a packet.
#define DECODING_FOR_FILTER
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define av_realloc_f(p, o, n)
This structure describes decoded (raw) audio or video data.
int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts)
Queue a command for one or more filter instances.
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
int x
top left corner of pict, undefined when pict is not set
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
#define FF_DEBUG_VIS_QP
only access through AVOptions from outside libavcodec
void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq, int err)
Set the receiving error code.
static void sub2video_flush(InputStream *ist)
uint64_t error[AV_NUM_DATA_POINTERS]
error
char * filters
filtergraph associated to the -filter option
#define CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
static int process_input(int file_index)
#define CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
Main libavfilter public API header.
int64_t pos
byte position in stream, -1 if unknown
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Memory buffer source API.
AVFrame * coded_frame
the picture in the bitstream
void av_log_set_level(int level)
Set the log level.
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
int h
agreed upon image height
AVCodecParserContext * parser
FILE * av_fopen_utf8(const char *path, const char *mode)
Open a file using a UTF-8 filename.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
FilterGraph * init_simple_filtergraph(InputStream *ist, OutputStream *ost)
static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time)
int index
stream index in AVFormatContext
static int64_t getmaxrss(void)
static InputStream * get_input_stream(OutputStream *ost)
#define AVIO_FLAG_WRITE
write-only
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
void show_banner(int argc, char **argv, const OptionDef *options)
Print the program banner to stderr.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
AVBitStreamFilterContext * bitstream_filters
static void abort_codec_experimental(AVCodec *c, int encoder)
static int transcode_init(void)
static int compare_int64(const void *a, const void *b)
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.
#define FF_ARRAY_ELEMS(a)
int av_usleep(unsigned usec)
Sleep for a period of time.
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
AVPacketSideData * side_data
An array of side data that applies to the whole stream (i.e.
int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of audio.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define FF_DEBUG_VIS_MB_TYPE
only access through AVOptions from outside libavcodec
void avcodec_register_all(void)
Register all the codecs, parsers and bitstream filters which were enabled at configuration time...
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
int av_dup_packet(AVPacket *pkt)
static void report_new_stream(int input_index, AVPacket *pkt)
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
Copy the settings of the source AVCodecContext into the destination AVCodecContext.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
int avpicture_fill(AVPicture *picture, const uint8_t *ptr, enum AVPixelFormat pix_fmt, int width, int height)
Setup the picture fields based on the specified image parameters and the provided image data buffer...
float dts_error_threshold
int64_t start_time
start time in microseconds == AV_TIME_BASE units
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
static int decode_interrupt_cb(void *ctx)
static int process_input_packet(InputStream *ist, const AVPacket *pkt)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
static void update_benchmark(const char *fmt,...)
static void log_callback_null(void *ptr, int level, const char *fmt, va_list vl)
static int check_keyboard_interaction(int64_t cur_time)
memory buffer sink API for audio and video
unsigned int nb_stream_indexes
#define AV_LOG_QUIET
Print no output.
#define CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
int w
width of pict, undefined when pict is not set
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVFilterLink ** inputs
array of pointers to input links
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static void do_video_out(AVFormatContext *s, OutputStream *ost, AVFrame *next_picture, double sync_ipts)
static uint8_t * subtitle_out
#define DEFAULT_PASS_LOGFILENAME_PREFIX
static int main_return_code
static int64_t start_time
int copy_initial_nonkeyframes
void register_exit(void(*cb)(int ret))
Register a program-specific cleanup routine.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Opaque data information usually continuous.
int av_thread_message_queue_recv(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Receive a message from the queue.
int av_parser_change(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
static void sub2video_push_ref(InputStream *ist, int64_t pts)
enum AVCodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the AVCodecID for the given codec tag tag.
miscellaneous OS support macros and functions.
timestamp utils, mostly useful for debugging/logging purposes
attribute_deprecated void(* destruct)(struct AVPacket *)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointers to the image data planes
static av_cold int end(AVCodecContext *avctx)
#define media_type_string
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
int av_thread_message_queue_send(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Send a message on the queue.
libavcodec/libavfilter gluing utilities
#define ECHO(name, type, min, max)
static const HWAccel * get_hwaccel(enum AVPixelFormat pix_fmt)
static int need_output(void)
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int nb_side_data
The number of elements in the AVStream.side_data array.
static double psnr(double d)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream ** streams
A list of all streams in the file.
int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
int av_codec_get_tag2(const struct AVCodecTag *const *tags, enum AVCodecID id, unsigned int *tag)
Get the codec tag for the given codec id.
void avfilter_register_all(void)
Initialize the filter system.
static int64_t getutime(void)
void av_pkt_dump_log2(void *avcl, int level, const AVPacket *pkt, int dump_payload, const AVStream *st)
Send a nice dump of a packet to the log.
int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
Add a frame to the buffer source.
static double av_q2d(AVRational a)
Convert rational to double.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
AVDictionary * resample_opts
static void parse_forced_key_frames(char *kf, OutputStream *ost, AVCodecContext *avctx)
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.
#define AVERROR_EOF
End of file.
static int read_key(void)
static int reap_filters(int flush)
Get and encode new output from any of the filtergraphs, without causing activity. ...
#define AV_LOG_VERBOSE
Detailed information.
int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size)
Generate an SDP for an RTP session.
static void do_video_stats(OutputStream *ost, int frame_size)
int interlaced_frame
The content of the picture is interlaced.
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the '-loglevel' option in the command line args and apply it.
const AVClass * avcodec_get_frame_class(void)
Get the AVClass for AVFrame.
int64_t av_frame_get_best_effort_timestamp(const AVFrame *frame)
Accessors for some AVFrame fields.
int h
height of pict, undefined when pict is not set
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
enum AVDiscard discard
selects which program to discard and which to feed to the caller
char * stats_out
pass1 encoding statistics output buffer
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
const OptionDef options[]
struct AVBitStreamFilterContext * next
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.