33 #include <stdatomic.h>
73 #if HAVE_SYS_RESOURCE_H
75 #include <sys/types.h>
76 #include <sys/resource.h>
77 #elif HAVE_GETPROCESSTIMES
80 #if HAVE_GETPROCESSMEMORYINFO
84 #if HAVE_SETCONSOLECTRLHANDLER
90 #include <sys/select.h>
95 #include <sys/ioctl.h>
164 static struct termios oldtty;
165 static int restore_tty;
169 static void free_input_threads(
void);
195 uint32_t *pal, *dst2;
203 if (
r->x < 0 ||
r->x +
r->w >
w ||
r->y < 0 ||
r->y +
r->h >
h) {
205 r->x,
r->y,
r->w,
r->h,
w,
h
210 dst +=
r->y * dst_linesize +
r->x * 4;
212 pal = (uint32_t *)
r->data[1];
213 for (y = 0; y <
r->h; y++) {
214 dst2 = (uint32_t *)dst;
216 for (x = 0; x <
r->w; x++)
217 *(dst2++) = pal[*(src2++)];
219 src +=
r->linesize[0];
247 int64_t
pts, end_pts;
256 num_rects =
sub->num_rects;
269 "Impossible to get a blank canvas.\n");
272 dst =
frame->data [0];
273 dst_linesize =
frame->linesize[0];
274 for (
i = 0;
i < num_rects;
i++)
299 if (pts2 <= ist2->sub2video.last_pts)
306 for (j = 0, nb_reqs = 0; j < ist2->
nb_filters; j++)
333 tcsetattr (0, TCSANOW, &oldtty);
358 ret = write(2,
"Received > 3 system signals, hard exiting\n",
359 strlen(
"Received > 3 system signals, hard exiting\n"));
365 #if HAVE_SETCONSOLECTRLHANDLER
366 static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
373 case CTRL_BREAK_EVENT:
377 case CTRL_CLOSE_EVENT:
378 case CTRL_LOGOFF_EVENT:
379 case CTRL_SHUTDOWN_EVENT:
398 #define SIGNAL(sig, func) \
400 action.sa_handler = func; \
401 sigaction(sig, &action, NULL); \
404 #define SIGNAL(sig, func) \
410 #if defined __linux__
411 struct sigaction action = {0};
415 sigfillset(&action.sa_mask);
418 action.sa_flags = SA_RESTART;
424 if (tcgetattr (0, &tty) == 0) {
428 tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
429 |INLCR|IGNCR|ICRNL|IXON);
430 tty.c_oflag |= OPOST;
431 tty.c_lflag &= ~(
ECHO|ECHONL|ICANON|IEXTEN);
432 tty.c_cflag &= ~(CSIZE|PARENB);
437 tcsetattr (0, TCSANOW, &tty);
449 signal(SIGPIPE, SIG_IGN);
451 #if HAVE_SETCONSOLECTRLHANDLER
452 SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
469 n = select(1, &rfds,
NULL,
NULL, &tv);
478 # if HAVE_PEEKNAMEDPIPE
480 static HANDLE input_handle;
483 input_handle = GetStdHandle(STD_INPUT_HANDLE);
484 is_pipe = !GetConsoleMode(input_handle, &dw);
489 if (!PeekNamedPipe(input_handle,
NULL, 0,
NULL, &nchars,
NULL)) {
604 ost->audio_channels_mapped = 0;
612 if (
ost->muxing_queue) {
624 free_input_threads();
652 "Error closing vstats file, loss of information possible: %s\n",
711 "bench: %8" PRIu64
" user %8" PRIu64
" sys %8" PRIu64
" real %s \n",
725 ost2->
finished |=
ost == ost2 ? this_stream : others;
744 if (
ost->frame_number >=
ost->max_frames) {
755 unsigned int are_we_over_size =
756 (
ost->muxing_queue_data_size +
pkt->
size) >
ost->muxing_queue_data_threshold;
757 int new_size = are_we_over_size ?
759 ost->max_muxing_queue_size) :
764 "Too many packets buffered for output stream %d:%d.\n",
779 ost->muxing_queue_data_size += tmp_pkt->
size;
802 if (
ost->frame_rate.num &&
ost->is_cfr) {
816 av_log(
s,
AV_LOG_WARNING,
"Invalid DTS: %"PRId64
" PTS: %"PRId64
" in output stream %d:%d, replacing by guess\n",
833 av_log(
s, loglevel,
"Non-monotonous DTS in output stream "
834 "%d:%d; previous: %"PRId64
", current: %"PRId64
"; ",
840 av_log(
s, loglevel,
"changing to %"PRId64
". This may result "
841 "in incorrect timestamps in the output file.\n",
852 ost->packets_written++;
858 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s size:%d\n",
917 "packet for stream #%d:%d.\n",
ost->file_index,
ost->
index);
942 !enc || !
ost->filter || !
ost->filter->graph->graph)
959 float_pts +=
FFSIGN(float_pts) * 1.0 / (1<<17);
981 char *
error,
int error_len);
987 char error[1024] = {0};
989 if (
ost->initialized)
1019 ost->samples_encoded +=
frame->nb_samples;
1020 ost->frames_encoded++;
1025 "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
1048 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
1066 int subtitle_out_max_size = 1024 * 1024;
1067 int subtitle_out_size, nb,
i;
1101 for (
i = 0;
i < nb;
i++) {
1102 unsigned save_num_rects =
sub->num_rects;
1111 sub->end_display_time -=
sub->start_display_time;
1112 sub->start_display_time = 0;
1116 ost->frames_encoded++;
1119 subtitle_out_max_size,
sub);
1121 sub->num_rects = save_num_rects;
1122 if (subtitle_out_size < 0) {
1129 pkt->
size = subtitle_out_size;
1149 int ret, format_video_sync;
1153 int nb_frames, nb0_frames,
i;
1154 double delta, delta0;
1164 if (
ost->source_index >= 0)
1168 if (frame_rate.
num > 0 && frame_rate.
den > 0)
1174 if (!
ost->filters_script &&
1183 if (!next_picture) {
1185 nb0_frames = nb_frames =
mid_pred(
ost->last_nb0_frames[0],
1186 ost->last_nb0_frames[1],
1187 ost->last_nb0_frames[2]);
1189 delta0 = sync_ipts -
ost->sync_opts;
1218 if (delta0 < -0.6) {
1222 sync_ipts =
ost->sync_opts;
1227 switch (format_video_sync) {
1229 if (
ost->frame_number == 0 && delta0 >= 0.5) {
1239 }
else if (
delta < -1.1)
1241 else if (
delta > 1.1) {
1244 nb0_frames =
llrintf(delta0 - 0.6);
1250 else if (
delta > 0.6)
1262 nb_frames =
FFMIN(nb_frames,
ost->max_frames -
ost->frame_number);
1263 nb0_frames =
FFMIN(nb0_frames, nb_frames);
1265 memmove(
ost->last_nb0_frames + 1,
1266 ost->last_nb0_frames,
1268 ost->last_nb0_frames[0] = nb0_frames;
1270 if (nb0_frames == 0 &&
ost->last_dropped) {
1273 "*** dropping frame %d from stream %d at ts %"PRId64
"\n",
1276 if (nb_frames > (nb0_frames &&
ost->last_dropped) + (nb_frames > nb0_frames)) {
1282 nb_frames_dup += nb_frames - (nb0_frames &&
ost->last_dropped) - (nb_frames > nb0_frames);
1289 ost->last_dropped = nb_frames == nb0_frames && next_picture;
1292 for (
i = 0;
i < nb_frames;
i++) {
1294 int forced_keyframe = 0;
1297 if (i < nb0_frames && ost->last_frame) {
1298 in_picture =
ost->last_frame;
1300 in_picture = next_picture;
1305 in_picture->
pts =
ost->sync_opts;
1315 ost->forced_kf_ref_pts = in_picture->
pts;
1319 if (
ost->forced_kf_index <
ost->forced_kf_count &&
1320 in_picture->
pts >=
ost->forced_kf_pts[
ost->forced_kf_index]) {
1321 ost->forced_kf_index++;
1322 forced_keyframe = 1;
1323 }
else if (
ost->forced_keyframes_pexpr) {
1325 ost->forced_keyframes_expr_const_values[
FKF_T] = pts_time;
1327 ost->forced_keyframes_expr_const_values,
NULL);
1328 ff_dlog(
NULL,
"force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n",
1329 ost->forced_keyframes_expr_const_values[
FKF_N],
1332 ost->forced_keyframes_expr_const_values[
FKF_T],
1336 forced_keyframe = 1;
1338 ost->forced_keyframes_expr_const_values[
FKF_N];
1340 ost->forced_keyframes_expr_const_values[
FKF_T];
1344 ost->forced_keyframes_expr_const_values[
FKF_N] += 1;
1345 }
else if (
ost->forced_keyframes
1346 && !strncmp(
ost->forced_keyframes,
"source", 6)
1349 forced_keyframe = 1;
1352 if (forced_keyframe) {
1360 "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
1365 ost->frames_encoded++;
1384 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
1396 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
1415 ost->frame_number++;
1421 if (!
ost->last_frame)
1424 if (next_picture &&
ost->last_frame)
1437 return -10.0 * log10(d);
1444 double ti1,
bitrate, avg_bitrate;
1459 fprintf(
vstats_file,
"frame= %5d q= %2.1f ", frame_number,
1476 avg_bitrate = (double)(
ost->data_size * 8) / ti1 / 1000.0;
1477 fprintf(
vstats_file,
"s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
1478 (
double)
ost->data_size / 1024, ti1,
bitrate, avg_bitrate);
1515 if (!
ost->filter || !
ost->filter->graph->graph)
1537 filtered_frame =
ost->filtered_frame;
1545 "Error in av_buffersink_get_frame_flags(): %s\n",
av_err2str(
ret));
1552 if (
ost->finished) {
1559 if (!
ost->frame_aspect_ratio.num)
1568 "Audio filter graph output is not normalized and encoder does not support parameter changes\n");
1587 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
1588 uint64_t subtitle_size = 0;
1590 float percent = -1.0;
1596 switch (
ost->enc_ctx->codec_type) {
1600 default: other_size +=
ost->data_size;
break;
1602 extra_size +=
ost->enc_ctx->extradata_size;
1612 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: ",
1613 video_size / 1024.0,
1614 audio_size / 1024.0,
1615 subtitle_size / 1024.0,
1616 other_size / 1024.0,
1617 extra_size / 1024.0);
1627 uint64_t total_packets = 0, total_size = 0;
1632 for (j = 0; j <
f->nb_streams; j++) {
1656 total_packets, total_size);
1661 uint64_t total_packets = 0, total_size = 0;
1670 total_size +=
ost->data_size;
1671 total_packets +=
ost->packets_written;
1675 if (
ost->encoding_needed) {
1677 ost->frames_encoded);
1684 ost->packets_written,
ost->data_size);
1690 total_packets, total_size);
1692 if(video_size +
data_size + audio_size + subtitle_size + extra_size == 0){
1702 static void print_report(
int is_last_report, int64_t timer_start, int64_t cur_time)
1704 AVBPrint buf, buf_script;
1709 int frame_number, vid,
i;
1712 int64_t
pts = INT64_MIN + 1;
1713 static int64_t last_time = -1;
1714 static int first_report = 1;
1715 static int qp_histogram[52];
1716 int hours, mins, secs,
us;
1717 const char *hours_sign;
1724 if (!is_last_report) {
1725 if (last_time == -1) {
1726 last_time = cur_time;
1728 if (((cur_time - last_time) <
stats_period && !first_report) ||
1731 last_time = cur_time;
1734 t = (cur_time-timer_start) / 1000000.0;
1740 if (total_size <= 0)
1750 if (!
ost->stream_copy)
1755 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
1761 frame_number =
ost->frame_number;
1762 fps = t > 1 ? frame_number / t : 0;
1763 av_bprintf(&buf,
"frame=%5d fps=%3.*f q=%3.1f ",
1764 frame_number, fps < 9.95, fps, q);
1765 av_bprintf(&buf_script,
"frame=%d\n", frame_number);
1767 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
1776 for (j = 0; j < 32; j++)
1782 double error, error_sum = 0;
1783 double scale, scale_sum = 0;
1785 char type[3] = {
'Y',
'U',
'V' };
1787 for (j = 0; j < 3; j++) {
1788 if (is_last_report) {
1790 scale = enc->
width * enc->
height * 255.0 * 255.0 * frame_number;
1801 av_bprintf(&buf_script,
"stream_%d_%d_psnr_%c=%2.2f\n",
1804 p =
psnr(error_sum / scale_sum);
1806 av_bprintf(&buf_script,
"stream_%d_%d_psnr_all=%2.2f\n",
1833 hours_sign = (
pts < 0) ?
"-" :
"";
1835 bitrate =
pts && total_size >= 0 ? total_size * 8 / (
pts / 1000.0) : -1;
1838 if (total_size < 0)
av_bprintf(&buf,
"size=N/A time=");
1839 else av_bprintf(&buf,
"size=%8.0fkB time=", total_size / 1024.0);
1855 if (total_size < 0)
av_bprintf(&buf_script,
"total_size=N/A\n");
1856 else av_bprintf(&buf_script,
"total_size=%"PRId64
"\n", total_size);
1858 av_bprintf(&buf_script,
"out_time_us=N/A\n");
1859 av_bprintf(&buf_script,
"out_time_ms=N/A\n");
1864 av_bprintf(&buf_script,
"out_time=%s%02d:%02d:%02d.%06d\n",
1865 hours_sign, hours, mins, secs,
us);
1878 av_bprintf(&buf_script,
"speed=%4.3gx\n", speed);
1882 const char end = is_last_report ?
'\n' :
'\r';
1884 fprintf(stderr,
"%s %c", buf.str, end);
1894 is_last_report ?
"end" :
"continue");
1896 FFMIN(buf_script.len, buf_script.size - 1));
1899 if (is_last_report) {
1902 "Error closing progress log, loss of information possible: %s\n",
av_err2str(
ret));
1934 if (!
ost->encoding_needed)
1939 if (!
ost->initialized) {
1943 "Finishing stream %d:%d without any data written to it.\n",
2040 if (
ost->source_index != ist_index)
2068 !
ost->copy_initial_nonkeyframes)
2071 if (!
ost->frame_number && !
ost->copy_prior_start) {
2076 ist->
pts < comp_start :
2087 if (
f->recording_time != INT64_MAX) {
2117 opkt->
pts = opkt->
dts - ost_tb_start_time;
2120 opkt->
dts -= ost_tb_start_time;
2131 if (!
dec->channel_layout) {
2132 char layout_name[256];
2137 if (!
dec->channel_layout)
2140 dec->channels,
dec->channel_layout);
2180 int need_reinit,
ret,
i;
2192 need_reinit |= ifilter->
width !=
frame->width ||
2211 if (need_reinit || !fg->
graph) {
2323 "Failed to inject frame into filter network: %s\n",
av_err2str(
ret));
2389 return err < 0 ? err :
ret;
2396 int i,
ret = 0, err = 0;
2397 int64_t best_effort_timestamp;
2440 "video_delay is larger in decoder than demuxer %d > %d.\n"
2441 "If you want to help, upload a sample "
2442 "of this file to https://streams.videolan.org/upload/ "
2443 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n",
2503 "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",
2506 best_effort_timestamp,
2520 return err < 0 ? err :
ret;
2545 if (end < ist->
prev_sub.subtitle.end_display_time) {
2547 "Subtitle duration reduced from %"PRId32
" to %d%s\n",
2549 end <= 0 ?
", dropping it" :
"");
2622 int eof_reached = 0;
2660 int64_t duration_dts = 0;
2661 int64_t duration_pts = 0;
2663 int decode_failed = 0;
2694 if (duration_pts > 0) {
2720 if (decode_failed) {
2805 return !eof_reached;
2837 printf(
"SDP:\n%s\n", sdp);
2890 "%s hwaccel requested for input stream #%d:%d, "
2891 "but cannot be initialized.\n",
2919 "%s hwaccel requested for input stream #%d:%d, "
2920 "but cannot be initialized.\n", hwaccel->
name,
2928 if (!
s->hw_frames_ctx)
2957 snprintf(
error, error_len,
"Decoder (codec %s) not found for input stream #%d:%d",
2965 #if LIBAVCODEC_VERSION_MAJOR < 60
2973 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");
2991 "decoder on input stream #%d:%d : %s",
3001 "Error while opening decoder for input stream "
3017 if (
ost->source_index >= 0)
3024 return FFDIFFSIGN(*(
const int64_t *)
a, *(
const int64_t *)
b);
3034 if (!
ost->initialized)
3043 "Could not write header for output file #%d "
3044 "(incorrect codec parameters ?): %s\n",
3114 uint32_t codec_tag = par_dst->
codec_tag;
3123 "Error setting up codec context options.\n");
3130 "Error getting reference codec parameters.\n");
3135 unsigned int codec_tag_tmp;
3148 if (!
ost->frame_rate.num)
3175 memcpy(dst_data, sd_src->
data, sd_src->
size);
3179 if (
ost->rotate_overridden) {
3198 if (
ost->frame_aspect_ratio.num) {
3201 (
AVRational){ par_dst->height, par_dst->width });
3203 "with stream copy may produce invalid files\n");
3225 int encoder_string_len;
3226 int format_flags = 0;
3248 encoder_string =
av_mallocz(encoder_string_len);
3249 if (!encoder_string)
3255 av_strlcpy(encoder_string,
"Lavc ", encoder_string_len);
3256 av_strlcat(encoder_string,
ost->enc->name, encoder_string_len);
3268 for (p = kf; *p; p++)
3279 for (
i = 0;
i < n;
i++) {
3280 char *next = strchr(p,
',');
3285 if (!memcmp(p,
"chapters", 8)) {
3294 "Could not allocate forced key frames array.\n");
3321 ost->forced_kf_pts =
pts;
3330 if (
ost->enc_timebase.num > 0) {
3335 if (
ost->enc_timebase.num < 0) {
3382 if (!
ost->frame_rate.num)
3384 if (ist && !
ost->frame_rate.num)
3386 if (ist && !
ost->frame_rate.num)
3388 if (ist && !
ost->frame_rate.num && !
ost->max_frame_rate.num) {
3392 "about the input framerate is available. Falling "
3393 "back to a default value of 25fps for output stream #%d:%d. Use the -r option "
3394 "if you want a different framerate.\n",
3398 if (
ost->max_frame_rate.num &&
3400 !
ost->frame_rate.den))
3401 ost->frame_rate =
ost->max_frame_rate;
3403 if (
ost->enc->supported_framerates && !
ost->force_fps) {
3405 ost->frame_rate =
ost->enc->supported_framerates[idx];
3410 ost->frame_rate.num,
ost->frame_rate.den, 65535);
3435 "Please consider specifying a lower framerate, a different muxer or -vsync 2\n");
3441 ost->frame_aspect_ratio.num ?
3472 ost->top_field_first >= 0)
3473 frame->top_field_first = !!
ost->top_field_first;
3475 if (
frame->interlaced_frame) {
3485 if (
ost->top_field_first == 0) {
3487 }
else if (
ost->top_field_first == 1) {
3491 if (
ost->forced_keyframes) {
3492 if (!strncmp(
ost->forced_keyframes,
"expr:", 5)) {
3497 "Invalid force_key_frames expression '%s'\n",
ost->forced_keyframes+5);
3500 ost->forced_keyframes_expr_const_values[
FKF_N] = 0;
3507 }
else if(strncmp(
ost->forced_keyframes,
"source", 6)) {
3514 if (!enc_ctx->
width) {
3532 char *
error,
int error_len)
3536 if (
ost->encoding_needed) {
3547 if (
dec &&
dec->subtitle_header) {
3550 if (!
ost->enc_ctx->subtitle_header)
3552 memcpy(
ost->enc_ctx->subtitle_header,
dec->subtitle_header,
dec->subtitle_header_size);
3553 ost->enc_ctx->subtitle_header_size =
dec->subtitle_header_size;
3566 "encoder on output stream #%d:%d : %s",
3572 int input_props = 0, output_props = 0;
3577 if (input_descriptor)
3579 if (output_descriptor)
3581 if (input_props && output_props && input_props != output_props) {
3583 "Subtitle encoding currently only possible from text to text "
3584 "or bitmap to bitmap");
3593 "Error while opening encoder for output stream #%d:%d - "
3594 "maybe incorrect parameters such as bit_rate, rate, width or height",
3601 ost->enc_ctx->frame_size);
3603 if (
ost->enc_ctx->bit_rate &&
ost->enc_ctx->bit_rate < 1000 &&
3606 " It takes bits/s as argument, not kbits/s\n");
3611 "Error initializing the output stream codec context.\n");
3615 if (
ost->enc_ctx->nb_coded_side_data) {
3618 for (
i = 0;
i <
ost->enc_ctx->nb_coded_side_data;
i++) {
3625 memcpy(dst_data, sd_src->
data, sd_src->
size);
3658 }
else if (
ost->stream_copy) {
3667 {
"disposition" ,
NULL, 0,
AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
3685 static const AVClass class = {
3691 const AVClass *pclass = &
class;
3705 ost->initialized = 1;
3722 "New %s stream %d:%d at pos:%"PRId64
" and DTS:%ss\n",
3731 int ret = 0,
i, j, k;
3735 char error[1024] = {0};
3755 if (
ifile->rate_emu)
3756 for (j = 0; j <
ifile->nb_streams; j++)
3793 for (j = 0; j <
ifile->ctx->nb_programs; j++) {
3837 if (
ost->attachment_filename) {
3862 ost->sync_ist->file_index,
3864 if (
ost->stream_copy)
3869 const char *decoder_name =
"?";
3870 const char *in_codec_name =
"?";
3871 const char *encoder_name =
"?";
3872 const char *out_codec_name =
"?";
3876 decoder_name = in_codec->
name;
3879 in_codec_name =
desc->name;
3880 if (!strcmp(decoder_name, in_codec_name))
3881 decoder_name =
"native";
3885 encoder_name = out_codec->
name;
3888 out_codec_name =
desc->name;
3889 if (!strcmp(encoder_name, out_codec_name))
3890 encoder_name =
"native";
3894 in_codec_name, decoder_name,
3895 out_codec_name, encoder_name);
3920 if (
ost->finished ||
3923 if (
ost->frame_number >=
ost->max_frames) {
3944 int64_t opts_min = INT64_MAX;
3954 "cur_dts is invalid st:%d (%d) [init:%d i_done:%d finish:%d] (this is harmless if it occurs once at the start per stream)\n",
3957 if (!
ost->initialized && !
ost->inputs_done)
3960 if (!
ost->finished &&
opts < opts_min) {
3972 if (tcgetattr(0, &tty) == 0) {
3973 if (
on) tty.c_lflag |=
ECHO;
3974 else tty.c_lflag &= ~
ECHO;
3975 tcsetattr(0, TCSANOW, &tty);
3983 static int64_t last_time;
3989 last_time = cur_time;
4006 if (
key ==
'c' ||
key ==
'C'){
4007 char buf[4096], target[64],
command[256],
arg[256] = {0};
4010 fprintf(stderr,
"\nEnter command: <target>|all <time>|-1 <command>[ <argument>]\n");
4013 while ((k =
read_key()) !=
'\n' && k !=
'\r' &&
i <
sizeof(buf)-1)
4018 fprintf(stderr,
"\n");
4020 (n = sscanf(buf,
"%63[^ ] %lf %255[^ ] %255[^\n]", target, &time,
command,
arg)) >= 3) {
4029 fprintf(stderr,
"Command reply for stream %d: ret:%d res:\n%s",
i,
ret, buf);
4030 }
else if (
key ==
'c') {
4031 fprintf(stderr,
"Queuing commands only on filters supporting the specific command is unsupported\n");
4036 fprintf(stderr,
"Queuing command failed with error %s\n",
av_err2str(
ret));
4042 "Parse error, at least 3 arguments were expected, "
4043 "only %d given in string '%s'\n", n, buf);
4046 if (
key ==
'd' ||
key ==
'D'){
4050 if(!debug) debug = 1;
4058 while ((k =
read_key()) !=
'\n' && k !=
'\r' &&
i <
sizeof(buf)-1)
4063 fprintf(stderr,
"\n");
4064 if (k <= 0 || sscanf(buf,
"%d", &debug)!=1)
4065 fprintf(stderr,
"error parsing debug value\n");
4072 ost->enc_ctx->debug = debug;
4075 fprintf(stderr,
"debug=%d\n", debug);
4078 fprintf(stderr,
"key function\n"
4079 "? show this help\n"
4080 "+ increase verbosity\n"
4081 "- decrease verbosity\n"
4082 "c Send command to first matching filter supporting it\n"
4083 "C Send/Queue command to all matching filters\n"
4084 "D cycle through available debug modes\n"
4085 "h dump packets/hex press to cycle through the 3 states\n"
4087 "s Show QP histogram\n"
4094 static void *input_thread(
void *
arg)
4124 "Thread message queue blocking; consider raising the "
4125 "thread_queue_size option (current value: %d)\n",
4126 f->thread_queue_size);
4131 "Unable to send packet to main thread: %s\n",
4142 static void free_input_thread(
int i)
4147 if (!
f || !
f->in_thread_queue)
4158 static void free_input_threads(
void)
4163 free_input_thread(
i);
4166 static int init_input_thread(
int i)
4171 if (
f->thread_queue_size < 0)
4173 if (!
f->thread_queue_size)
4176 if (
f->ctx->pb ? !
f->ctx->pb->seekable :
4177 strcmp(
f->ctx->iformat->name,
"lavfi"))
4178 f->non_blocking = 1;
4180 f->thread_queue_size,
sizeof(
f->pkt));
4185 av_log(
NULL,
AV_LOG_ERROR,
"pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(
ret));
4193 static int init_input_threads(
void)
4198 ret = init_input_thread(
i);
4217 for (
i = 0;
i <
f->nb_streams;
i++) {
4227 if (
f->thread_queue_size)
4228 return get_input_packet_mt(
f,
pkt);