Go to the documentation of this file.
33 #include <stdatomic.h>
74 #if HAVE_SYS_RESOURCE_H
76 #include <sys/types.h>
77 #include <sys/resource.h>
78 #elif HAVE_GETPROCESSTIMES
81 #if HAVE_GETPROCESSMEMORYINFO
85 #if HAVE_SETCONSOLECTRLHANDLER
91 #include <sys/select.h>
96 #include <sys/ioctl.h>
155 static struct termios oldtty;
156 static int restore_tty;
182 uint32_t *pal, *dst2;
190 if (
r->x < 0 ||
r->x +
r->w >
w ||
r->y < 0 ||
r->y +
r->h >
h) {
192 r->x,
r->y,
r->w,
r->h,
w,
h
197 dst +=
r->y * dst_linesize +
r->x * 4;
199 pal = (uint32_t *)
r->data[1];
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++)];
206 src +=
r->linesize[0];
234 int64_t
pts, end_pts;
243 num_rects =
sub->num_rects;
256 "Impossible to get a blank canvas.\n");
259 dst =
frame->data [0];
260 dst_linesize =
frame->linesize[0];
261 for (
i = 0;
i < num_rects;
i++)
286 if (pts2 <= ist2->sub2video.last_pts)
293 for (j = 0, nb_reqs = 0; j < ist2->
nb_filters; j++)
320 tcsetattr (0, TCSANOW, &oldtty);
345 ret = write(2,
"Received > 3 system signals, hard exiting\n",
346 strlen(
"Received > 3 system signals, hard exiting\n"));
352 #if HAVE_SETCONSOLECTRLHANDLER
353 static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
360 case CTRL_BREAK_EVENT:
364 case CTRL_CLOSE_EVENT:
365 case CTRL_LOGOFF_EVENT:
366 case CTRL_SHUTDOWN_EVENT:
385 #define SIGNAL(sig, func) \
387 action.sa_handler = func; \
388 sigaction(sig, &action, NULL); \
391 #define SIGNAL(sig, func) \
397 #if defined __linux__
398 struct sigaction action = {0};
402 sigfillset(&action.sa_mask);
405 action.sa_flags = SA_RESTART;
411 if (tcgetattr (0, &tty) == 0) {
415 tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
416 |INLCR|IGNCR|ICRNL|IXON);
417 tty.c_oflag |= OPOST;
418 tty.c_lflag &= ~(
ECHO|ECHONL|ICANON|IEXTEN);
419 tty.c_cflag &= ~(CSIZE|PARENB);
424 tcsetattr (0, TCSANOW, &tty);
436 signal(SIGPIPE, SIG_IGN);
438 #if HAVE_SETCONSOLECTRLHANDLER
439 SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
456 n = select(1, &rfds,
NULL,
NULL, &tv);
465 # if HAVE_PEEKNAMEDPIPE
467 static HANDLE input_handle;
470 input_handle = GetStdHandle(STD_INPUT_HANDLE);
471 is_pipe = !GetConsoleMode(input_handle, &dw);
476 if (!PeekNamedPipe(input_handle,
NULL, 0,
NULL, &nchars,
NULL)) {
561 "Error closing vstats file, loss of information possible: %s\n",
591 int ost_idx = prev ? prev->
index + 1 : 0;
607 int ist_idx = prev ? prev->
st->
index + 1 : 0;
612 return f->streams[ist_idx];
655 "bench: %8" PRIu64
" user %8" PRIu64
" sys %8" PRIu64
" real %s \n",
669 if (
ost->sq_idx_encode >= 0)
707 float_pts +=
FFSIGN(float_pts) * 1.0 / (1<<17);
711 frame->time_base = enc->time_base;
720 enc ? enc->time_base.num : -1,
721 enc ? enc->time_base.den : -1);
728 char *
error,
int error_len);
734 char error[1024] = {0};
736 if (
ost->initialized)
753 return -10.0 * log10(
d);
761 int64_t frame_number;
762 double ti1,
bitrate, avg_bitrate;
786 frame_number =
ost->packets_encoded;
788 fprintf(
vstats_file,
"frame= %5"PRId64
" q= %2.1f ", frame_number,
791 fprintf(
vstats_file,
"out= %2d st= %2d frame= %5"PRId64
" q= %2.1f ",
ost->file_index,
ost->
index, frame_number,
805 avg_bitrate = (
double)(
ost->data_size_enc * 8) / ti1 / 1000.0;
806 fprintf(
vstats_file,
"s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
807 (
double)
ost->data_size_enc / 1024, ti1,
bitrate, avg_bitrate);
820 int64_t ptsi = INT64_MAX;
882 const char *action =
frame ?
"encode" :
"flush";
886 if (
ost->enc_stats_pre.io)
888 ost->frames_encoded);
890 ost->frames_encoded++;
891 ost->samples_encoded +=
frame->nb_samples;
895 "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
928 }
else if (
ret < 0) {
935 if (
ost->enc_stats_post.io)
937 ost->packets_encoded);
941 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s "
942 "duration:%s duration_time:%s\n",
954 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s "
955 "duration:%s duration_time:%s\n",
964 "Subtitle heartbeat logic failed in %s! (%s)\n",
971 ost->packets_encoded++;
984 if (
ost->sq_idx_encode < 0)
1010 }
else if (
ret < 0) {
1055 int subtitle_out_max_size = 1024 * 1024;
1056 int subtitle_out_size, nb,
i,
ret;
1082 for (
i = 0;
i < nb;
i++) {
1083 unsigned save_num_rects =
sub->num_rects;
1095 sub->end_display_time -=
sub->start_display_time;
1096 sub->start_display_time = 0;
1100 ost->frames_encoded++;
1104 sub->num_rects = save_num_rects;
1105 if (subtitle_out_size < 0) {
1134 int64_t *nb_frames, int64_t *nb_frames_prev)
1136 double delta0,
delta;
1141 delta0 = sync_ipts -
ost->next_pts;
1146 *nb_frames_prev = 0;
1154 if (delta0 < -0.6) {
1158 sync_ipts =
ost->next_pts;
1163 switch (
ost->vsync_method) {
1165 if (
ost->vsync_frame_number == 0 && delta0 >= 0.5) {
1175 }
else if (
delta < -1.1)
1177 else if (
delta > 1.1) {
1180 *nb_frames_prev =
llrintf(delta0 - 0.6);
1187 else if (
delta > 0.6)
1214 goto force_keyframe;
1215 }
else if (kf->
pexpr) {
1220 ff_dlog(
NULL,
"force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n",
1234 goto force_keyframe;
1237 in_picture->
key_frame == 1 && !dup_idx) {
1238 goto force_keyframe;
1242 goto force_keyframe;
1260 int64_t nb_frames, nb_frames_prev,
i;
1268 if (frame_rate.
num > 0 && frame_rate.
den > 0)
1274 if (!
ost->filters_script &&
1283 if (!next_picture) {
1285 nb_frames_prev = nb_frames =
mid_pred(
ost->last_nb0_frames[0],
1286 ost->last_nb0_frames[1],
1287 ost->last_nb0_frames[2]);
1290 &nb_frames, &nb_frames_prev);
1293 memmove(
ost->last_nb0_frames + 1,
1294 ost->last_nb0_frames,
1296 ost->last_nb0_frames[0] = nb_frames_prev;
1298 if (nb_frames_prev == 0 &&
ost->last_dropped) {
1301 "*** dropping frame %"PRId64
" at ts %"PRId64
"\n",
1302 ost->vsync_frame_number,
ost->last_frame->pts);
1304 if (nb_frames > (nb_frames_prev &&
ost->last_dropped) + (nb_frames > nb_frames_prev)) {
1310 nb_frames_dup += nb_frames - (nb_frames_prev &&
ost->last_dropped) - (nb_frames > nb_frames_prev);
1317 ost->last_dropped = nb_frames == nb_frames_prev && next_picture;
1318 ost->kf.dropped_keyframe =
ost->last_dropped && next_picture && next_picture->key_frame;
1321 for (
i = 0;
i < nb_frames;
i++) {
1324 if (i < nb_frames_prev && ost->last_frame->buf[0]) {
1325 in_picture =
ost->last_frame;
1327 in_picture = next_picture;
1332 in_picture->
pts =
ost->next_pts;
1347 ost->vsync_frame_number++;
1372 if (!
ost->filter || !
ost->filter->graph->graph)
1388 filtered_frame =
ost->filtered_frame;
1396 "Error in av_buffersink_get_frame_flags(): %s\n",
av_err2str(
ret));
1403 if (
ost->finished) {
1423 if (!
ost->frame_aspect_ratio.num)
1432 "Audio filter graph output is not normalized and encoder does not support parameter changes\n");
1451 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
1452 uint64_t subtitle_size = 0;
1454 float percent = -1.0;
1460 const uint64_t
s =
ost->data_size_mux;
1466 default: other_size +=
s;
break;
1479 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: ",
1480 video_size / 1024.0,
1481 audio_size / 1024.0,
1482 subtitle_size / 1024.0,
1483 other_size / 1024.0,
1484 extra_size / 1024.0);
1494 uint64_t total_packets = 0, total_size = 0;
1499 for (j = 0; j <
f->nb_streams; j++) {
1523 total_packets, total_size);
1528 uint64_t total_packets = 0, total_size = 0;
1537 total_size +=
ost->data_size_mux;
1544 ost->frames_encoded);
1557 total_packets, total_size);
1559 if(video_size +
data_size + audio_size + subtitle_size + extra_size == 0){
1569 static void print_report(
int is_last_report, int64_t timer_start, int64_t cur_time)
1571 AVBPrint buf, buf_script;
1576 int64_t
pts = INT64_MIN + 1;
1577 static int64_t last_time = -1;
1578 static int first_report = 1;
1579 static int qp_histogram[52];
1580 int hours, mins, secs,
us;
1581 const char *hours_sign;
1588 if (!is_last_report) {
1589 if (last_time == -1) {
1590 last_time = cur_time;
1592 if (((cur_time - last_time) <
stats_period && !first_report) ||
1595 last_time = cur_time;
1598 t = (cur_time-timer_start) / 1000000.0;
1609 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
1616 fps = t > 1 ? frame_number / t : 0;
1617 av_bprintf(&buf,
"frame=%5"PRId64
" fps=%3.*f q=%3.1f ",
1618 frame_number, fps < 9.95, fps, q);
1619 av_bprintf(&buf_script,
"frame=%"PRId64
"\n", frame_number);
1621 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
1630 for (j = 0; j < 32; j++)
1637 double error, error_sum = 0;
1638 double scale, scale_sum = 0;
1640 char type[3] = {
'Y',
'U',
'V' };
1642 for (j = 0; j < 3; j++) {
1643 if (is_last_report) {
1656 av_bprintf(&buf_script,
"stream_%d_%d_psnr_%c=%2.2f\n",
1659 p =
psnr(error_sum / scale_sum);
1661 av_bprintf(&buf_script,
"stream_%d_%d_psnr_all=%2.2f\n",
1687 hours_sign = (
pts < 0) ?
"-" :
"";
1689 bitrate =
pts && total_size >= 0 ? total_size * 8 / (
pts / 1000.0) : -1;
1692 if (total_size < 0)
av_bprintf(&buf,
"size=N/A time=");
1693 else av_bprintf(&buf,
"size=%8.0fkB time=", total_size / 1024.0);
1709 if (total_size < 0)
av_bprintf(&buf_script,
"total_size=N/A\n");
1710 else av_bprintf(&buf_script,
"total_size=%"PRId64
"\n", total_size);
1712 av_bprintf(&buf_script,
"out_time_us=N/A\n");
1713 av_bprintf(&buf_script,
"out_time_ms=N/A\n");
1718 av_bprintf(&buf_script,
"out_time=%s%02d:%02d:%02d.%06d\n",
1719 hours_sign, hours, mins, secs,
us);
1732 av_bprintf(&buf_script,
"speed=%4.3gx\n", speed);
1736 const char end = is_last_report ?
'\n' :
'\r';
1738 fprintf(stderr,
"%s %c", buf.str, end);
1748 is_last_report ?
"end" :
"continue");
1750 FFMIN(buf_script.len, buf_script.size - 1));
1753 if (is_last_report) {
1756 "Error closing progress log, loss of information possible: %s\n",
av_err2str(
ret));
1790 if (
ost->sq_idx_encode >= 0)
1803 if (!
ost->initialized) {
1807 "Finishing stream without any data written to it.\n");
1813 if (ifilter->
format < 0 &&
1851 if (
ost->ist != ist)
1879 !
ost->copy_initial_nonkeyframes)
1882 if (!
ost->streamcopy_started && !
ost->copy_prior_start) {
1884 ist->
pts <
ost->ts_copy_start :
1895 if (
f->recording_time != INT64_MAX) {
1925 opkt->
pts = opkt->
dts - ost_tb_start_time;
1928 opkt->
dts -= ost_tb_start_time;
1936 "Subtitle heartbeat logic failed in %s! (%s)\n",
1944 ost->streamcopy_started = 1;
1981 int need_reinit,
ret;
1996 need_reinit |= ifilter->
width !=
frame->width ||
2021 if (need_reinit || !fg->
graph) {
2069 if (ifilter->
format < 0) {
2111 if (!
frame->opaque_ref) {
2138 "Failed to inject frame into filter network: %s\n",
av_err2str(
ret));
2194 (
AVRational){1, decoded_frame->sample_rate});
2199 return err < 0 ? err :
ret;
2206 int i,
ret = 0, err = 0;
2207 int64_t best_effort_timestamp;
2245 "video_delay is larger in decoder than demuxer %d > %d.\n"
2246 "If you want to help, upload a sample "
2247 "of this file to https://streams.videolan.org/upload/ "
2248 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n",
2307 "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",
2310 best_effort_timestamp,
2323 return err < 0 ? err :
ret;
2336 if (end < ist->
prev_sub.subtitle.end_display_time) {
2338 "Subtitle duration reduced from %"PRId32
" to %d%s\n",
2340 end <= 0 ?
", dropping it" :
"");
2389 .format =
src->format,
2390 .start_display_time =
src->start_display_time,
2391 .end_display_time =
src->end_display_time,
2397 if (!
src->num_rects)
2403 for (
int i = 0;
i <
src->num_rects;
i++) {
2417 dst_rect->
x = src_rect->
x;
2418 dst_rect->
y = src_rect->
y;
2419 dst_rect->
w = src_rect->
w;
2420 dst_rect->
h = src_rect->
h;
2435 for (
int j = 0; j < 4; j++) {
2443 if (!src_rect->
data[j])
2473 signal_pts <= prev_subtitle->
pts)
2557 int eof_reached = 0;
2593 int64_t duration_dts = 0;
2594 int64_t duration_pts = 0;
2596 int decode_failed = 0;
2629 if (duration_pts > 0) {
2655 if (decode_failed) {
2741 return !eof_reached;
2767 if (
config->pix_fmt == *p)
2776 "%s hwaccel requested for input stream #%d:%d, "
2777 "but cannot be initialized.\n",
2800 snprintf(
error, error_len,
"Decoder (codec %s) not found for input stream #%d:%d",
2812 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");
2828 "decoder on input stream #%d:%d : %s",
2838 "Error while opening decoder for input stream "
2874 "Error setting up codec context options.\n");
2883 "Error getting reference codec parameters.\n");
2888 unsigned int codec_tag_tmp;
2897 if (!
ost->frame_rate.num)
2900 if (
ost->frame_rate.num)
2911 if (
ost->frame_rate.num)
2921 if (!
ost->copy_prior_start) {
2938 memcpy(dst_data, sd_src->
data, sd_src->
size);
2942 #if FFMPEG_ROTATION_METADATA
2943 if (
ost->rotate_overridden) {
2960 if (
ost->frame_aspect_ratio.num) {
2965 "with stream copy may produce invalid files\n");
2984 const char *cname =
ost->enc_ctx->codec->name;
2985 uint8_t *encoder_string;
2986 int encoder_string_len;
2992 encoder_string =
av_mallocz(encoder_string_len);
2993 if (!encoder_string)
2999 av_strlcpy(encoder_string,
"Lavc ", encoder_string_len);
3000 av_strlcat(encoder_string, cname, encoder_string_len);
3010 if (
ost->enc_timebase.num > 0) {
3015 if (
ost->enc_timebase.num < 0) {
3022 "Input stream data not available, using default time base\n");
3043 if (!
ost->frame_rate.num)
3045 if (!
ost->frame_rate.num && !
ost->max_frame_rate.num) {
3049 "about the input framerate is available. Falling "
3050 "back to a default value of 25fps. Use the -r option "
3051 "if you want a different framerate.\n");
3054 if (
ost->max_frame_rate.num &&
3056 !
ost->frame_rate.den))
3057 ost->frame_rate =
ost->max_frame_rate;
3066 ost->frame_rate.num,
ost->frame_rate.den, 65535);
3078 if (
ost->bits_per_raw_sample)
3080 else if (
dec_ctx &&
ost->filter->graph->is_meta)
3096 "Please consider specifying a lower framerate, a different muxer or "
3097 "setting vsync/fps_mode to vfr\n");
3103 ost->frame_aspect_ratio.num ?
3109 if (
ost->bits_per_raw_sample)
3111 else if (
dec_ctx &&
ost->filter->graph->is_meta)
3130 ost->top_field_first >= 0)
3131 frame->top_field_first = !!
ost->top_field_first;
3133 if (
frame->interlaced_frame) {
3143 if (
ost->top_field_first == 0) {
3145 }
else if (
ost->top_field_first == 1) {
3152 if (!enc_ctx->
width) {
3153 enc_ctx->
width =
ost->ist->par->width;
3154 enc_ctx->
height =
ost->ist->par->height;
3159 if (!
ost->enc_ctx->subtitle_header)
3167 int input_props = 0, output_props = 0;
3172 if (input_descriptor)
3174 if (output_descriptor)
3176 if (input_props && output_props && input_props != output_props) {
3178 "Subtitle encoding currently only possible from text to text "
3179 "or bitmap to bitmap");
3195 if (
ost->sq_idx_encode >= 0)
3204 char *
error,
int error_len)
3228 "encoder on output stream #%d:%d : %s",
3237 "Error while opening encoder for output stream #%d:%d - "
3238 "maybe incorrect parameters such as bit_rate, rate, width or height",
3245 ost->enc_ctx->frame_size);
3247 if (
ost->enc_ctx->bit_rate &&
ost->enc_ctx->bit_rate < 1000 &&
3250 " It takes bits/s as argument, not kbits/s\n");
3255 "Error initializing the output stream codec context.\n");
3259 if (
ost->enc_ctx->nb_coded_side_data) {
3262 for (
i = 0;
i <
ost->enc_ctx->nb_coded_side_data;
i++) {
3269 memcpy(dst_data, sd_src->
data, sd_src->
size);
3302 }
else if (
ost->ist) {
3318 char error[1024] = {0};
3324 for (
int j = 0; j <
ifile->nb_streams; j++)
3356 for (
int j = 0; j <
ifile->ctx->nb_programs; j++) {
3373 for (
int j = 0; j < ist->nb_filters; j++) {
3376 ist->file_index, ist->st->index, ist->dec ? ist->dec->name :
"?",
3377 ist->filters[j]->name);
3386 if (
ost->attachment_filename) {
3405 ost->ist->file_index,
3411 const AVCodec *out_codec =
ost->enc_ctx->codec;
3412 const char *decoder_name =
"?";
3413 const char *in_codec_name =
"?";
3414 const char *encoder_name =
"?";
3415 const char *out_codec_name =
"?";
3419 decoder_name = in_codec->
name;
3422 in_codec_name =
desc->name;
3423 if (!strcmp(decoder_name, in_codec_name))
3424 decoder_name =
"native";
3428 encoder_name = out_codec->
name;
3431 out_codec_name =
desc->name;
3432 if (!strcmp(encoder_name, out_codec_name))
3433 encoder_name =
"native";
3437 in_codec_name, decoder_name,
3438 out_codec_name, encoder_name);
3474 int64_t opts_min = INT64_MAX;
3484 INT64_MIN :
ost->last_mux_dts;
3487 "cur_dts is invalid [init:%d i_done:%d finish:%d] (this is harmless if it occurs once at the start per stream)\n",
3488 ost->initialized,
ost->inputs_done,
ost->finished);
3491 if (!
ost->initialized && !
ost->inputs_done)
3494 if (!
ost->finished &&
opts < opts_min) {
3506 if (tcgetattr(0, &tty) == 0) {
3507 if (
on) tty.c_lflag |=
ECHO;
3508 else tty.c_lflag &= ~
ECHO;
3509 tcsetattr(0, TCSANOW, &tty);
3517 static int64_t last_time;
3521 if (cur_time - last_time >= 100000) {
3523 last_time = cur_time;
3533 if (
key ==
'c' ||
key ==
'C'){
3534 char buf[4096], target[64],
command[256],
arg[256] = {0};
3537 fprintf(stderr,
"\nEnter command: <target>|all <time>|-1 <command>[ <argument>]\n");
3540 while ((k =
read_key()) !=
'\n' && k !=
'\r' &&
i <
sizeof(buf)-1)
3545 fprintf(stderr,
"\n");
3547 (n = sscanf(buf,
"%63[^ ] %lf %255[^ ] %255[^\n]", target, &time,
command,
arg)) >= 3) {
3556 fprintf(stderr,
"Command reply for stream %d: ret:%d res:\n%s",
i,
ret, buf);
3557 }
else if (
key ==
'c') {
3558 fprintf(stderr,
"Queuing commands only on filters supporting the specific command is unsupported\n");
3563 fprintf(stderr,
"Queuing command failed with error %s\n",
av_err2str(
ret));
3569 "Parse error, at least 3 arguments were expected, "
3570 "only %d given in string '%s'\n", n, buf);
3573 if (
key ==
'd' ||
key ==
'D'){
3581 if(!debug) debug = 1;
3589 while ((k =
read_key()) !=
'\n' && k !=
'\r' &&
i <
sizeof(buf)-1)
3594 fprintf(stderr,
"\n");
3595 if (k <= 0 || sscanf(buf,
"%d", &debug)!=1)
3596 fprintf(stderr,
"error parsing debug value\n");
3599 ist->dec_ctx->debug = debug;
3602 ost->enc_ctx->debug = debug;
3605 fprintf(stderr,
"debug=%d\n", debug);
3608 fprintf(stderr,
"key function\n"
3609 "? show this help\n"
3610 "+ increase verbosity\n"
3611 "- decrease verbosity\n"
3612 "c Send command to first matching filter supporting it\n"
3613 "C Send/Queue command to all matching filters\n"
3614 "D cycle through available debug modes\n"
3615 "h dump packets/hex press to cycle through the 3 states\n"
3617 "s Show QP histogram\n"
3626 if (
ost->unavailable)
3637 ost->unavailable = 0;
3642 for (
int i = 0;
i <
ifile->nb_streams;
i++) {
3675 int disable_discontinuity_correction =
copy_ts;
3685 disable_discontinuity_correction = 0;
3690 if (fmt_is_discont) {
3695 "timestamp discontinuity for stream #%d:%d "
3696 "(id=%d, type=%s): %"PRId64
", new offset= %"PRId64
"\n",
3724 "Inter stream timestamp discontinuity %"PRId64
", new offset= %"PRId64
"\n",
3789 for (
i = 0;
i <
ifile->nb_streams;
i++) {
3799 if (
ost->ist == ist &&
3807 ifile->eof_reached = 1;
3819 goto discard_packet;
3837 memcpy(dst_data, src_sd->
data, src_sd->
size);
3845 av_log(
NULL,
AV_LOG_INFO,
"demuxer+ffmpeg -> ist_index:%d:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n",
3875 int nb_requests, nb_requests_max = 0;
3900 if (nb_requests > nb_requests_max) {
3901 nb_requests_max = nb_requests;
3935 if (
ost->filter && !
ost->filter->graph->graph) {
3945 if (
ost->filter &&
ost->filter->graph->graph) {
3974 }
else if (
ost->filter) {
3976 for (
i = 0;
i <
ost->filter->graph->nb_inputs;
i++) {
3984 ost->inputs_done = 1;
3995 ost->unavailable = 1;
4012 int64_t timer_start;
4013 int64_t total_packets_written = 0;
4071 uint64_t packets_written;
4073 total_packets_written += packets_written;
4098 struct rusage rusage;
4100 getrusage(RUSAGE_SELF, &rusage);
4102 (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
4104 (rusage.ru_stime.tv_sec * 1000000LL) + rusage.ru_stime.tv_usec;
4105 #elif HAVE_GETPROCESSTIMES
4107 FILETIME
c, e, k,
u;
4108 proc = GetCurrentProcess();
4109 GetProcessTimes(proc, &
c, &e, &k, &
u);
4111 ((int64_t)
u.dwHighDateTime << 32 |
u.dwLowDateTime) / 10;
4113 ((int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
4122 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
4123 struct rusage rusage;
4124 getrusage(RUSAGE_SELF, &rusage);
4125 return (int64_t)rusage.ru_maxrss * 1024;
4126 #elif HAVE_GETPROCESSMEMORYINFO
4128 PROCESS_MEMORY_COUNTERS memcounters;
4129 proc = GetCurrentProcess();
4130 memcounters.cb =
sizeof(memcounters);
4131 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
4132 return memcounters.PeakPagefileUsage;
4147 setvbuf(stderr,
NULL,_IONBF,0);
4180 int64_t utime, stime, rtime;
4186 "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
4187 utime / 1000000.0, stime / 1000000.0, rtime / 1000000.0);
static void error(const char *err)
static void sub2video_copy_rect(uint8_t *dst, int dst_linesize, int w, int h, AVSubtitleRect *r)
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
enum AVCodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the AVCodecID for the given codec tag tag.
#define AVFILTER_CMD_FLAG_ONE
Stop once a filter understood the command (for target=all for example), fast filters are favored auto...
#define AV_LOG_WARNING
Something somehow does not look correct.
int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out)
static int need_output(void)
static int check_output_constraints(InputStream *ist, OutputStream *ost)
AVPixelFormat
Pixel format.
AVRational av_buffersink_get_sample_aspect_ratio(const AVFilterContext *ctx)
static double psnr(double d)
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
static int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par)
#define atomic_store(object, desired)
static AVCodecContext * dec_ctx
static void reset_eagain(void)
int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int configure_filtergraph(FilterGraph *fg)
static volatile int ffmpeg_exited
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Callback to negotiate the pixel format.
enum AVMediaType codec_type
General type of the encoded data.
enum AVColorSpace colorspace
YUV colorspace type.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
unsigned int nb_stream_indexes
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
static int init_output_stream(OutputStream *ost, AVFrame *frame, char *error, int error_len)
int sample_rate
samples per second
@ KF_FORCE_SOURCE_NO_DROP
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
The official guide to swscale for confused that is
This struct describes the properties of an encoded stream.
#define u(width, name, range_min, range_max)
#define AV_LOG_QUIET
Print no output.
static float sub(float src0, float src1)
int64_t duration
Duration of the frame, in the same units as pts.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AVERROR_EOF
End of file.
uint8_t * data
The data buffer.
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.
static void sub2video_heartbeat(InputStream *ist, int64_t pts)
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
void remove_avoptions(AVDictionary **a, AVDictionary *b)
float frame_drop_threshold
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static int transcode_step(void)
Run a single step of transcoding.
@ AV_BUFFERSRC_FLAG_KEEP_REF
Keep a reference to the frame.
InputStream * ist_iter(InputStream *prev)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int64_t start_time
start time in microseconds == AV_TIME_BASE units
int ffmpeg_parse_options(int argc, char **argv)
This structure describes decoded (raw) audio or video data.
static av_cold void cleanup(FlashSV2Context *s)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
int64_t of_filesize(OutputFile *of)
int capabilities
Codec capabilities.
static BenchmarkTimeStamps current_time
int depth
Number of bits in the component.
enum AVFieldOrder field_order
Field order.
static OutputStream * ost_iter(OutputStream *prev)
int top_field_first
If the content is interlaced, is top field displayed first.
static uint64_t dup_warning
#define ATOMIC_VAR_INIT(value)
int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame)
Add a frame to the buffer source.
static int fix_sub_duration_heartbeat(InputStream *ist, int64_t signal_pts)
AVRational avg_frame_rate
Average framerate.
unsigned nb_output_dumped
static enum AVPictureType forced_kf_apply(void *logctx, KeyframeForceCtx *kf, AVRational tb, const AVFrame *in_picture, int dup_idx)
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
uint8_t * subtitle_header
Header containing style information for text subtitles.
static int transcode(void)
#define AV_LOG_VERBOSE
Detailed information.
AVIOContext * progress_avio
static void do_audio_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
void av_display_rotation_set(int32_t matrix[9], double angle)
Initialize a transformation matrix describing a pure clockwise rotation by the specified angle (in de...
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
static int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt)
static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output, int *decode_failed)
const int program_birth_year
program birth year, defined by the program for show_banner()
int nb_channels
Number of channels in this layout.
#define AV_CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
static void flush_encoders(void)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
static void term_exit_sigsafe(void)
static int init_output_stream_encode(OutputStream *ost, AVFrame *frame)
#define ECHO(name, type, min, max)
Callback for checking whether to abort blocking functions.
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
static int got_eagain(void)
static int ifilter_send_eof(InputFilter *ifilter, int64_t pts)
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...
void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
Set the frame size for an audio buffer sink.
float dts_delta_threshold
static int submit_encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
static int init_input_stream(InputStream *ist, char *error, int error_len)
const struct AVCodec * codec
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
AVChannelLayout ch_layout
Audio channel layout.
void report_and_exit(int ret)
Reports an error corresponding to the provided AVERROR code and calls exit_program() with the corresp...
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
int x
top left corner of pict, undefined when pict is not set
enum AVDiscard discard
selects which program to discard and which to feed to the caller
#define AV_BPRINT_SIZE_AUTOMATIC
int key_frame
1 -> keyframe, 0-> not
int flags
AV_CODEC_FLAG_*.
static int sub2video_get_blank_frame(InputStream *ist)
AVChannelLayout ch_layout
Channel layout of the audio data.
int sq_receive(SyncQueue *sq, int stream_idx, SyncQueueFrame frame)
Read a frame from the queue.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
static av_always_inline float scale(float x, float s)
int hw_device_setup_for_decode(InputStream *ist)
#define us(width, name, range_min, range_max, subs,...)
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
int64_t duration
Decoding: duration of the stream, in stream time base.
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.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
int avformat_network_init(void)
Do global initialization of network libraries.
char * ass
0 terminated ASS/SSA compatible event line.
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
static int init_output_stream_streamcopy(OutputStream *ost)
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
@ AV_CODEC_ID_DVB_SUBTITLE
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
static void ffmpeg_cleanup(int ret)
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
#define ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM
static void decode_flush(InputFile *ifile)
int av_thread_message_queue_send(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Send a message on the queue.
static OutputStream * choose_output(void)
Select the output stream to process.
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
AVRational av_buffersink_get_frame_rate(const AVFilterContext *ctx)
int frame_size
Audio only.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
int has_b_frames
Size of the frame reordering buffer in the decoder.
EncStatsComponent * components
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
const AVRational * supported_framerates
array of supported framerates, or NULL if any, array is terminated by {0,0}
This struct describes the properties of a single codec described by an AVCodecID.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
int global_quality
Global quality for codecs which cannot change it per frame.
static BenchmarkTimeStamps get_benchmark_time_stamps(void)
static int ifilter_has_all_input_formats(FilterGraph *fg)
static int64_t copy_ts_first_pts
static void close_output_stream(OutputStream *ost)
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
AVRational sample_aspect_ratio
Video only.
int y
top left corner of pict, undefined when pict is not set
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
int av_buffersink_get_format(const AVFilterContext *ctx)
int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder or encoder (when the AV_CODEC_FLAG_RECON_FRAME flag is used...
AVRational av_buffersink_get_time_base(const AVFilterContext *ctx)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
static enum AVPixelFormat pix_fmts[]
struct OutputStream * ost
void sq_set_tb(SyncQueue *sq, unsigned int stream_idx, AVRational tb)
Set the timebase for the stream with index stream_idx.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static void video_sync_process(OutputFile *of, OutputStream *ost, AVFrame *next_picture, double duration, int64_t *nb_frames, int64_t *nb_frames_prev)
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int64_t pts
Same as packet pts, in AV_TIME_BASE.
static void abort_codec_experimental(const AVCodec *c, int encoder)
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going on
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
void enc_stats_write(OutputStream *ost, EncStats *es, const AVFrame *frame, const AVPacket *pkt, uint64_t frame_num)
uint64_t error[AV_NUM_DATA_POINTERS]
error
int av_usleep(unsigned usec)
Sleep for a period of time.
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
static void ts_discontinuity_process(InputFile *ifile, InputStream *ist, AVPacket *pkt)
#define atomic_load(object)
char * text
0 terminated plain UTF-8 text
void assert_avoptions(AVDictionary *m)
static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
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 int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
static int process_input(int file_index)
static int init_output_stream_wrapper(OutputStream *ost, AVFrame *frame, unsigned int fatal)
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
double expr_const_values[FKF_NB]
void of_enc_stats_close(void)
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
static int transcode_from_filter(FilterGraph *graph, InputStream **best_ist)
Perform a step of transcoding for the specified filter graph.
@ AVDISCARD_ALL
discard all
int av_log_get_level(void)
Get the current log level.
void init_dynload(void)
Initialize dynamic library loading.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int w
width of pict, undefined when pict is not set
static void print_final_stats(int64_t total_size)
static int transcode_subtitles(InputStream *ist, const AVPacket *pkt, int *got_output, int *decode_failed)
static int64_t nb_frames_drop
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
#define AV_DICT_MULTIKEY
Allow to store several equal keys in the dictionary.
int main(int argc, char **argv)
static void update_benchmark(const char *fmt,...)
static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame)
static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_t *duration_pts, int eof, int *decode_failed)
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
void of_close(OutputFile **pof)
Rational number (pair of numerator and denominator).
static int64_t getmaxrss(void)
enum AVPacketSideDataType type
static int check_keyboard_interaction(int64_t cur_time)
@ AV_PICTURE_TYPE_I
Intra.
void av_log_set_flags(int arg)
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
@ AV_BUFFERSRC_FLAG_PUSH
Immediately push the frame to the output.
#define AV_CODEC_PROP_BITMAP_SUB
Subtitle codec is bitmap based Decoded AVSubtitle data can be read from the AVSubtitleRect->pict fiel...
unsigned int * stream_index
static FILE * vstats_file
int ifile_get_packet(InputFile *f, AVPacket **pkt)
Get next input packet from the demuxer.
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
static int transcode_init(void)
int avfilter_graph_request_oldest(AVFilterGraph *graph)
Request a frame on the oldest sink link.
static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts)
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
static void sub2video_push_ref(InputStream *ist, int64_t pts)
void avio_w8(AVIOContext *s, int b)
static volatile int received_nb_signals
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
AVChannelLayout ch_layout
Audio only.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
int sample_rate
Audio only.
int64_t best_effort_timestamp
frame timestamp estimated using various heuristics, in stream time base
int extradata_size
Size of the extradata content in bytes.
static int decode_interrupt_cb(void *ctx)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags)
Close the buffer source after EOF.
#define FF_DEBUG_DCT_COEFF
const OptionDef options[]
char * stats_out
pass1 encoding statistics output buffer
enum AVPictureType pict_type
Picture type of the frame.
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *next_picture)
OutputFile ** output_files
#define SIGNAL(sig, func)
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats)
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int sample_rate
Sample rate of the audio data.
static volatile int received_sigterm
static int64_t start_time
char * url
input or output URL.
enum AVSampleFormat sample_fmt
audio sample format
static int send_filter_eof(InputStream *ist)
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame)
Submit a frame for the stream with index stream_idx.
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents.
static AVRational av_make_q(int num, int den)
Create an AVRational.
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.
#define AV_NOPTS_VALUE
Undefined timestamp value.
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
AVRational time_base
Time base for the timestamps in this frame.
int hwaccel_decode_init(AVCodecContext *avctx)
AVRational av_stream_get_codec_timebase(const AVStream *st)
Get the internal codec timebase from a stream.
void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
@ AV_PICTURE_TYPE_NONE
Undefined.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
uint32_t end_display_time
void show_banner(int argc, char **argv, const OptionDef *options)
Print the program banner to stderr.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
@ AV_FIELD_TT
Top coded_first, top displayed first.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
int flags
A combination of AV_PKT_FLAG values.
static int decode(InputStream *ist, AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.
enum AVMediaType av_buffersink_get_type(const AVFilterContext *ctx)
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
@ SUBTITLE_BITMAP
A bitmap, pict will be set.
#define AV_LOG_INFO
Standard information.
static int64_t nb_frames_dup
AVPacketSideData * side_data
An array of side data that applies to the whole stream (i.e.
static void do_subtitle_out(OutputFile *of, OutputStream *ost, AVSubtitle *sub)
int av_find_nearest_q_idx(AVRational q, const AVRational *q_list)
Find the value in a list of rationals nearest a given reference rational.
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
void register_exit(void(*cb)(int ret))
Register a program-specific cleanup routine.
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
int av_buffersink_get_w(const AVFilterContext *ctx)
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
void av_log_set_level(int level)
Set the log level.
int nb_samples
number of audio samples (per channel) described by this frame
#define DECODING_FOR_FILTER
void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static int process_subtitle(InputStream *ist, AVSubtitle *subtitle, int *got_output)
#define AV_FRAME_FLAG_CORRUPT
The frame data may be corrupted, e.g.
static int check_recording_time(OutputStream *ost, int64_t ts, AVRational tb)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
int nb_colors
number of colors in pict, undefined when pict is not set
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
static void sub2video_flush(InputStream *ist)
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
#define AV_TIME_BASE
Internal time base represented as integer.
int block_align
Audio only.
int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
Add a frame to the buffer source.
static void sigterm_handler(int sig)
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
New fields can be added to the end with minor version bumps.
const char * name
Name of the codec implementation.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
FilterGraph ** filtergraphs
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
const AVIOInterruptCB int_cb
int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Supply a raw video or audio frame to the encoder.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void * av_calloc(size_t nmemb, size_t size)
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the '-loglevel' option in the command line args and apply it.
int av_buffersink_get_h(const AVFilterContext *ctx)
int64_t frame_num
Frame counter, set by libavcodec.
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
#define AV_BUFFERSINK_FLAG_NO_REQUEST
Tell av_buffersink_get_buffer_ref() not to request a frame from its input.
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
static int64_t decode_error_stat[2]
int id
Format-specific stream ID.
int decode_error_flags
decode error flags of the frame, set to a combination of FF_DECODE_ERROR_xxx flags if the decoder pro...
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
int h
height of pict, undefined when pict is not set
#define FFSWAP(type, a, b)
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal codec state / flush internal buffers.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
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 int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
AVChannelLayout ch_layout
int nb_side_data
The number of elements in the AVStream.side_data array.
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
void * opaque
Private data of the user, can be used to carry app specific stuff.
void hw_device_free_all(void)
static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, AVFrame *frame)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
#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...
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
void ifile_close(InputFile **f)
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
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.
main external API structure.
int index
stream index in AVFormatContext
static atomic_int transcode_init_done
int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, AVStream *ost, const AVStream *ist, enum AVTimebaseSource copy_tb)
Transfer internal timing information from one stream to another.
static int copy_av_subtitle(AVSubtitle *dst, AVSubtitle *src)
int hw_device_setup_for_encode(OutputStream *ost)
int av_buffersink_get_sample_rate(const AVFilterContext *ctx)
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
static void ts_discontinuity_detect(InputFile *ifile, InputStream *ist, AVPacket *pkt)
static void check_decode_result(InputStream *ist, int *got_output, int ret)
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
AVRational r_frame_rate
Real base framerate of the stream.
const char program_name[]
program name, defined by the program for show_version().
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
const AVCodecHWConfig * avcodec_get_hw_config(const AVCodec *codec, int index)
Retrieve supported hardware configurations for a codec.
static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time)
#define AV_CODEC_CAP_PARAM_CHANGE
Codec supports changed parameters at any point.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
enum AVMediaType codec_type
char * av_strdup(const char *s)
Duplicate a string.
unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src)
Get the number of failed requests.
void(* flush)(AVBSFContext *ctx)
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int video_delay
Video only.
static void set_encoder_id(OutputFile *of, OutputStream *ost)
Structure to hold side data for an AVFrame.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference)
AVRational av_add_q(AVRational b, AVRational c)
Add two rationals.
@ AV_ROUND_PASS_MINMAX
Flag telling rescaling functions to pass INT64_MIN/MAX through unchanged, avoiding special cases for ...
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
@ AV_FIELD_TB
Top coded first, bottom displayed first.
uint8_t * av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, size_t size)
Allocate new information from stream.
@ AV_FIELD_BB
Bottom coded first, bottom displayed first.
int width
picture width / height.
@ AV_PKT_DATA_QUALITY_STATS
This side data contains quality related information from the encoder.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
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.
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.
float dts_error_threshold
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
const AVOutputFormat * format
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
static void set_tty_echo(int on)
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
int pts_wrap_bits
Number of bits in timestamps.
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
@ AV_FIELD_BT
Bottom coded first, top displayed first.
int of_stream_init(OutputFile *of, OutputStream *ost)
#define ABORT_ON_FLAG_EMPTY_OUTPUT
static int read_key(void)
static int reap_filters(int flush)
Get and encode new output from any of the filtergraphs, without causing activity.
int of_write_trailer(OutputFile *of)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
int filtergraph_is_simple(FilterGraph *fg)
static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base)
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
static uint32_t BS_FUNC() read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
AVRational time_base
Time base of the packet's timestamps.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
void avdevice_register_all(void)
Initialize libavdevice and register all the input and output devices.