72 #if HAVE_SYS_RESOURCE_H
74 #include <sys/types.h>
75 #include <sys/resource.h>
76 #elif HAVE_GETPROCESSTIMES
79 #if HAVE_GETPROCESSMEMORYINFO
83 #if HAVE_SETCONSOLECTRLHANDLER
89 #include <sys/select.h>
94 #include <sys/ioctl.h>
156 static struct termios oldtty;
157 static int restore_tty;
161 static void free_input_threads(
void);
187 uint32_t *pal, *dst2;
195 if (r->
x < 0 || r->
x + r->
w > w || r->
y < 0 || r->
y + r->
h > h) {
197 r->
x, r->
y, r->
w, r->
h, w, h
202 dst += r->
y * dst_linesize + r->
x * 4;
205 for (y = 0; y < r->
h; y++) {
206 dst2 = (uint32_t *)dst;
208 for (x = 0; x < r->
w; x++)
209 *(dst2++) = pal[*(src2++)];
234 int64_t
pts, end_pts;
251 "Impossible to get a blank canvas.\n");
254 dst = frame->
data [0];
256 for (i = 0; i < num_rects; i++)
280 if (pts2 <= ist2->sub2video.last_pts)
284 for (j = 0, nb_reqs = 0; j < ist2->
nb_filters; j++)
307 tcsetattr (0, TCSANOW, &oldtty);
330 write(2,
"Received > 3 system signals, hard exiting\n",
331 strlen(
"Received > 3 system signals, hard exiting\n"));
337 #if HAVE_SETCONSOLECTRLHANDLER
338 static BOOL WINAPI CtrlHandler(
DWORD fdwCtrlType)
345 case CTRL_BREAK_EVENT:
349 case CTRL_CLOSE_EVENT:
350 case CTRL_LOGOFF_EVENT:
351 case CTRL_SHUTDOWN_EVENT:
378 if (istty && tcgetattr (0, &tty) == 0) {
382 tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
383 |INLCR|IGNCR|ICRNL|IXON);
384 tty.c_oflag |= OPOST;
385 tty.c_lflag &= ~(
ECHO|ECHONL|ICANON|IEXTEN);
386 tty.c_cflag &= ~(CSIZE|PARENB);
391 tcsetattr (0, TCSANOW, &tty);
402 #if HAVE_SETCONSOLECTRLHANDLER
403 SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler,
TRUE);
420 n = select(1, &rfds,
NULL,
NULL, &tv);
429 # if HAVE_PEEKNAMEDPIPE
431 static HANDLE input_handle;
434 input_handle = GetStdHandle(STD_INPUT_HANDLE);
435 is_pipe = !GetConsoleMode(input_handle, &dw);
440 if (!PeekNamedPipe(input_handle,
NULL, 0,
NULL, &nchars,
NULL)) {
542 free_input_threads();
632 ost2->
finished |= ost == ost2 ? this_stream : others;
697 if(a == 0 && new_pkt.
data != pkt->
data
705 memcpy(t, new_pkt.
data, new_pkt.
size);
723 av_log(NULL,
AV_LOG_ERROR,
"Failed to open bitstream filter %s for stream %d with codec %s",
739 av_log(s,
AV_LOG_WARNING,
"Invalid DTS: %"PRId64
" PTS: %"PRId64
" in output stream %d:%d, replacing by guess\n",
752 if (pkt->
dts < max) {
754 av_log(s, loglevel,
"Non-monotonous DTS in output stream "
755 "%d:%d; previous: %"PRId64
", current: %"PRId64
"; ",
761 av_log(s, loglevel,
"changing to %"PRId64
". This may result "
762 "in incorrect timestamps in the output file.\n",
779 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s size:%d\n",
844 "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
860 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
874 int subtitle_out_max_size = 1024 * 1024;
875 int subtitle_out_size, nb, i;
909 for (i = 0; i < nb; i++) {
910 unsigned save_num_rects = sub->
num_rects;
927 subtitle_out_max_size, sub);
930 if (subtitle_out_size < 0) {
937 pkt.
size = subtitle_out_size;
944 pkt.
pts += 90 * sub->start_display_time;
946 pkt.
pts += 90 * sub->end_display_time;
958 int ret, format_video_sync;
962 int nb_frames, nb0_frames, i;
963 double delta, delta0;
1021 double cor =
FFMIN(-delta0, duration);
1022 if (delta0 < -0.6) {
1031 switch (format_video_sync) {
1033 if (ost->
frame_number == 0 && delta - duration >= 0.5) {
1043 }
else if (delta < -1.1)
1045 else if (delta > 1.1) {
1046 nb_frames =
lrintf(delta);
1048 nb0_frames =
lrintf(delta0 - 0.6);
1054 else if (delta > 0.6)
1067 nb0_frames =
FFMIN(nb0_frames, nb_frames);
1077 "*** dropping frame %d from stream %d at ts %"PRId64
"\n",
1080 if (nb_frames > (nb0_frames && ost->
last_droped) + (nb_frames > nb0_frames)) {
1089 ost->
last_droped = nb_frames == nb0_frames && next_picture;
1092 for (i = 0; i < nb_frames; i++) {
1098 if (i < nb0_frames && ost->last_frame) {
1101 in_picture = next_picture;
1131 int got_packet, forced_keyframe = 0;
1154 forced_keyframe = 1;
1160 ff_dlog(
NULL,
"force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n",
1168 forced_keyframe = 1;
1180 forced_keyframe = 1;
1183 if (forced_keyframe) {
1191 "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
1208 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
1220 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
1225 frame_size = pkt.
size;
1257 return -10.0 * log(d) / log(10.0);
1264 double ti1, bitrate, avg_bitrate;
1278 fprintf(
vstats_file,
"frame= %5d q= %2.1f ", frame_number,
1291 avg_bitrate = (double)(ost->
data_size * 8) / ti1 / 1000.0;
1292 fprintf(
vstats_file,
"s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
1293 (
double)ost->
data_size / 1024, ti1, bitrate, avg_bitrate);
1346 "Error in av_buffersink_get_frame_flags(): %s\n",
av_err2str(ret));
1368 float_pts +=
FFSIGN(float_pts) * 1.0 / (1<<17);
1370 filtered_frame->
pts =
1395 "Audio filter graph output is not normalized and encoder does not support parameter changes\n");
1414 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
1415 uint64_t subtitle_size = 0;
1416 uint64_t data_size = 0;
1417 float percent = -1.0;
1427 default: other_size += ost->
data_size;
break;
1436 if (data_size && total_size>0 && total_size >= data_size)
1437 percent = 100.0 * (total_size - data_size) / data_size;
1439 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: ",
1440 video_size / 1024.0,
1441 audio_size / 1024.0,
1442 subtitle_size / 1024.0,
1443 other_size / 1024.0,
1444 extra_size / 1024.0);
1454 uint64_t total_packets = 0, total_size = 0;
1483 total_packets, total_size);
1488 uint64_t total_packets = 0, total_size = 0;
1517 total_packets, total_size);
1519 if(video_size + data_size + audio_size + subtitle_size + extra_size == 0){
1532 AVBPrint buf_script;
1537 int frame_number, vid, i;
1539 int64_t
pts = INT64_MIN;
1540 static int64_t last_time = -1;
1541 static int qp_histogram[52];
1542 int hours, mins, secs, us;
1544 if (!
print_stats && !is_last_report && !progress_avio)
1547 if (!is_last_report) {
1548 if (last_time == -1) {
1552 if ((cur_time - last_time) < 500000)
1558 oc = output_files[0]->
ctx;
1561 if (total_size <= 0)
1569 ost = output_streams[i];
1575 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"q=%2.1f ", q);
1576 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
1580 float fps, t = (cur_time-timer_start) / 1000000.0;
1583 fps = t > 1 ? frame_number / t : 0;
1584 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"frame=%5d fps=%3.*f q=%3.1f ",
1585 frame_number, fps < 9.95, fps, q);
1586 av_bprintf(&buf_script,
"frame=%d\n", frame_number);
1588 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
1591 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"L");
1597 for (j = 0; j < 32; j++)
1598 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%X", (
int)
lrintf(
log2(qp_histogram[j] + 1)));
1603 double error, error_sum = 0;
1604 double scale, scale_sum = 0;
1606 char type[3] = {
'Y',
'U',
'V' };
1607 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"PSNR=");
1608 for (j = 0; j < 3; j++) {
1609 if (is_last_report) {
1610 error = enc->
error[j];
1611 scale = enc->
width * enc->
height * 255.0 * 255.0 * frame_number;
1613 error = ost->
error[j];
1620 p =
psnr(error / scale);
1621 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"%c:%2.2f ", type[j], p);
1622 av_bprintf(&buf_script,
"stream_%d_%d_psnr_%c=%2.2f\n",
1625 p =
psnr(error_sum / scale_sum);
1626 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"*:%2.2f ",
psnr(error_sum / scale_sum));
1627 av_bprintf(&buf_script,
"stream_%d_%d_psnr_all=%2.2f\n",
1647 bitrate = pts && total_size >= 0 ? total_size * 8 / (pts / 1000.0) : -1;
1649 if (total_size < 0)
snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
1651 else snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
1652 "size=%8.0fkB time=", total_size / 1024.0);
1654 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"-");
1655 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
1656 "%02d:%02d:%02d.%02d ", hours, mins, secs,
1660 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"bitrate=N/A");
1663 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
"bitrate=%6.1fkbits/s", bitrate);
1664 av_bprintf(&buf_script,
"bitrate=%6.1fkbits/s\n", bitrate);
1667 if (total_size < 0)
av_bprintf(&buf_script,
"total_size=N/A\n");
1668 else av_bprintf(&buf_script,
"total_size=%"PRId64
"\n", total_size);
1669 av_bprintf(&buf_script,
"out_time_ms=%"PRId64
"\n", pts);
1670 av_bprintf(&buf_script,
"out_time=%02d:%02d:%02d.%06d\n",
1671 hours, mins, secs, us);
1674 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
" dup=%d drop=%d",
1680 const char end = is_last_report ?
'\n' :
'\r';
1682 fprintf(stderr,
"%s %c", buf, end);
1689 if (progress_avio) {
1691 is_last_report ?
"end" :
"continue");
1693 FFMIN(buf_script.len, buf_script.size - 1));
1696 if (is_last_report) {
1713 int stop_encoding = 0;
1749 ret = encode(enc, &pkt,
NULL, &got_packet);
1769 pkt_size = pkt.
size;
1857 opkt.
dts -= ost_tb_start_time;
1877 &opkt.data, &opkt.size,
1900 int ret =
avpicture_fill(&pict, opkt.data, ost->st->codec->pix_fmt, ost->st->codec->width, ost->st->codec->height);
1919 char layout_name[256];
1938 int i, ret, err = 0, resample_changed;
1956 if (*got_output || ret<0)
1962 if (!*got_output || ret < 0)
1981 if (resample_changed) {
1982 char layout1[64], layout2[64];
1986 "layout for Input Stream #%d.%d\n", ist->
file_index,
1998 "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",
2029 decoded_frame->
pts = pkt->
pts;
2032 decoded_frame->
pts = ist->
dts;
2040 for (i = 0; i < ist->nb_filters; i++) {
2041 if (i < ist->nb_filters - 1) {
2042 f = ist->filter_frame;
2059 return err < 0 ? err : ret;
2065 int i, ret = 0, err = 0, resample_changed;
2066 int64_t best_effort_timestamp;
2078 decoded_frame, got_output, pkt);
2088 "has_b_frames is larger in decoder than demuxer %d > %d.\n"
2089 "If you want to help, upload a sample "
2090 "of this file to ftp://upload.ffmpeg.org/incoming/ "
2091 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)",
2096 if (*got_output || ret<0)
2102 if (*got_output && ret >= 0) {
2107 decoded_frame->
width,
2116 if (!*got_output || ret < 0)
2137 "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",
2140 best_effort_timestamp,
2154 if (resample_changed) {
2156 "Input stream #%d:%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
2176 if (!frame_sample_aspect->
num)
2179 if (i < ist->nb_filters - 1) {
2189 }
else if (ret < 0) {
2191 "Failed to inject frame into filter network: %s\n",
av_err2str(ret));
2199 return err < 0 ? err : ret;
2206 &subtitle, got_output, pkt);
2208 if (*got_output || ret<0)
2214 if (ret < 0 || !*got_output) {
2225 if (end < ist->prev_sub.subtitle.end_display_time) {
2227 "Subtitle duration reduced from %d to %d%s\n",
2229 end <= 0 ?
", dropping it" :
"");
2325 "Multiple frames in a packet from stream %d\n", pkt->
stream_index);
2381 if (got_output && !pkt)
2444 if (!strcmp(output_files[i]->ctx->oformat->name,
"rtp")) {
2445 avc[j] = output_files[i]->
ctx;
2453 printf(
"SDP:\n%s\n", sdp);
2472 if (
hwaccels[i].pix_fmt == pix_fmt)
2483 for (p = pix_fmts; *p != -1; p++) {
2496 ret = hwaccel->
init(s);
2500 "%s hwaccel requested for input stream #%d:%d, "
2501 "but cannot be initialized.\n", hwaccel->
name,
2533 snprintf(error, error_len,
"Decoder (codec %s) not found for input stream #%d:%d",
2548 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");
2558 "Error while opening decoder for input stream "
2581 int64_t va = *(int64_t *)a, vb = *(int64_t *)
b;
2582 return va < vb ? -1 : va > vb ? +1 : 0;
2617 "Error while opening encoder for output stream #%d:%d - "
2618 "maybe incorrect parameters such as bit_rate, rate, width or height",
2629 " It takes bits/s as argument, not kbits/s\n");
2634 "Error initializing the output stream codec context.\n");
2645 "Error setting up codec context options.\n");
2662 for (p = kf; *p; p++)
2673 for (i = 0; i <
n; i++) {
2674 char *next = strchr(p,
',');
2679 if (!memcmp(p,
"chapters", 8)) {
2688 "Could not allocate forced key frames array.\n");
2720 InputFile *file = input_files[input_index];
2726 "New %s stream %d:%d at pos:%"PRId64
" and DTS:%ss\n",
2738 int encoder_string_len;
2739 int format_flags = 0;
2761 encoder_string =
av_mallocz(encoder_string_len);
2762 if (!encoder_string)
2768 av_strlcpy(encoder_string,
"Lavc ", encoder_string_len);
2776 int ret = 0, i, j, k;
2780 char error[1024] = {0};
2792 if (fg->
inputs[0]->
ist == input_streams[k])
2810 ost = output_streams[i];
2838 uint64_t extra_size;
2844 if (extra_size > INT_MAX) {
2853 unsigned int codec_tag;
2902 if( copy_tb<0 && dec_ctx->time_base.den
2964 #if FF_API_AUDIOENC_DELAY
2982 "with stream copy may produce invalid files\n");
3008 snprintf(error,
sizeof(error),
"Encoder (codec %s) not found for output stream #%d:%d",
3038 "about the input framerate is available. Falling "
3039 "back to a default value of 25fps for output stream #%d:%d. Use the -r option "
3040 "if you want a different framerate.\n",
3055 switch (enc_ctx->codec_type) {
3061 enc_ctx->time_base = (
AVRational){ 1, enc_ctx->sample_rate };
3065 if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
3070 "Please consider specifying a lower framerate, a different muxer or -vsync 2\n");
3075 enc_ctx->time_base);
3083 if (!strncmp(ost->
enc->
name,
"libx264", 7) &&
3087 "No pixel format specified, %s for H.264 encoding chosen.\n"
3088 "Use -pix_fmt yuv420p for compatibility with outdated media players.\n",
3090 if (!strncmp(ost->
enc->
name,
"mpeg2video", 10) &&
3094 "No pixel format specified, %s for MPEG-2 encoding chosen.\n"
3095 "Use -pix_fmt yuv420p for compatibility with outdated media players.\n",
3131 if (!enc_ctx->width) {
3144 if (ost->disposition) {
3146 {
"disposition" ,
NULL, 0,
AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
3162 static const AVClass class = {
3168 const AVClass *pclass = &
class;
3170 ret =
av_opt_eval_flags(&pclass, &opts[0], ost->disposition, &ost->st->disposition);
3187 ost = output_streams[i];
3211 oc = output_files[i]->
ctx;
3215 "Could not write header for output file #%d "
3216 "(incorrect codec parameters ?): %s",
3222 if (strcmp(oc->oformat->name,
"rtp")) {
3231 av_dump_format(output_files[i]->ctx, i, output_files[i]->ctx->filename, 1);
3237 ist = input_streams[i];
3239 for (j = 0; j < ist->nb_filters; j++) {
3240 if (ist->filters[j]->graph->graph_desc) {
3242 ist->file_index, ist->st->index, ist->dec ? ist->dec->name :
"?",
3243 ist->filters[j]->name);
3252 ost = output_streams[i];
3254 if (ost->attachment_filename) {
3257 ost->attachment_filename, ost->file_index, ost->index);
3261 if (ost->filter && ost->filter->graph->graph_desc) {
3268 ost->index, ost->enc ? ost->enc->name :
"?");
3273 input_streams[ost->source_index]->
file_index,
3274 input_streams[ost->source_index]->
st->
index,
3277 if (ost->sync_ist != input_streams[ost->source_index])
3279 ost->sync_ist->file_index,
3280 ost->sync_ist->st->index);
3281 if (ost->stream_copy)
3284 const AVCodec *in_codec = input_streams[ost->source_index]->
dec;
3285 const AVCodec *out_codec = ost->enc;
3286 const char *decoder_name =
"?";
3287 const char *in_codec_name =
"?";
3288 const char *encoder_name =
"?";
3289 const char *out_codec_name =
"?";
3293 decoder_name = in_codec->
name;
3296 in_codec_name = desc->
name;
3297 if (!strcmp(decoder_name, in_codec_name))
3298 decoder_name =
"native";
3302 encoder_name = out_codec->
name;
3305 out_codec_name = desc->
name;
3306 if (!strcmp(encoder_name, out_codec_name))
3307 encoder_name =
"native";
3311 in_codec_name, decoder_name,
3312 out_codec_name, encoder_name);
3365 int64_t opts_min = INT64_MAX;
3372 if (!ost->
finished && opts < opts_min) {
3383 static int64_t last_time;
3406 if (key ==
'c' || key ==
'C'){
3410 fprintf(stderr,
"\nEnter command: <target>|all <time>|-1 <command>[ <argument>]\n");
3412 while ((k =
read_key()) !=
'\n' && k !=
'\r' && i <
sizeof(buf)-1)
3417 (n = sscanf(buf,
"%63[^ ] %lf %255[^ ] %255[^\n]", target, &time, command, arg)) >= 3) {
3419 target, time, command, arg);
3426 fprintf(stderr,
"Command reply for stream %d: ret:%d res:\n%s", i, ret, buf);
3427 }
else if (key ==
'c') {
3428 fprintf(stderr,
"Queing commands only on filters supporting the specific command is unsupported\n");
3433 fprintf(stderr,
"Queing command failed with error %s\n",
av_err2str(ret));
3439 "Parse error, at least 3 arguments were expected, "
3440 "only %d given in string '%s'\n", n, buf);
3443 if (key ==
'd' || key ==
'D'){
3447 if(!debug) debug = 1;
3454 while ((k =
read_key()) !=
'\n' && k !=
'\r' && i <
sizeof(buf)-1)
3458 if (k <= 0 || sscanf(buf,
"%d", &debug)!=1)
3459 fprintf(stderr,
"error parsing debug value\n");
3469 fprintf(stderr,
"debug=%d\n", debug);
3472 fprintf(stderr,
"key function\n"
3473 "? show this help\n"
3474 "+ increase verbosity\n"
3475 "- decrease verbosity\n"
3476 "c Send command to first matching filter supporting it\n"
3477 "C Send/Que command to all matching filters\n"
3478 "D cycle through available debug modes\n"
3479 "h dump packets/hex press to cycle through the 3 states\n"
3481 "s Show QP histogram\n"
3488 static void *input_thread(
void *
arg)
3508 if (flags && ret ==
AVERROR(EAGAIN)) {
3512 "Thread message queue blocking; consider raising the "
3513 "thread_queue_size option (current value: %d)\n",
3514 f->thread_queue_size);
3519 "Unable to send packet to main thread: %s\n",
3530 static void free_input_threads(
void)
3538 if (!f || !f->in_thread_queue)
3550 static int init_input_threads(
void)
3554 if (nb_input_files == 1)
3562 f->non_blocking = 1;
3564 f->thread_queue_size,
sizeof(
AVPacket));
3569 av_log(
NULL,
AV_LOG_ERROR,
"pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
3599 if (nb_input_files > 1)
3600 return get_input_packet_mt(f, pkt);
3609 if (output_streams[i]->unavailable)
3618 input_files[i]->eagain = 0;
3620 output_streams[i]->unavailable = 0;
3632 InputFile *ifile = input_files[file_index];
3653 ist = input_streams[ifile->
ist_index + i];
3684 goto discard_packet;
3693 goto discard_packet;
3697 "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",
3708 int64_t stime, stime2;
3715 int64_t new_start_time = INT64_MAX;
3759 memcpy(dst_data, src_sd->
data, src_sd->
size);
3783 "Inter stream timestamp discontinuity %"PRId64
", new offset= %"PRId64
"\n",
3803 "timestamp discontinuity %"PRId64
", new offset= %"PRId64
"\n",
3831 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",
3859 int nb_requests, nb_requests_max = 0;
3877 for (i = 0; i < graph->
nb_inputs; i++) {
3878 ifilter = graph->
inputs[i];
3884 if (nb_requests > nb_requests_max) {
3885 nb_requests_max = nb_requests;
3951 int64_t timer_start;
3964 if ((ret = init_input_threads()) < 0)
3999 free_input_threads();
4004 ist = input_streams[i];
4015 os = output_files[i]->
ctx;
4024 ost = output_streams[i];
4032 ist = input_streams[i];
4045 free_input_threads();
4048 if (output_streams) {
4050 ost = output_streams[i];
4074 struct rusage rusage;
4076 getrusage(RUSAGE_SELF, &rusage);
4077 return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
4078 #elif HAVE_GETPROCESSTIMES
4080 FILETIME
c, e, k,
u;
4081 proc = GetCurrentProcess();
4082 GetProcessTimes(proc, &c, &e, &k, &u);
4083 return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
4091 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
4092 struct rusage rusage;
4093 getrusage(RUSAGE_SELF, &rusage);
4094 return (int64_t)rusage.ru_maxrss * 1024;
4095 #elif HAVE_GETPROCESSMEMORYINFO
4097 PROCESS_MEMORY_COUNTERS memcounters;
4098 proc = GetCurrentProcess();
4099 memcounters.cb =
sizeof(memcounters);
4100 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
4101 return memcounters.PeakPagefileUsage;
4118 setvbuf(stderr,
NULL,_IONBF,0);
4123 if(argc>1 && !strcmp(argv[1],
"-d")){
4147 if (nb_output_files <= 0 && nb_input_files == 0) {
4154 if (nb_output_files <= 0) {
unsigned int nb_chapters
Number of chapters in AVChapter array.
#define AV_CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
#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 flush(AVCodecContext *avctx)
static void sub2video_flush(InputStream *ist)
uint64_t error[AV_NUM_DATA_POINTERS]
error
char * filters
filtergraph associated to the -filter option
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
static int process_input(int file_index)
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_output_stream(OutputStream *ost, char *error, int error_len)
#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.
Memory buffer source API.
void av_log_set_level(int level)
Set the log level.
int h
agreed upon image height
AVCodecParserContext * parser
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.
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.
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...
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
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
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.
Keep a reference to the frame.
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.
static volatile int ffmpeg_exited
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.
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.
unsigned int * stream_index
static void sub2video_heartbeat(InputStream *ist, int64_t pts)
int ist_in_filtergraph(FilterGraph *fg, InputStream *ist)
#define AV_BUFFERSINK_FLAG_NO_REQUEST
Tell av_buffersink_get_buffer_ref() not to request a frame from its input.
struct AVOutputFormat * oformat
The output container format.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
AVRational av_add_q(AVRational b, AVRational c)
Add two rationals.
void av_buffer_default_free(void *opaque, uint8_t *data)
Default free callback, which calls av_free() on the buffer data.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base.
Main libavdevice API header.
Callback for checking whether to abort blocking functions.
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
static volatile int transcode_init_done
libswresample public header
const AVCodecDefault * defaults
Private codec-specific defaults.
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
int has_b_frames
Size of the frame reordering buffer in the decoder.
static void finish_output_stream(OutputStream *ost)
static void reset_eagain(void)
static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
void * av_opt_ptr(const AVClass *class, void *obj, const char *name)
Gets a pointer to the requested field in a struct.
void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another...
int ffmpeg_parse_options(int argc, char **argv)
FilterGraph ** filtergraphs
const AVIOInterruptCB int_cb
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown; if left to 0/0, will be automatically be cop...
int sample_rate
samples per second
int y
top left corner of pict, undefined when pict is not set
int av_opt_eval_flags(void *obj, const AVOption *o, const char *val, int *flags_out)
static int64_t decode_error_stat[2]
int avfilter_link_get_channels(AVFilterLink *link)
Get the number of channels of a link.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
const char *const forced_keyframes_const_names[]
int capabilities
Codec capabilities.
int initial_padding
Audio only.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_bitstream_filter_close(AVBitStreamFilterContext *bsf)
Release bitstream filter context.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
preferred ID for decoding MPEG audio layer 1, 2 or 3
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
int flags
AV_CODEC_FLAG_*.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
#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...
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
int rc_max_rate
maximum bitrate
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
simple assert() macros that are a bit more flexible than ISO C assert().
enum AVPacketSideDataType type
int av_log_get_level(void)
Get the current log level.
const char * name
Name of the codec implementation.
static int check_recording_time(OutputStream *ost)
int(* init)(AVCodecContext *s)
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
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.
void remove_avoptions(AVDictionary **a, AVDictionary *b)
AVRational avg_frame_rate
Average framerate.
New fields can be added to the end with minor version bumps.
int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
Get a frame with filtered data from sink and put it in frame.
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.
float frame_drop_threshold
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
int flags
A combination of AV_PKT_FLAG values.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
uint64_t channel_layout
Audio channel layout.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare 2 timestamps each in its own timebases.
uint32_t end_display_time
int64_t pts
Same as packet pts, in AV_TIME_BASE.
AVCodecContext * codec
Codec context associated with this stream.
int rc_buffer_size
decoder bitstream buffer size
uint64_t channel_layout
Channel layout of the audio data.
int w
agreed upon image width
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
AVRational frame_aspect_ratio
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
common internal API header
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
static int nb_frames_drop
A bitmap, pict will be set.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int bit_rate
the average bitrate
int void avio_flush(AVIOContext *s)
Force flushing of buffered data.
audio channel layout utility functions
enum AVPictureType pict_type
Picture type of the frame.
static int transcode(void)
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
char filename[1024]
input or output filename
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
AVPicture pict
data+linesize for the bitmap of this subtitle.
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.
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
This side data contains quality related information from the encoder.
static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
struct OutputStream * ost
int width
picture width / height.
double forced_keyframes_expr_const_values[FKF_NB]
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
void av_parser_close(AVCodecParserContext *s)
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, const AVPacket *avpkt)
Decode the audio frame of size avpkt->size from avpkt->data into frame.
static void term_exit_sigsafe(void)
int audio_channels_mapped
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
#define AVFILTER_CMD_FLAG_ONE
Stop once a filter understood the command (for target=all for example), fast filters are favored auto...
Usually treated as AVMEDIA_TYPE_DATA.
Opaque data information usually sparse.
#define FF_API_DESTRUCT_PACKET
static uint32_t codec_flags(enum AVCodecID codec_id)
const char program_name[]
program name, defined by the program for show_version().
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
static int got_eagain(void)
preferred ID for MPEG-1/2 video decoding
static void sub2video_update(InputStream *ist, AVSubtitle *sub)
int av_find_nearest_q_idx(AVRational q, const AVRational *q_list)
Find the nearest value in q_list to q.
int format
agreed upon media format
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it...
#define FF_ARRAY_ELEMS(a)
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
int av_packet_split_side_data(AVPacket *pkt)
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
int frame_size
Number of samples per channel in an audio frame.
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
static int sub2video_get_blank_frame(InputStream *ist)
static void set_encoder_id(OutputFile *of, OutputStream *ost)
#define AV_LOG_INFO
Standard information.
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)
Filter bitstream.
AVCodecParserContext * av_parser_init(int codec_id)
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
enum AVMediaType codec_type
void av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq, int err)
Set the sending error code.
const AVRational * supported_framerates
array of supported framerates, or NULL if any, array is terminated by {0,0}
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
static int init_input_stream(int ist_index, char *error, int error_len)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
static void sub2video_copy_rect(uint8_t *dst, int dst_linesize, int w, int h, AVSubtitleRect *r)
int sample_rate
samples per second
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output)
AVIOContext * pb
I/O context.
int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb)
Rescale a timestamp while preserving known durations.
static void print_sdp(void)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
main external API structure.
static void ffmpeg_cleanup(int ret)
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
const char * attachment_filename
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
static int check_output_constraints(InputStream *ist, OutputStream *ost)
int avfilter_graph_request_oldest(AVFilterGraph *graph)
Request a frame on the oldest sink link.
a very simple circular buffer FIFO implementation
void assert_avoptions(AVDictionary *m)
Perform non-blocking operation.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Replacements for frequently missing libm functions.
struct AVBitStreamFilter * filter
static int transcode_from_filter(FilterGraph *graph, InputStream **best_ist)
Perform a step of transcoding for the specified filter graph.
#define VSYNC_PASSTHROUGH
Describe the class of an AVClass context structure.
int sample_rate
Sample rate of the audio data.
int configure_filtergraph(FilterGraph *fg)
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
callback to negotiate the pixelFormat
int av_frame_get_channels(const AVFrame *frame)
OutputStream ** output_streams
#define AV_CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time...
rational number numerator/denominator
int av_thread_message_queue_alloc(AVThreadMessageQueue **mq, unsigned nelem, unsigned elsize)
Allocate a new message queue.
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...
discard useless packets like 0 size packets in avi
static av_always_inline av_const long int lrint(double x)
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.
int(* get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags)
This callback is called at the beginning of each frame to get data buffer(s) for it.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
const char * name
Name of the codec described by this descriptor.
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
int frame_bits_per_raw_sample
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src)
Get the number of failed requests.
static void do_subtitle_out(AVFormatContext *s, OutputStream *ost, InputStream *ist, AVSubtitle *sub)
static int transcode_step(void)
Run a single step of transcoding.
char * filters_script
filtergraph script associated to the -filter_script option
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame)
Add a frame to the buffer source.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
static enum AVPixelFormat pix_fmts[]
AVRational av_buffersink_get_frame_rate(AVFilterContext *ctx)
Get the frame rate of the input.
This struct describes the properties of a single codec described by an AVCodecID. ...
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
static volatile int received_nb_signals
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int global_quality
Global quality for codecs which cannot change it per frame.
static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, OSTFinished others)
static int64_t pts
Global timestamp for the audio frames.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
void av_thread_message_queue_free(AVThreadMessageQueue **mq)
Free a message queue.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts)
enum AVMediaType type
filter media type
int64_t start_time
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.
AVExpr * forced_keyframes_pexpr
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
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...
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
struct FilterGraph * graph
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static void print_final_stats(int64_t total_size)
#define FF_DISABLE_DEPRECATION_WARNINGS
AVIOContext * progress_avio
int main(int argc, char **argv)
void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
Set the frame size for an audio buffer sink.
#define AV_CODEC_CAP_PARAM_CHANGE
Codec supports changed parameters at any point.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
int disposition
AV_DISPOSITION_* bit field.
static AVCodecContext * dec_ctx
uint32_t start_display_time
int pts_wrap_bits
number of bits in pts (used for wrapping control)
AVRational time_base
time base in which the start/end timestamps are specified
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
int thread_safe_callbacks
Set by the client if its custom get_buffer() callback can be called synchronously from another thread...
int64_t nb_frames
number of frames in this stream if known or 0
static FILE * vstats_file
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents...
int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags)
Send a command to one or more filter instances.
struct AVInputFormat * iformat
The input container format.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static void do_audio_out(AVFormatContext *s, OutputStream *ost, AVFrame *frame)
#define FF_ENABLE_DEPRECATION_WARNINGS
int top_field_first
If the content is interlaced, is top field displayed first.
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
float dts_delta_threshold
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
int channels
number of audio channels
static int get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
void av_log_set_flags(int arg)
Immediately push the frame to the output.
int key_frame
1 -> keyframe, 0-> not
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
AVDictionary * encoder_opts
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
const int program_birth_year
program birth year, defined by the program for show_banner()
int repeat_pict
This field is used for proper frame duration computation in lavf.
enum AVFieldOrder field_order
Field order.
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
static int send_filter_eof(InputStream *ist)
OutputFile ** output_files
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
#define av_malloc_array(a, b)
static void flush_encoders(void)
static volatile int received_sigterm
#define FFSWAP(type, a, b)
static int get_input_packet(InputFile *f, AVPacket *pkt)
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
int av_copy_packet_side_data(AVPacket *dst, const AVPacket *src)
Copy packet side data.
AVRational r_frame_rate
Real base framerate of the stream.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
AVPixelFormat
Pixel format.
This structure stores compressed data.
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
static OutputStream * choose_output(void)
Select the output stream to process.
int nb_samples
number of audio samples (per channel) described by this frame
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void sigterm_handler(int sig)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void * opaque
Private data of the user, can be used to carry app specific stuff.
#define AV_NOPTS_VALUE
Undefined timestamp value.
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
InputStream ** input_streams
static void close_output_stream(OutputStream *ost)
uint8_t * subtitle_header
Header containing style information for text subtitles.