99#include "libavformat/avformat.h"
100#include "libavdevice/avdevice.h"
101#include "libswresample/swresample.h"
102#include "libavutil/opt.h"
103#include "libavutil/channel_layout.h"
104#include "libavutil/parseutils.h"
105#include "libavutil/samplefmt.h"
106#include "libavutil/fifo.h"
107#include "libavutil/hwcontext.h"
108#include "libavutil/internal.h"
109#include "libavutil/intreadwrite.h"
110#include "libavutil/dict.h"
111#include "libavutil/display.h"
112#include "libavutil/mathematics.h"
113#include "libavutil/pixdesc.h"
114#include "libavutil/avstring.h"
115#include "libavutil/libm.h"
116#include "libavutil/imgutils.h"
117#include "libavutil/timestamp.h"
118#include "libavutil/bprint.h"
119#include "libavutil/time.h"
120#include "libavutil/thread.h"
121#include "libavutil/threadmessage.h"
122#include "libavcodec/mathops.h"
123#include "libavformat/os_support.h"
125# include "libavfilter/avfilter.h"
126# include "libavfilter/buffersrc.h"
127# include "libavfilter/buffersink.h"
129#if HAVE_SYS_RESOURCE_H
131#include <sys/types.h>
132#include <sys/resource.h>
133#elif HAVE_GETPROCESSTIMES
136#if HAVE_GETPROCESSMEMORYINFO
140#if HAVE_SETCONSOLECTRLHANDLER
146#include <sys/select.h>
151#include <sys/ioctl.h>
163#include "libavutil/avassert.h"
219extern int opt_map(
void *optctx,
const char *opt,
const char *arg);
220extern int opt_map_channel(
void *optctx,
const char *opt,
const char *arg);
222extern int opt_data_frames(
void *optctx,
const char *opt,
const char *arg);
223extern int opt_progress(
void *optctx,
const char *opt,
const char *arg);
224extern int opt_target(
void *optctx,
const char *opt,
const char *arg);
225extern int opt_vsync(
void *optctx,
const char *opt,
const char *arg);
226extern int opt_abort_on(
void *optctx,
const char *opt,
const char *arg);
228extern int opt_qscale(
void *optctx,
const char *opt,
const char *arg);
229extern int opt_profile(
void *optctx,
const char *opt,
const char *arg);
232extern int opt_attach(
void *optctx,
const char *opt,
const char *arg);
234extern int opt_video_codec(
void *optctx,
const char *opt,
const char *arg);
235extern int opt_sameq(
void *optctx,
const char *opt,
const char *arg);
236extern int opt_timecode(
void *optctx,
const char *opt,
const char *arg);
237extern int opt_vstats_file(
void *optctx,
const char *opt,
const char *arg);
238extern int opt_vstats(
void *optctx,
const char *opt,
const char *arg);
240extern int opt_old2new(
void *optctx,
const char *opt,
const char *arg);
241extern int opt_streamid(
void *optctx,
const char *opt,
const char *arg);
242extern int opt_bitrate(
void *optctx,
const char *opt,
const char *arg);
243extern int show_hwaccels(
void *optctx,
const char *opt,
const char *arg);
247extern int opt_audio_codec(
void *optctx,
const char *opt,
const char *arg);
249extern int opt_preset(
void *optctx,
const char *opt,
const char *arg);
254extern int opt_sdp_file(
void *optctx,
const char *opt,
const char *arg);
256extern int opt_vaapi_device(
void *optctx,
const char *opt,
const char *arg);
259extern int opt_qsv_device(
void *optctx,
const char *opt,
const char *arg);
261extern int opt_data_codec(
void *optctx,
const char *opt,
const char *arg);
276__thread
struct termios oldtty;
277__thread
int restore_tty;
281static void free_input_threads(
void);
304 av_frame_unref(frame);
308 if ((ret = av_frame_get_buffer(frame, 0)) < 0)
310 memset(frame->data[0], 0, frame->height * frame->linesize[0]);
317 uint32_t *pal, *dst2;
321 if (r->type != SUBTITLE_BITMAP) {
322 av_log(NULL, AV_LOG_WARNING,
"sub2video: non-bitmap subtitle\n");
325 if (r->x < 0 || r->x + r->w > w || r->y < 0 || r->y + r->h > h) {
326 av_log(NULL, AV_LOG_WARNING,
"sub2video: rectangle (%d %d %d %d) overflowing %d %d\n",
327 r->x, r->y, r->w, r->h, w, h
332 dst += r->y * dst_linesize + r->x * 4;
334 pal = (uint32_t *)r->data[1];
335 for (y = 0; y < r->h; y++) {
336 dst2 = (uint32_t *)dst;
338 for (x = 0; x < r->w; x++)
339 *(dst2++) = pal[*(src2++)];
341 src += r->linesize[0];
351 av_assert1(frame->data[0]);
354 ret = av_buffersrc_add_frame_flags(ist->
filters[i]->
filter, frame,
355 AV_BUFFERSRC_FLAG_KEEP_REF |
356 AV_BUFFERSRC_FLAG_PUSH);
357 if (ret != AVERROR_EOF && ret < 0)
358 av_log(NULL, AV_LOG_WARNING,
"Error while add the frame to buffer source(%s).\n",
369 int64_t pts, end_pts;
374 pts = av_rescale_q(sub->pts + sub->start_display_time * 1000LL,
375 AV_TIME_BASE_Q, ist->
st->time_base);
376 end_pts = av_rescale_q(sub->pts + sub->end_display_time * 1000LL,
377 AV_TIME_BASE_Q, ist->
st->time_base);
378 num_rects = sub->num_rects;
390 av_log(ist->
dec_ctx, AV_LOG_ERROR,
391 "Impossible to get a blank canvas.\n");
394 dst = frame->data [0];
395 dst_linesize = frame->linesize[0];
396 for (i = 0; i < num_rects; i++)
419 pts2 = av_rescale_q(pts, ist->
st->time_base, ist2->
st->time_base) - 1;
421 if (pts2 <= ist2->sub2video.last_pts)
428 for (j = 0, nb_reqs = 0; j < ist2->
nb_filters; j++)
429 nb_reqs += av_buffersrc_get_nb_failed_requests(ist2->
filters[j]->
filter);
444 if (ret != AVERROR_EOF && ret < 0)
445 av_log(NULL, AV_LOG_WARNING,
"Flush the frame error.\n");
455 tcsetattr (0, TCSANOW, &oldtty);
461 av_log(NULL, AV_LOG_QUIET,
"%s",
"");
481#if HAVE_SETCONSOLECTRLHANDLER
482static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
484 av_log(NULL, AV_LOG_DEBUG,
"\nReceived windows signal %ld\n", fdwCtrlType);
489 case CTRL_BREAK_EVENT:
493 case CTRL_CLOSE_EVENT:
494 case CTRL_LOGOFF_EVENT:
495 case CTRL_SHUTDOWN_EVENT:
507 av_log(NULL, AV_LOG_ERROR,
"Received unknown windows signal %ld\n", fdwCtrlType);
514#define SIGNAL(sig, func) \
516 action.sa_handler = func; \
517 sigaction(sig, &action, NULL); \
520#define SIGNAL(sig, func) \
527 #if defined __aarch64__ || defined __amd64__ || defined __x86_64__
528 struct sigaction action = {0};
530 struct sigaction action = {{0}};
536 sigfillset(&action.sa_mask);
539 action.sa_flags = SA_RESTART;
545 if (tcgetattr (0, &tty) == 0) {
549 tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
550 |INLCR|IGNCR|ICRNL|IXON);
551 tty.c_oflag |= OPOST;
552 tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
553 tty.c_cflag &= ~(CSIZE|PARENB);
558 tcsetattr (0, TCSANOW, &tty);
582#if HAVE_SETCONSOLECTRLHANDLER
583 SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
600 n = select(1, &rfds, NULL, NULL, &tv);
609# if HAVE_PEEKNAMEDPIPE
611 static HANDLE input_handle;
614 input_handle = GetStdHandle(STD_INPUT_HANDLE);
615 is_pipe = !GetConsoleMode(input_handle, &dw);
620 if (!PeekNamedPipe(input_handle, NULL, 0, NULL, &nchars, NULL)) {
654 av_log(NULL, AV_LOG_INFO,
"bench: maxrss=%ikB\n", maxrss);
659 avfilter_graph_free(&fg->
graph);
666 while (av_fifo_read(ifilter->
frame_queue, &frame, 1) >= 0)
667 av_frame_free(&frame);
674 avsubtitle_free(&sub);
678 av_freep(&ifilter->
name);
685 avfilter_inout_free(&ofilter->
out_tmp);
686 av_freep(&ofilter->
name);
687 av_channel_layout_uninit(&ofilter->
ch_layout);
713 av_packet_free(&ost->
pkt);
727 avcodec_free_context(&ost->
enc_ctx);
728 avcodec_parameters_free(&ost->
ref_par);
733 av_packet_free(&
pkt);
740 free_input_threads();
751 av_packet_free(&ist->
pkt);
759 avcodec_free_context(&ist->
dec_ctx);
766 av_log(NULL, AV_LOG_ERROR,
767 "Error closing vstats file, loss of information possible: %s\n",
768 av_err2str(AVERROR(errno)));
780 avformat_network_deinit();
783 av_log(NULL, AV_LOG_INFO,
"Exiting normally, received signal %d.\n",
786 av_log(NULL, AV_LOG_INFO,
"Exiting normally, received cancel request.\n");
788 av_log(NULL, AV_LOG_INFO,
"Conversion failed!\n");
796 const AVDictionaryEntry *t = NULL;
798 while ((t = av_dict_get(b,
"", t, AV_DICT_IGNORE_SUFFIX))) {
799 av_dict_set(a, t->key, NULL, AV_DICT_MATCH_CASE);
805 const AVDictionaryEntry *t;
806 if ((t = av_dict_get(m,
"", NULL, AV_DICT_IGNORE_SUFFIX))) {
807 av_log(NULL, AV_LOG_FATAL,
"Option %s not found.\n", t->key);
826 vsnprintf(buf,
sizeof(buf), fmt, va);
828 av_log(NULL, AV_LOG_INFO,
829 "bench: %8" PRIu64
" user %8" PRIu64
" sys %8" PRIu64
" real %s \n",
845 int64_t end = av_rescale_q(ost->
sync_opts - ost->
first_pts, time_base, AV_TIME_BASE_Q);
871 while ((
ret = av_bsf_receive_packet(ost->
bsf_ctx,
pkt)) >= 0)
873 if (
ret == AVERROR(EAGAIN))
879 if (
ret < 0 &&
ret != AVERROR_EOF) {
880 av_log(NULL, AV_LOG_ERROR,
"Error applying bitstream filters to an output "
893 AV_TIME_BASE_Q) >= 0) {
903 double float_pts = AV_NOPTS_VALUE;
904 AVCodecContext *enc = ost->
enc_ctx;
905 if (!frame || frame->pts == AV_NOPTS_VALUE ||
913 AVRational filter_tb = av_buffersink_get_time_base(filter);
914 AVRational tb = enc->time_base;
915 int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);
917 tb.den <<= extra_bits;
919 av_rescale_q(frame->pts, filter_tb, tb) -
920 av_rescale_q(start_time, AV_TIME_BASE_Q, tb);
921 float_pts /= 1 << extra_bits;
923 float_pts += FFSIGN(float_pts) * 1.0 / (1<<17);
926 av_rescale_q(frame->pts, filter_tb, enc->time_base) -
927 av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base);
933 av_log(NULL, AV_LOG_INFO,
"filter -> pts:%s pts_time:%s exact:%f time_base:%d/%d\n",
934 frame ? av_ts2str(frame->pts) :
"NULL",
935 frame ? av_ts2timestr(frame->pts, &enc->time_base) :
"NULL",
937 enc ? enc->time_base.num : -1,
938 enc ? enc->time_base.den : -1);
945 char *error,
int error_len);
950 int ret = AVERROR_BUG;
951 char error[1024] = {0};
958 av_log(NULL, AV_LOG_ERROR,
"Error initializing output stream %d:%d -- %s\n",
970 return -10.0 * log10(
d);
975 const uint8_t *sd = av_packet_get_side_data(
pkt, AV_PKT_DATA_QUALITY_STATS,
977 AVCodecContext *enc = ost->
enc_ctx;
978 int64_t frame_number;
979 double ti1, bitrate, avg_bitrate;
981 ost->
quality = sd ? AV_RL32(sd) : -1;
982 ost->
pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE;
984 for (
int i = 0; i<FF_ARRAY_ELEMS(ost->
error); i++) {
986 ost->
error[i] = AV_RL64(sd + 8 + 8*i);
1005 fprintf(
vstats_file,
"frame= %5"PRId64
" q= %2.1f ", frame_number,
1006 ost->
quality / (
float)FF_QP2LAMBDA);
1009 ost->
quality / (
float)FF_QP2LAMBDA);
1012 if (ost->
error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR))
1013 fprintf(
vstats_file,
"PSNR= %6.2f ",
psnr(ost->
error[0] / (enc->width * enc->height * 255.0 * 255.0)));
1021 bitrate = (
pkt->size * 8) / av_q2d(enc->time_base) / 1000.0;
1022 avg_bitrate = (double)(ost->
data_size * 8) / ti1 / 1000.0;
1023 fprintf(
vstats_file,
"s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
1024 (
double)ost->
data_size / 1024, ti1, bitrate, avg_bitrate);
1030 AVCodecContext *enc = ost->
enc_ctx;
1031 AVPacket *
pkt = ost->
pkt;
1032 const char *type_desc = av_get_media_type_string(enc->codec_type);
1033 const char *action = frame ?
"encode" :
"flush";
1040 av_log(NULL, AV_LOG_INFO,
"encoder <- type:%s "
1041 "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
1043 av_ts2str(frame->pts), av_ts2timestr(frame->pts, &enc->time_base),
1044 enc->time_base.num, enc->time_base.den);
1050 ret = avcodec_send_frame(enc, frame);
1051 if (
ret < 0 && !(
ret == AVERROR_EOF && !frame)) {
1052 av_log(NULL, AV_LOG_ERROR,
"Error submitting %s frame to the encoder\n",
1058 ret = avcodec_receive_packet(enc,
pkt);
1063 if ((
ret >= 0 ||
ret == AVERROR_EOF) && ost->
logfile && enc->stats_out)
1064 fprintf(ost->
logfile,
"%s", enc->stats_out);
1066 if (
ret == AVERROR(EAGAIN)) {
1069 }
else if (
ret == AVERROR_EOF) {
1072 }
else if (
ret < 0) {
1073 av_log(NULL, AV_LOG_ERROR,
"%s encoding failed\n", type_desc);
1078 av_log(NULL, AV_LOG_INFO,
"encoder -> type:%s "
1079 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s "
1080 "duration:%s duration_time:%s\n",
1082 av_ts2str(
pkt->pts), av_ts2timestr(
pkt->pts, &enc->time_base),
1083 av_ts2str(
pkt->dts), av_ts2timestr(
pkt->dts, &enc->time_base),
1084 av_ts2str(
pkt->duration), av_ts2timestr(
pkt->duration, &enc->time_base));
1090 av_log(NULL, AV_LOG_INFO,
"encoder -> type:%s "
1091 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s "
1092 "duration:%s duration_time:%s\n",
1094 av_ts2str(
pkt->pts), av_ts2timestr(
pkt->pts, &enc->time_base),
1095 av_ts2str(
pkt->dts), av_ts2timestr(
pkt->dts, &enc->time_base),
1096 av_ts2str(
pkt->duration), av_ts2timestr(
pkt->duration, &enc->time_base));
1099 if (enc->codec_type == AVMEDIA_TYPE_VIDEO)
1122 ost->
sync_opts = frame->pts + frame->nb_samples;
1134 int subtitle_out_max_size = 1024 * 1024;
1135 int subtitle_out_size, nb, i;
1136 AVCodecContext *enc;
1137 AVPacket *
pkt = ost->
pkt;
1140 if (sub->pts == AV_NOPTS_VALUE) {
1141 av_log(NULL, AV_LOG_ERROR,
"Subtitle packets must have a pts\n");
1152 av_log(NULL, AV_LOG_FATAL,
"Failed to allocate subtitle_out\n");
1160 if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE)
1169 for (i = 0; i < nb; i++) {
1170 unsigned save_num_rects = sub->num_rects;
1172 ost->
sync_opts = av_rescale_q(
pts, AV_TIME_BASE_Q, enc->time_base);
1178 sub->pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q);
1179 sub->end_display_time -= sub->start_display_time;
1180 sub->start_display_time = 0;
1186 subtitle_out_size = avcodec_encode_subtitle(enc,
subtitle_out,
1187 subtitle_out_max_size, sub);
1189 sub->num_rects = save_num_rects;
1190 if (subtitle_out_size < 0) {
1191 av_log(NULL, AV_LOG_FATAL,
"Subtitle encoding failed\n");
1195 av_packet_unref(
pkt);
1197 pkt->size = subtitle_out_size;
1199 pkt->duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->
mux_timebase);
1200 if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
1204 pkt->pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, ost->
mux_timebase);
1206 pkt->pts += av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->
mux_timebase);
1216 AVFrame *next_picture)
1219 AVCodecContext *enc = ost->
enc_ctx;
1220 AVRational frame_rate;
1221 int64_t nb_frames, nb0_frames, i;
1222 double delta, delta0;
1223 double duration = 0;
1224 double sync_ipts = AV_NOPTS_VALUE;
1234 frame_rate = av_buffersink_get_frame_rate(filter);
1235 if (frame_rate.num > 0 && frame_rate.den > 0)
1236 duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base));
1238 if(ist && ist->
st->start_time != AV_NOPTS_VALUE && ist->
first_dts != AV_NOPTS_VALUE && ost->
frame_rate.num)
1239 duration = FFMIN(duration, 1/(av_q2d(ost->
frame_rate) * av_q2d(enc->time_base)));
1246 lrintf(next_picture->pkt_duration * av_q2d(ist->
st->time_base) / av_q2d(enc->time_base)) > 0) {
1247 duration = lrintf(next_picture->pkt_duration * av_q2d(ist->
st->time_base) / av_q2d(enc->time_base));
1250 if (!next_picture) {
1257 delta = delta0 + duration;
1267 if (delta0 < -0.6) {
1268 av_log(NULL, AV_LOG_VERBOSE,
"Past duration %f too large\n", -delta0);
1270 av_log(NULL, AV_LOG_DEBUG,
"Clipping frame in rate conversion by %f\n", -delta0);
1279 av_log(NULL, AV_LOG_DEBUG,
"Not duplicating %d initial frames\n", (
int)lrintf(delta0));
1288 }
else if (delta < -1.1)
1290 else if (delta > 1.1) {
1291 nb_frames = llrintf(delta);
1293 nb0_frames = llrintf(delta0 - 0.6);
1299 else if (delta > 0.6)
1317 nb0_frames = FFMIN(nb0_frames, nb_frames);
1326 av_log(NULL, AV_LOG_VERBOSE,
1327 "*** dropping frame %"PRId64
" from stream %d at ts %"PRId64
"\n",
1330 if (nb_frames > (nb0_frames && ost->
last_dropped) + (nb_frames > nb0_frames)) {
1332 av_log(NULL, AV_LOG_ERROR,
"%"PRId64
" frame duplication too large, skipping\n", nb_frames - 1);
1337 av_log(NULL, AV_LOG_VERBOSE,
"*** %"PRId64
" dup!\n", nb_frames - 1);
1339 av_log(NULL, AV_LOG_WARNING,
"More than %"PRIu64
" frames duplicated\n",
dup_warning);
1343 ost->
last_dropped = nb_frames == nb0_frames && next_picture;
1347 for (i = 0; i < nb_frames; i++) {
1348 AVFrame *in_picture;
1349 int forced_keyframe = 0;
1352 if (i < nb0_frames && ost->last_frame->buf[0]) {
1355 in_picture = next_picture;
1365 in_picture->quality = enc->global_quality;
1366 in_picture->pict_type = 0;
1369 in_picture->pts != AV_NOPTS_VALUE)
1372 pts_time = in_picture->pts != AV_NOPTS_VALUE ?
1377 forced_keyframe = 1;
1383 ff_dlog(NULL,
"force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n",
1391 forced_keyframe = 1;
1402 && in_picture->key_frame==1
1404 forced_keyframe = 1;
1412 if (forced_keyframe) {
1413 in_picture->pict_type = AV_PICTURE_TYPE_I;
1414 av_log(NULL, AV_LOG_DEBUG,
"Forced keyframe at time %f\n", pts_time);
1427 av_frame_move_ref(ost->
last_frame, next_picture);
1438 int64_t end = av_rescale_q(ost->
sync_opts - ost->
first_pts, time_base, AV_TIME_BASE_Q);
1451 AVFrame *filtered_frame = NULL;
1458 AVFilterContext *filter;
1459 AVCodecContext *enc = ost->
enc_ctx;
1475 if (av_buffersink_get_type(filter) == AVMEDIA_TYPE_AUDIO)
1481 ret = av_buffersink_get_frame_flags(filter, filtered_frame,
1482 AV_BUFFERSINK_FLAG_NO_REQUEST);
1484 if (
ret != AVERROR(EAGAIN) &&
ret != AVERROR_EOF) {
1485 av_log(NULL, AV_LOG_WARNING,
1486 "Error in av_buffersink_get_frame_flags(): %s\n", av_err2str(
ret));
1487 }
else if (flush &&
ret == AVERROR_EOF) {
1488 if (av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO)
1494 av_frame_unref(filtered_frame);
1498 switch (av_buffersink_get_type(filter)) {
1499 case AVMEDIA_TYPE_VIDEO:
1501 enc->sample_aspect_ratio = filtered_frame->sample_aspect_ratio;
1505 case AVMEDIA_TYPE_AUDIO:
1506 if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) &&
1507 enc->ch_layout.nb_channels != filtered_frame->ch_layout.nb_channels) {
1508 av_log(NULL, AV_LOG_ERROR,
1509 "Audio filter graph output is not normalized and encoder does not support parameter changes\n");
1519 av_frame_unref(filtered_frame);
1528 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
1529 uint64_t subtitle_size = 0;
1531 float percent = -1.0;
1537 switch (ost->
enc_ctx->codec_type) {
1538 case AVMEDIA_TYPE_VIDEO: video_size += ost->
data_size;
break;
1539 case AVMEDIA_TYPE_AUDIO: audio_size += ost->
data_size;
break;
1540 case AVMEDIA_TYPE_SUBTITLE: subtitle_size += ost->
data_size;
break;
1541 default: other_size += ost->
data_size;
break;
1543 extra_size += ost->
enc_ctx->extradata_size;
1545 if ( (ost->
enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2))
1546 != AV_CODEC_FLAG_PASS1)
1553 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: ",
1554 video_size / 1024.0,
1555 audio_size / 1024.0,
1556 subtitle_size / 1024.0,
1557 other_size / 1024.0,
1558 extra_size / 1024.0);
1560 av_log(NULL, AV_LOG_INFO,
"%f%%", percent);
1562 av_log(NULL, AV_LOG_INFO,
"unknown");
1563 av_log(NULL, AV_LOG_INFO,
"\n");
1568 uint64_t total_packets = 0, total_size = 0;
1570 av_log(NULL, AV_LOG_VERBOSE,
"Input file #%d (%s):\n",
1575 enum AVMediaType type = ist->
dec_ctx->codec_type;
1580 av_log(NULL, AV_LOG_VERBOSE,
" Input stream #%d:%d (%s): ",
1581 i, j, av_get_media_type_string(type));
1582 av_log(NULL, AV_LOG_VERBOSE,
"%"PRIu64
" packets read (%"PRIu64
" bytes); ",
1586 av_log(NULL, AV_LOG_VERBOSE,
"%"PRIu64
" frames decoded",
1588 if (type == AVMEDIA_TYPE_AUDIO)
1589 av_log(NULL, AV_LOG_VERBOSE,
" (%"PRIu64
" samples)", ist->
samples_decoded);
1590 av_log(NULL, AV_LOG_VERBOSE,
"; ");
1593 av_log(NULL, AV_LOG_VERBOSE,
"\n");
1596 av_log(NULL, AV_LOG_VERBOSE,
" Total: %"PRIu64
" packets (%"PRIu64
" bytes) demuxed\n",
1597 total_packets, total_size);
1602 uint64_t total_packets = 0, total_size = 0;
1604 av_log(NULL, AV_LOG_VERBOSE,
"Output file #%d (%s):\n",
1607 for (j = 0; j < of->
ctx->nb_streams; j++) {
1609 enum AVMediaType type = ost->
enc_ctx->codec_type;
1614 av_log(NULL, AV_LOG_VERBOSE,
" Output stream #%d:%d (%s): ",
1615 i, j, av_get_media_type_string(type));
1617 av_log(NULL, AV_LOG_VERBOSE,
"%"PRIu64
" frames encoded",
1619 if (type == AVMEDIA_TYPE_AUDIO)
1620 av_log(NULL, AV_LOG_VERBOSE,
" (%"PRIu64
" samples)", ost->
samples_encoded);
1621 av_log(NULL, AV_LOG_VERBOSE,
"; ");
1624 av_log(NULL, AV_LOG_VERBOSE,
"%"PRIu64
" packets muxed (%"PRIu64
" bytes); ",
1627 av_log(NULL, AV_LOG_VERBOSE,
"\n");
1630 av_log(NULL, AV_LOG_VERBOSE,
" Total: %"PRIu64
" packets (%"PRIu64
" bytes) muxed\n",
1631 total_packets, total_size);
1633 if(video_size +
data_size + audio_size + subtitle_size + extra_size == 0){
1634 av_log(NULL, AV_LOG_WARNING,
"Output file is empty, nothing was encoded ");
1636 av_log(NULL, AV_LOG_WARNING,
"\n");
1638 av_log(NULL, AV_LOG_WARNING,
"(check -ss / -t / -frames parameters if used)\n");
1645 AVFormatContext *oc = NULL;
1646 AVCodecContext *enc = NULL;
1648 int64_t
pts = INT64_MIN + 1;
1651 int64_t frame_number = 0;
1654 int64_t total_size = 0;
1656 double bitrate = 0.0;
1659 float t = (cur_time-timer_start) / 1000000.0;
1664 total_size = avio_size(oc->pb);
1665 if (total_size <= 0) {
1666 total_size = avio_tell(oc->pb);
1677 quality = ost->
quality / (float) FF_QP2LAMBDA;
1680 if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
1686 fps = t > 1 ? frame_number / t : 0;
1690 if (av_stream_get_end_pts(ost->
st) != AV_NOPTS_VALUE)
1691 pts = FFMAX(
pts, av_rescale_q(av_stream_get_end_pts(ost->
st),
1692 ost->
st->time_base, AV_TIME_BASE_Q));
1698 seconds = FFABS(
pts) / 1000;
1701 bitrate =
pts && total_size >= 0 ? total_size * 8 / (
pts / 1000.0) : -1;
1704 speed = t != 0.0 ? (double)
pts / AV_TIME_BASE / t : -1;
1708 report_callback(frame_number, fps, quality, total_size, seconds, bitrate, speed);
1712static void print_report(
int is_last_report, int64_t timer_start, int64_t cur_time)
1714 AVBPrint buf, buf_script;
1716 AVFormatContext *oc;
1718 AVCodecContext *enc;
1722 int64_t
pts = INT64_MIN + 1;
1723 int hours, mins, secs, us;
1724 const char *hours_sign;
1728 if (!is_last_report) {
1743 t = (cur_time-timer_start) / 1000000.0;
1748 total_size = avio_size(oc->pb);
1749 if (total_size <= 0)
1750 total_size = avio_tell(oc->pb);
1753 av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
1754 av_bprint_init(&buf_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
1760 q = ost->
quality / (float) FF_QP2LAMBDA;
1762 if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
1763 av_bprintf(&buf,
"q=%2.1f ", q);
1764 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
1767 if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
1771 fps = t > 1 ? frame_number / t : 0;
1772 av_bprintf(&buf,
"frame=%5"PRId64
" fps=%3.*f q=%3.1f ",
1773 frame_number, fps < 9.95, fps, q);
1774 av_bprintf(&buf_script,
"frame=%"PRId64
"\n", frame_number);
1775 av_bprintf(&buf_script,
"fps=%.2f\n", fps);
1776 av_bprintf(&buf_script,
"stream_%d_%d_q=%.1f\n",
1779 av_bprintf(&buf,
"L");
1785 for (j = 0; j < 32; j++)
1789 if ((enc->flags & AV_CODEC_FLAG_PSNR) && (ost->
pict_type != AV_PICTURE_TYPE_NONE || is_last_report)) {
1791 double error, error_sum = 0;
1792 double scale, scale_sum = 0;
1794 char type[3] = {
'Y',
'U',
'V' };
1795 av_bprintf(&buf,
"PSNR=");
1796 for (j = 0; j < 3; j++) {
1797 if (is_last_report) {
1798 error = enc->error[j];
1799 scale = enc->width * enc->height * 255.0 * 255.0 * frame_number;
1801 error = ost->
error[j];
1802 scale = enc->width * enc->height * 255.0 * 255.0;
1808 p =
psnr(error / scale);
1809 av_bprintf(&buf,
"%c:%2.2f ", type[j], p);
1810 av_bprintf(&buf_script,
"stream_%d_%d_psnr_%c=%2.2f\n",
1813 p =
psnr(error_sum / scale_sum);
1814 av_bprintf(&buf,
"*:%2.2f ",
psnr(error_sum / scale_sum));
1815 av_bprintf(&buf_script,
"stream_%d_%d_psnr_all=%2.2f\n",
1821 if (av_stream_get_end_pts(ost->
st) != AV_NOPTS_VALUE) {
1822 pts = FFMAX(
pts, av_rescale_q(av_stream_get_end_pts(ost->
st),
1823 ost->
st->time_base, AV_TIME_BASE_Q));
1836 secs = FFABS(
pts) / AV_TIME_BASE;
1837 us = FFABS(
pts) % AV_TIME_BASE;
1842 hours_sign = (
pts < 0) ?
"-" :
"";
1844 bitrate =
pts && total_size >= 0 ? total_size * 8 / (
pts / 1000.0) : -1;
1845 speed = t != 0.0 ? (double)
pts / AV_TIME_BASE / t : -1;
1847 if (total_size < 0) av_bprintf(&buf,
"size=N/A time=");
1848 else av_bprintf(&buf,
"size=%8.0fkB time=", total_size / 1024.0);
1849 if (
pts == AV_NOPTS_VALUE) {
1850 av_bprintf(&buf,
"N/A ");
1852 av_bprintf(&buf,
"%s%02d:%02d:%02d.%02d ",
1853 hours_sign, hours, mins, secs, (100 * us) / AV_TIME_BASE);
1857 av_bprintf(&buf,
"bitrate=N/A");
1858 av_bprintf(&buf_script,
"bitrate=N/A\n");
1860 av_bprintf(&buf,
"bitrate=%6.1fkbits/s", bitrate);
1861 av_bprintf(&buf_script,
"bitrate=%6.1fkbits/s\n", bitrate);
1864 if (total_size < 0) av_bprintf(&buf_script,
"total_size=N/A\n");
1865 else av_bprintf(&buf_script,
"total_size=%"PRId64
"\n", total_size);
1866 if (
pts == AV_NOPTS_VALUE) {
1867 av_bprintf(&buf_script,
"out_time_us=N/A\n");
1868 av_bprintf(&buf_script,
"out_time_ms=N/A\n");
1869 av_bprintf(&buf_script,
"out_time=N/A\n");
1871 av_bprintf(&buf_script,
"out_time_us=%"PRId64
"\n",
pts);
1872 av_bprintf(&buf_script,
"out_time_ms=%"PRId64
"\n",
pts);
1873 av_bprintf(&buf_script,
"out_time=%s%02d:%02d:%02d.%06d\n",
1874 hours_sign, hours, mins, secs, us);
1879 av_bprintf(&buf_script,
"dup_frames=%"PRId64
"\n",
nb_frames_dup);
1880 av_bprintf(&buf_script,
"drop_frames=%"PRId64
"\n",
nb_frames_drop);
1883 av_bprintf(&buf,
" speed=N/A");
1884 av_bprintf(&buf_script,
"speed=N/A\n");
1886 av_bprintf(&buf,
" speed=%4.3gx", speed);
1887 av_bprintf(&buf_script,
"speed=%4.3gx\n", speed);
1891 const char end = is_last_report ?
'\n' :
'\r';
1892 if (
print_stats==1 && AV_LOG_INFO > av_log_get_level()) {
1895 av_log(NULL, AV_LOG_INFO,
"%s %c", buf.str, end);
1897 av_bprint_finalize(&buf, NULL);
1900 av_bprintf(&buf_script,
"progress=%s\n",
1901 is_last_report ?
"end" :
"continue");
1903 FFMIN(buf_script.len, buf_script.size - 1));
1905 av_bprint_finalize(&buf_script, NULL);
1906 if (is_last_report) {
1908 av_log(NULL, AV_LOG_ERROR,
1909 "Error closing progress log, loss of information possible: %s\n", av_err2str(
ret));
1925 ifilter->
format = par->format;
1927 ifilter->
width = par->width;
1928 ifilter->
height = par->height;
1930 ret = av_channel_layout_copy(&ifilter->
ch_layout, &par->ch_layout);
1943 AVCodecContext *enc = ost->
enc_ctx;
1954 av_log(NULL, AV_LOG_WARNING,
1955 "Finishing stream %d:%d without any data written to it.\n",
1962 if (ifilter->
format < 0 &&
1964 av_log(NULL, AV_LOG_ERROR,
"Error copying paramerets from input stream\n");
1974 av_log(NULL, AV_LOG_ERROR,
"Error configuring filter graph\n");
1984 if (enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO)
1988 if (
ret != AVERROR_EOF)
2018 int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->
mux_timebase);
2019 AVPacket *opkt = ost->
pkt;
2021 av_packet_unref(opkt);
2033 int64_t comp_start = start_time;
2036 if (
pkt->pts == AV_NOPTS_VALUE ?
2037 ist->
pts < comp_start :
2038 pkt->pts < av_rescale_q(comp_start, AV_TIME_BASE_Q, ist->
st->time_base))
2060 if (av_packet_ref(opkt,
pkt) < 0)
2063 if (
pkt->pts != AV_NOPTS_VALUE)
2064 opkt->pts = av_rescale_q(
pkt->pts, ist->
st->time_base, ost->
mux_timebase) - ost_tb_start_time;
2066 if (
pkt->dts == AV_NOPTS_VALUE) {
2067 opkt->dts = av_rescale_q(ist->
dts, AV_TIME_BASE_Q, ost->
mux_timebase);
2068 }
else if (ost->
st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
2069 int duration = av_get_audio_frame_duration(ist->
dec_ctx,
pkt->size);
2071 duration = ist->
dec_ctx->frame_size;
2072 opkt->dts = av_rescale_delta(ist->
st->time_base,
pkt->dts,
2073 (AVRational){1, ist->dec_ctx->sample_rate}, duration,
2076 opkt->pts = opkt->dts - ost_tb_start_time;
2079 opkt->dts -= ost_tb_start_time;
2081 opkt->duration = av_rescale_q(
pkt->duration, ist->
st->time_base, ost->
mux_timebase);
2094 if (
dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
2095 char layout_name[256];
2099 av_channel_layout_default(&
dec->ch_layout,
dec->ch_layout.nb_channels);
2100 if (
dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
2102 av_channel_layout_describe(&
dec->ch_layout, layout_name,
sizeof(layout_name));
2103 av_log(NULL, AV_LOG_WARNING,
"Guessed Channel Layout for Input Stream "
2104 "#%d.%d : %s\n", ist->
file_index, ist->
st->index, layout_name);
2142 AVFrameSideData *sd;
2143 int need_reinit,
ret;
2144 int buffersrc_flags = AV_BUFFERSRC_FLAG_PUSH;
2147 buffersrc_flags |= AV_BUFFERSRC_FLAG_KEEP_REF;
2150 need_reinit = ifilter->
format != frame->format;
2152 switch (ifilter->
ist->
st->codecpar->codec_type) {
2153 case AVMEDIA_TYPE_AUDIO:
2154 need_reinit |= ifilter->
sample_rate != frame->sample_rate ||
2155 av_channel_layout_compare(&ifilter->
ch_layout, &frame->ch_layout);
2157 case AVMEDIA_TYPE_VIDEO:
2158 need_reinit |= ifilter->
width != frame->width ||
2159 ifilter->
height != frame->height;
2170 if ((sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX))) {
2183 if (need_reinit || !fg->
graph) {
2185 AVFrame *tmp = av_frame_clone(frame);
2187 return AVERROR(ENOMEM);
2191 av_frame_free(&tmp);
2197 if (
ret < 0 &&
ret != AVERROR_EOF) {
2198 av_log(NULL, AV_LOG_ERROR,
"Error while filtering: %s\n", av_err2str(
ret));
2204 av_log(NULL, AV_LOG_ERROR,
"Error reinitializing filters!\n");
2209 ret = av_buffersrc_add_frame_flags(ifilter->
filter, frame, buffersrc_flags);
2211 if (
ret != AVERROR_EOF)
2212 av_log(NULL, AV_LOG_ERROR,
"Error while filtering: %s\n", av_err2str(
ret));
2229 ret = av_buffersrc_close(ifilter->
filter,
pts, AV_BUFFERSRC_FLAG_PUSH);
2235 if (ifilter->
format < 0) {
2240 if (ifilter->
format < 0 && (ifilter->
type == AVMEDIA_TYPE_AUDIO || ifilter->
type == AVMEDIA_TYPE_VIDEO)) {
2241 av_log(NULL, AV_LOG_ERROR,
"Cannot determine format of input stream %d:%d after EOF\n", ifilter->
ist->
file_index, ifilter->
ist->
st->index);
2242 return AVERROR_INVALIDDATA;
2253static int decode(AVCodecContext *avctx, AVFrame *frame,
int *got_frame, AVPacket *
pkt)
2260 ret = avcodec_send_packet(avctx,
pkt);
2263 if (
ret < 0 &&
ret != AVERROR_EOF)
2267 ret = avcodec_receive_frame(avctx, frame);
2268 if (
ret < 0 &&
ret != AVERROR(EAGAIN))
2283 if (
ret == AVERROR_EOF)
2286 av_log(NULL, AV_LOG_ERROR,
2287 "Failed to inject frame into filter network: %s\n", av_err2str(
ret));
2298 AVCodecContext *avctx = ist->
dec_ctx;
2300 AVRational decoded_frame_tb;
2308 if (
ret >= 0 && avctx->sample_rate <= 0) {
2309 av_log(avctx, AV_LOG_ERROR,
"Sample rate %d invalid\n", avctx->sample_rate);
2310 ret = AVERROR_INVALIDDATA;
2313 if (
ret != AVERROR_EOF)
2330 decoded_frame_tb = ist->
st->time_base;
2331 }
else if (
pkt &&
pkt->pts != AV_NOPTS_VALUE) {
2333 decoded_frame_tb = ist->
st->time_base;
2336 decoded_frame_tb = AV_TIME_BASE_Q;
2346 (AVRational){1, avctx->sample_rate});
2351 return err < 0 ? err :
ret;
2358 int i,
ret = 0, err = 0;
2359 int64_t best_effort_timestamp;
2360 int64_t
dts = AV_NOPTS_VALUE;
2365 if (!eof &&
pkt &&
pkt->size == 0)
2368 if (ist->
dts != AV_NOPTS_VALUE)
2369 dts = av_rescale_q(ist->
dts, AV_TIME_BASE_Q, ist->
st->time_base);
2379 return AVERROR(ENOMEM);
2392 if (ist->
st->codecpar->video_delay < ist->
dec_ctx->has_b_frames) {
2393 if (ist->
dec_ctx->codec_id == AV_CODEC_ID_H264) {
2394 ist->
st->codecpar->video_delay = ist->
dec_ctx->has_b_frames;
2396 av_log(ist->
dec_ctx, AV_LOG_WARNING,
2397 "video_delay is larger in decoder than demuxer %d > %d.\n"
2398 "If you want to help, upload a sample "
2399 "of this file to https://streams.videolan.org/upload/ "
2400 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n",
2402 ist->
st->codecpar->video_delay);
2405 if (
ret != AVERROR_EOF)
2412 av_log(NULL, AV_LOG_DEBUG,
"Frame parameters mismatch context %d,%d,%d != %d,%d,%d\n",
2437 best_effort_timestamp=
decoded_frame->best_effort_timestamp;
2443 if (eof && best_effort_timestamp == AV_NOPTS_VALUE && ist->
nb_dts_buffer > 0) {
2451 if(best_effort_timestamp != AV_NOPTS_VALUE) {
2452 int64_t ts = av_rescale_q(
decoded_frame->pts = best_effort_timestamp, ist->
st->time_base, AV_TIME_BASE_Q);
2454 if (ts != AV_NOPTS_VALUE)
2459 av_log(NULL, AV_LOG_INFO,
"decoder -> ist_index:%d type:video "
2460 "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",
2463 best_effort_timestamp,
2464 av_ts2timestr(best_effort_timestamp, &ist->
st->time_base),
2466 ist->
st->time_base.num, ist->
st->time_base.den);
2469 if (ist->
st->sample_aspect_ratio.num)
2476 return err < 0 ? err :
ret;
2484 int i,
ret = avcodec_decode_subtitle2(ist->
dec_ctx,
2500 1000, AV_TIME_BASE);
2501 if (end < ist->
prev_sub.subtitle.end_display_time) {
2502 av_log(ist->
dec_ctx, AV_LOG_DEBUG,
2503 "Subtitle duration reduced from %"PRId32
" to %d%s\n",
2505 end <= 0 ?
", dropping it" :
"");
2523 ist->
sub2video.
sub_queue = av_fifo_alloc2(8,
sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW);
2542 || ost->
enc->type != AVMEDIA_TYPE_SUBTITLE)
2558 int64_t
pts = av_rescale_q_rnd(ist->
pts, AV_TIME_BASE_Q, ist->
st->time_base,
2559 AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
2574 int eof_reached = 0;
2576 AVPacket *avpkt = ist->
pkt;
2580 ist->
dts = ist->
st->avg_frame_rate.num ? - ist->
dec_ctx->has_b_frames * AV_TIME_BASE / av_q2d(ist->
st->avg_frame_rate) : 0;
2584 ist->
dts += av_rescale_q(
pkt->pts, ist->
st->time_base, AV_TIME_BASE_Q);
2590 if (ist->
next_dts == AV_NOPTS_VALUE)
2592 if (ist->
next_pts == AV_NOPTS_VALUE)
2596 av_packet_unref(avpkt);
2597 ret = av_packet_ref(avpkt,
pkt);
2602 if (
pkt &&
pkt->dts != AV_NOPTS_VALUE) {
2603 ist->
next_dts = ist->
dts = av_rescale_q(
pkt->dts, ist->
st->time_base, AV_TIME_BASE_Q);
2610 int64_t duration_dts = 0;
2611 int64_t duration_pts = 0;
2613 int decode_failed = 0;
2618 switch (ist->
dec_ctx->codec_type) {
2619 case AVMEDIA_TYPE_AUDIO:
2622 av_packet_unref(avpkt);
2624 case AVMEDIA_TYPE_VIDEO:
2628 if (
pkt &&
pkt->duration) {
2629 duration_dts = av_rescale_q(
pkt->duration, ist->
st->time_base, AV_TIME_BASE_Q);
2630 }
else if(ist->
dec_ctx->framerate.num != 0 && ist->
dec_ctx->framerate.den != 0) {
2631 int ticks= av_stream_get_parser(ist->
st) ? av_stream_get_parser(ist->
st)->repeat_pict+1 : ist->
dec_ctx->ticks_per_frame;
2632 duration_dts = ((int64_t)AV_TIME_BASE *
2633 ist->
dec_ctx->framerate.den * ticks) /
2637 if(ist->
dts != AV_NOPTS_VALUE && duration_dts) {
2644 if (duration_pts > 0) {
2645 ist->
next_pts += av_rescale_q(duration_pts, ist->
st->time_base, AV_TIME_BASE_Q);
2650 av_packet_unref(avpkt);
2652 case AVMEDIA_TYPE_SUBTITLE:
2658 av_packet_unref(avpkt);
2664 if (
ret == AVERROR_EOF) {
2670 if (decode_failed) {
2671 av_log(NULL, AV_LOG_ERROR,
"Error while decoding stream #%d:%d: %s\n",
2674 av_log(NULL, AV_LOG_FATAL,
"Error while processing the decoded "
2675 "data for stream #%d:%d\n", ist->
file_index, ist->
st->index);
2707 av_log(NULL, AV_LOG_FATAL,
"Error marking filters as finished\n");
2715 switch (ist->
dec_ctx->codec_type) {
2716 case AVMEDIA_TYPE_AUDIO:
2717 av_assert1(
pkt->duration >= 0);
2718 if (ist->
dec_ctx->sample_rate) {
2722 ist->
next_dts += av_rescale_q(
pkt->duration, ist->
st->time_base, AV_TIME_BASE_Q);
2725 case AVMEDIA_TYPE_VIDEO:
2728 AVRational time_base_q = AV_TIME_BASE_Q;
2731 }
else if (
pkt->duration) {
2732 ist->
next_dts += av_rescale_q(
pkt->duration, ist->
st->time_base, AV_TIME_BASE_Q);
2733 }
else if(ist->
dec_ctx->framerate.num != 0) {
2734 int ticks= av_stream_get_parser(ist->
st) ? av_stream_get_parser(ist->
st)->repeat_pict + 1 : ist->
dec_ctx->ticks_per_frame;
2735 ist->
next_dts += ((int64_t)AV_TIME_BASE *
2736 ist->
dec_ctx->framerate.den * ticks) /
2755 return !eof_reached;
2758static enum AVPixelFormat
get_format(AVCodecContext *s,
const enum AVPixelFormat *pix_fmts)
2761 const enum AVPixelFormat *p;
2764 for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
2765 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(*p);
2766 const AVCodecHWConfig *config = NULL;
2769 if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
2775 config = avcodec_get_hw_config(s->codec, i);
2778 if (!(config->methods &
2779 AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX))
2781 if (config->pix_fmt == *p)
2789 av_log(NULL, AV_LOG_FATAL,
2790 "%s hwaccel requested for input stream #%d:%d, "
2791 "but cannot be initialized.\n",
2792 av_hwdevice_get_type_name(config->device_type),
2794 return AV_PIX_FMT_NONE;
2813 const AVCodec *codec = ist->
dec;
2815 snprintf(error, error_len,
"Decoder (codec %s) not found for input stream #%d:%d",
2817 return AVERROR(EINVAL);
2822#if LIBAVCODEC_VERSION_MAJOR < 60
2823 AV_NOWARN_DEPRECATED({
2824 ist->
dec_ctx->thread_safe_callbacks = 1;
2828 if (ist->
dec_ctx->codec_id == AV_CODEC_ID_DVB_SUBTITLE &&
2830 av_dict_set(&ist->
decoder_opts,
"compute_edt",
"1", AV_DICT_DONT_OVERWRITE);
2832 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");
2837 ist->
dec_ctx->pkt_timebase = ist->
st->time_base;
2839 if (!av_dict_get(ist->
decoder_opts,
"threads", NULL, 0))
2842 if (ist->
st->disposition & AV_DISPOSITION_ATTACHED_PIC)
2847 snprintf(error, error_len,
"Device setup failed for "
2848 "decoder on input stream #%d:%d : %s",
2854 if (
ret == AVERROR_EXPERIMENTAL)
2857 snprintf(error, error_len,
2858 "Error while opening decoder for input stream "
2881 return FFDIFFSIGN(*(
const int64_t *)a, *(
const int64_t *)b);
2886 AVBSFContext *ctx = ost->
bsf_ctx;
2892 ret = avcodec_parameters_copy(ctx->par_in, ost->
st->codecpar);
2896 ctx->time_base_in = ost->
st->time_base;
2898 ret = av_bsf_init(ctx);
2900 av_log(NULL, AV_LOG_ERROR,
"Error initializing bitstream filter: %s\n",
2905 ret = avcodec_parameters_copy(ost->
st->codecpar, ctx->par_out);
2908 ost->
st->time_base = ctx->time_base_out;
2917 AVCodecParameters *par_dst = ost->
st->codecpar;
2918 AVCodecParameters *par_src = ost->
ref_par;
2921 uint32_t codec_tag = par_dst->codec_tag;
2923 av_assert0(ist && !ost->
filter);
2925 ret = avcodec_parameters_to_context(ost->
enc_ctx, ist->
st->codecpar);
2929 av_log(NULL, AV_LOG_FATAL,
2930 "Error setting up codec context options.\n");
2934 ret = avcodec_parameters_from_context(par_src, ost->
enc_ctx);
2936 av_log(NULL, AV_LOG_FATAL,
2937 "Error getting reference codec parameters.\n");
2942 unsigned int codec_tag_tmp;
2943 if (!of->
format->codec_tag ||
2944 av_codec_get_id (of->
format->codec_tag, par_src->codec_tag) == par_src->codec_id ||
2945 !av_codec_get_tag2(of->
format->codec_tag, par_src->codec_id, &codec_tag_tmp))
2946 codec_tag = par_src->codec_tag;
2949 ret = avcodec_parameters_copy(par_dst, par_src);
2953 par_dst->codec_tag = codec_tag;
2961 ost->
st->avg_frame_rate = ist->
st->avg_frame_rate;
2968 if (ost->
st->time_base.num <= 0 || ost->
st->time_base.den <= 0) {
2972 ost->
st->time_base = av_add_q(av_stream_get_codec_timebase(ost->
st), (AVRational){0, 1});
2976 if (ost->
st->duration <= 0 && ist->
st->duration > 0)
2977 ost->
st->duration = av_rescale_q(ist->
st->duration, ist->
st->time_base, ost->
st->time_base);
2979 if (ist->
st->nb_side_data) {
2980 for (i = 0; i < ist->
st->nb_side_data; i++) {
2981 const AVPacketSideData *sd_src = &ist->
st->side_data[i];
2984 dst_data = av_stream_new_side_data(ost->
st, sd_src->type, sd_src->size);
2986 return AVERROR(ENOMEM);
2987 memcpy(dst_data, sd_src->data, sd_src->size);
2992 uint8_t *sd = av_stream_new_side_data(ost->
st, AV_PKT_DATA_DISPLAYMATRIX,
2993 sizeof(int32_t) * 9);
2998 switch (par_dst->codec_type) {
2999 case AVMEDIA_TYPE_AUDIO:
3001 av_log(NULL, AV_LOG_FATAL,
"-acodec copy and -vol are incompatible (frames are not decoded)\n");
3004 if((par_dst->block_align == 1 || par_dst->block_align == 1152 || par_dst->block_align == 576) && par_dst->codec_id == AV_CODEC_ID_MP3)
3005 par_dst->block_align= 0;
3006 if(par_dst->codec_id == AV_CODEC_ID_AC3)
3007 par_dst->block_align= 0;
3009 case AVMEDIA_TYPE_VIDEO:
3013 (AVRational){ par_dst->height, par_dst->width });
3014 av_log(NULL, AV_LOG_WARNING,
"Overriding aspect ratio "
3015 "with stream copy may produce invalid files\n");
3017 else if (ist->
st->sample_aspect_ratio.num)
3018 sar = ist->
st->sample_aspect_ratio;
3020 sar = par_src->sample_aspect_ratio;
3021 ost->
st->sample_aspect_ratio = par_dst->sample_aspect_ratio = sar;
3022 ost->
st->avg_frame_rate = ist->
st->avg_frame_rate;
3023 ost->
st->r_frame_rate = ist->
st->r_frame_rate;
3034 const AVDictionaryEntry *e;
3036 uint8_t *encoder_string;
3037 int encoder_string_len;
3038 int format_flags = 0;
3039 int codec_flags = ost->
enc_ctx->flags;
3041 if (av_dict_get(ost->
st->metadata,
"encoder", NULL, 0))
3044 e = av_dict_get(of->
opts,
"fflags", NULL, 0);
3046 const AVOption *o = av_opt_find(of->
ctx,
"fflags", NULL, 0, 0);
3049 av_opt_eval_flags(of->
ctx, o, e->value, &format_flags);
3053 const AVOption *o = av_opt_find(ost->
enc_ctx,
"flags", NULL, 0, 0);
3056 av_opt_eval_flags(ost->
enc_ctx, o, e->value, &codec_flags);
3059 encoder_string_len =
sizeof(LIBAVCODEC_IDENT) + strlen(ost->
enc->name) + 2;
3060 encoder_string = av_mallocz(encoder_string_len);
3061 if (!encoder_string)
3064 if (!(format_flags & AVFMT_FLAG_BITEXACT) && !(codec_flags & AV_CODEC_FLAG_BITEXACT))
3065 av_strlcpy(encoder_string, LIBAVCODEC_IDENT
" ", encoder_string_len);
3067 av_strlcpy(encoder_string,
"Lavc ", encoder_string_len);
3068 av_strlcat(encoder_string, ost->
enc->name, encoder_string_len);
3069 av_dict_set(&ost->
st->metadata,
"encoder", encoder_string,
3070 AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE);
3074 AVCodecContext *avctx)
3077 int n = 1, i, size, index = 0;
3080 for (p = kf; *p; p++)
3084 pts = av_malloc_array(size,
sizeof(*
pts));
3086 av_log(NULL, AV_LOG_FATAL,
"Could not allocate forced key frames array.\n");
3091 for (i = 0; i < n; i++) {
3092 char *next = strchr(p,
',');
3097 if (!memcmp(p,
"chapters", 8)) {
3102 if (avf->nb_chapters > INT_MAX - size ||
3103 !(
pts = av_realloc_f(
pts, size += avf->nb_chapters - 1,
3105 av_log(NULL, AV_LOG_FATAL,
3106 "Could not allocate forced key frames array.\n");
3110 t = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base);
3112 for (j = 0; j < avf->nb_chapters; j++) {
3113 AVChapter *c = avf->chapters[j];
3114 av_assert1(index < size);
3115 pts[index++] = av_rescale_q(c->start, c->time_base,
3116 avctx->time_base) + t;
3122 av_assert1(index < size);
3123 pts[index++] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base);
3130 av_assert0(index == size);
3139 AVCodecContext *enc_ctx = ost->
enc_ctx;
3140 AVFormatContext *oc;
3149 enc_ctx->time_base = ist->
st->time_base;
3154 av_log(oc, AV_LOG_WARNING,
"Input stream data not available, using default time base\n");
3157 enc_ctx->time_base = default_time_base;
3163 AVCodecContext *enc_ctx = ost->
enc_ctx;
3164 AVCodecContext *
dec_ctx = NULL;
3166 AVFormatContext *oc = of->
ctx;
3175 if (enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
3180 av_log(NULL, AV_LOG_WARNING,
3182 "about the input framerate is available. Falling "
3183 "back to a default value of 25fps for output stream #%d:%d. Use the -r option "
3184 "if you want a different framerate.\n",
3193 if (ost->
enc->supported_framerates && !ost->
force_fps) {
3194 int idx = av_find_nearest_q_idx(ost->
frame_rate, ost->
enc->supported_framerates);
3198 if (enc_ctx->codec_id == AV_CODEC_ID_MPEG4) {
3204 switch (enc_ctx->codec_type) {
3205 case AVMEDIA_TYPE_AUDIO:
3206 enc_ctx->sample_fmt = av_buffersink_get_format(ost->
filter->
filter);
3207 enc_ctx->sample_rate = av_buffersink_get_sample_rate(ost->
filter->
filter);
3208 ret = av_buffersink_get_ch_layout(ost->
filter->
filter, &enc_ctx->ch_layout);
3215 enc_ctx->bits_per_raw_sample = FFMIN(
dec_ctx->bits_per_raw_sample,
3216 av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
3221 case AVMEDIA_TYPE_VIDEO:
3224 if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
3225 enc_ctx->time_base = av_buffersink_get_time_base(ost->
filter->
filter);
3229 av_log(oc, AV_LOG_WARNING,
"Frame rate very high for a muxer not efficiently supporting it.\n"
3230 "Please consider specifying a lower framerate, a different muxer or "
3231 "setting vsync/fps_mode to vfr\n");
3234 enc_ctx->width = av_buffersink_get_w(ost->
filter->
filter);
3235 enc_ctx->height = av_buffersink_get_h(ost->
filter->
filter);
3236 enc_ctx->sample_aspect_ratio = ost->
st->sample_aspect_ratio =
3239 av_buffersink_get_sample_aspect_ratio(ost->
filter->
filter);
3241 enc_ctx->pix_fmt = av_buffersink_get_format(ost->
filter->
filter);
3246 enc_ctx->bits_per_raw_sample = FFMIN(
dec_ctx->bits_per_raw_sample,
3247 av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth);
3250 enc_ctx->color_range = frame->color_range;
3251 enc_ctx->color_primaries = frame->color_primaries;
3252 enc_ctx->color_trc = frame->color_trc;
3253 enc_ctx->colorspace = frame->colorspace;
3254 enc_ctx->chroma_sample_location = frame->chroma_location;
3263 if (enc_ctx->flags & (AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME) &&
3267 if (frame->interlaced_frame) {
3268 if (enc_ctx->codec->id == AV_CODEC_ID_MJPEG)
3269 enc_ctx->field_order = frame->top_field_first ? AV_FIELD_TT:AV_FIELD_BB;
3271 enc_ctx->field_order = frame->top_field_first ? AV_FIELD_TB:AV_FIELD_BT;
3273 enc_ctx->field_order = AV_FIELD_PROGRESSIVE;
3278 enc_ctx->field_order = AV_FIELD_BB;
3280 enc_ctx->field_order = AV_FIELD_TT;
3288 av_log(NULL, AV_LOG_ERROR,
3304 case AVMEDIA_TYPE_SUBTITLE:
3305 enc_ctx->time_base = AV_TIME_BASE_Q;
3306 if (!enc_ctx->width) {
3311 case AVMEDIA_TYPE_DATA:
3324 char *error,
int error_len)
3329 const AVCodec *codec = ost->
enc;
3330 AVCodecContext *
dec = NULL;
3339 if (
dec &&
dec->subtitle_header) {
3341 ost->
enc_ctx->subtitle_header = av_mallocz(
dec->subtitle_header_size + 1);
3342 if (!ost->
enc_ctx->subtitle_header)
3343 return AVERROR(ENOMEM);
3344 memcpy(ost->
enc_ctx->subtitle_header,
dec->subtitle_header,
dec->subtitle_header_size);
3345 ost->
enc_ctx->subtitle_header_size =
dec->subtitle_header_size;
3347 if (!av_dict_get(ost->
encoder_opts,
"threads", NULL, 0))
3352 snprintf(error, error_len,
"Device setup failed for "
3353 "encoder on output stream #%d:%d : %s",
3358 if (ist && ist->
dec->type == AVMEDIA_TYPE_SUBTITLE && ost->
enc->type == AVMEDIA_TYPE_SUBTITLE) {
3359 int input_props = 0, output_props = 0;
3360 AVCodecDescriptor
const *input_descriptor =
3361 avcodec_descriptor_get(
dec->codec_id);
3362 AVCodecDescriptor
const *output_descriptor =
3363 avcodec_descriptor_get(ost->
enc_ctx->codec_id);
3364 if (input_descriptor)
3365 input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
3366 if (output_descriptor)
3367 output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
3368 if (input_props && output_props && input_props != output_props) {
3369 snprintf(error, error_len,
3370 "Subtitle encoding currently only possible from text to text "
3371 "or bitmap to bitmap");
3372 return AVERROR_INVALIDDATA;
3377 if (
ret == AVERROR_EXPERIMENTAL)
3379 snprintf(error, error_len,
3380 "Error while opening encoder for output stream #%d:%d - "
3381 "maybe incorrect parameters such as bit_rate, rate, width or height",
3385 if (ost->
enc->type == AVMEDIA_TYPE_AUDIO &&
3386 !(ost->
enc->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE))
3391 ost->
enc_ctx->codec_id != AV_CODEC_ID_CODEC2 )
3392 av_log(NULL, AV_LOG_WARNING,
"The bitrate parameter is set too low."
3393 " It takes bits/s as argument, not kbits/s\n");
3395 ret = avcodec_parameters_from_context(ost->
st->codecpar, ost->
enc_ctx);
3397 av_log(NULL, AV_LOG_FATAL,
3398 "Error initializing the output stream codec context.\n");
3402 if (ost->
enc_ctx->nb_coded_side_data) {
3405 for (i = 0; i < ost->
enc_ctx->nb_coded_side_data; i++) {
3406 const AVPacketSideData *sd_src = &ost->
enc_ctx->coded_side_data[i];
3409 dst_data = av_stream_new_side_data(ost->
st, sd_src->type, sd_src->size);
3411 return AVERROR(ENOMEM);
3412 memcpy(dst_data, sd_src->data, sd_src->size);
3425 for (i = 0; i < ist->
st->nb_side_data; i++) {
3426 AVPacketSideData *sd = &ist->
st->side_data[i];
3427 if (sd->type != AV_PKT_DATA_CPB_PROPERTIES) {
3428 uint8_t *dst = av_stream_new_side_data(ost->
st, sd->type, sd->size);
3430 return AVERROR(ENOMEM);
3431 memcpy(dst, sd->data, sd->size);
3432 if (ist->
autorotate && sd->type == AV_PKT_DATA_DISPLAYMATRIX)
3433 av_display_rotation_set((uint32_t *)dst, 0);
3439 if (ost->
st->time_base.num <= 0 || ost->
st->time_base.den <= 0)
3440 ost->
st->time_base = av_add_q(ost->
enc_ctx->time_base, (AVRational){0, 1});
3443 if (ost->
st->duration <= 0 && ist && ist->
st->duration > 0)
3444 ost->
st->duration = av_rescale_q(ist->
st->duration, ist->
st->time_base, ost->
st->time_base);
3470 AVStream *
st = file->
ctx->streams[
pkt->stream_index];
3474 av_log(file->
ctx, AV_LOG_WARNING,
3475 "New %s stream %d:%d at pos:%"PRId64
" and DTS:%ss\n",
3476 av_get_media_type_string(
st->codecpar->codec_type),
3477 input_index,
pkt->stream_index,
3478 pkt->pos, av_ts2timestr(
pkt->dts, &
st->time_base));
3484 int ret = 0, i, j, k;
3485 AVFormatContext *oc;
3488 char error[1024] = {0};
3546 for (j = 0; j < ifile->
ctx->nb_programs; j++) {
3547 AVProgram *p = ifile->
ctx->programs[j];
3550 for (k = 0; k < p->nb_stream_indexes; k++)
3562 if (
output_files[i]->format->flags & AVFMT_NOSTREAMS && oc->nb_streams == 0) {
3571 av_log(NULL, AV_LOG_INFO,
"Stream mapping:\n");
3577 av_log(NULL, AV_LOG_INFO,
" Stream #%d:%d (%s) -> %s",
3582 av_log(NULL, AV_LOG_INFO,
"\n");
3592 av_log(NULL, AV_LOG_INFO,
" File %s -> Stream #%d:%d\n",
3599 av_log(NULL, AV_LOG_INFO,
" %s", ost->
filter->
name);
3603 av_log(NULL, AV_LOG_INFO,
" -> Stream #%d:%d (%s)\n", ost->
file_index,
3608 av_log(NULL, AV_LOG_INFO,
" Stream #%d:%d -> #%d:%d",
3614 av_log(NULL, AV_LOG_INFO,
" [sync #%d:%d]",
3618 av_log(NULL, AV_LOG_INFO,
" (copy)");
3621 const AVCodec *out_codec = ost->
enc;
3622 const char *decoder_name =
"?";
3623 const char *in_codec_name =
"?";
3624 const char *encoder_name =
"?";
3625 const char *out_codec_name =
"?";
3626 const AVCodecDescriptor *desc;
3629 decoder_name = in_codec->name;
3630 desc = avcodec_descriptor_get(in_codec->id);
3632 in_codec_name = desc->name;
3633 if (!strcmp(decoder_name, in_codec_name))
3634 decoder_name =
"native";
3638 encoder_name = out_codec->name;
3639 desc = avcodec_descriptor_get(out_codec->id);
3641 out_codec_name = desc->name;
3642 if (!strcmp(encoder_name, out_codec_name))
3643 encoder_name =
"native";
3646 av_log(NULL, AV_LOG_INFO,
" (%s (%s) -> %s (%s))",
3647 in_codec_name, decoder_name,
3648 out_codec_name, encoder_name);
3650 av_log(NULL, AV_LOG_INFO,
"\n");
3654 av_log(NULL, AV_LOG_ERROR,
"%s\n", error);
3678 for (j = 0; j < of->
ctx->nb_streams; j++)
3697 int64_t opts_min = INT64_MAX;
3702 int64_t opts = ost->
last_mux_dts == AV_NOPTS_VALUE ? INT64_MIN :
3706 av_log(NULL, AV_LOG_DEBUG,
3707 "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",
3713 if (!ost->
finished && opts < opts_min) {
3725 if (tcgetattr(0, &tty) == 0) {
3726 if (on) tty.c_lflag |= ECHO;
3727 else tty.c_lflag &= ~ECHO;
3728 tcsetattr(0, TCSANOW, &tty);
3737 return AVERROR_EXIT;
3745 av_log(NULL, AV_LOG_INFO,
"\n\n[q] command received. Exiting.\n\n");
3746 return AVERROR_EXIT;
3748 if (key ==
'+') av_log_set_level(av_log_get_level()+10);
3749 if (key ==
'-') av_log_set_level(av_log_get_level()-10);
3758 av_log_set_level(AV_LOG_DEBUG);
3760 if (key ==
'c' || key ==
'C'){
3761 char buf[4096], target[64], command[256], arg[256] = {0};
3764 av_log(NULL,
AV_LOG_STDERR,
"\nEnter command: <target>|all <time>|-1 <command>[ <argument>]\n");
3767 while ((k =
read_key()) !=
'\n' && k !=
'\r' && i <
sizeof(buf)-1)
3774 (n = sscanf(buf,
"%63[^ ] %lf %255[^ ] %255[^\n]", target, &time, command, arg)) >= 3) {
3775 av_log(NULL, AV_LOG_DEBUG,
"Processing command target:%s time:%f command:%s arg:%s",
3776 target, time, command, arg);
3781 ret = avfilter_graph_send_command(fg->
graph, target, command, arg, buf,
sizeof(buf),
3782 key ==
'c' ? AVFILTER_CMD_FLAG_ONE : 0);
3783 av_log(NULL,
AV_LOG_STDERR,
"Command reply for stream %d: ret:%d res:\n%s", i, ret, buf);
3784 }
else if (key ==
'c') {
3785 av_log(NULL,
AV_LOG_STDERR,
"Queuing commands only on filters supporting the specific command is unsupported\n");
3786 ret = AVERROR_PATCHWELCOME;
3788 ret = avfilter_graph_queue_command(fg->
graph, target, command, arg, 0, time);
3790 av_log(NULL,
AV_LOG_STDERR,
"Queuing command failed with error %s\n", av_err2str(ret));
3795 av_log(NULL, AV_LOG_ERROR,
3796 "Parse error, at least 3 arguments were expected, "
3797 "only %d given in string '%s'\n", n, buf);
3800 if (key ==
'd' || key ==
'D'){
3804 if(!debug) debug = 1;
3805 while (debug & FF_DEBUG_DCT_COEFF)
3812 while ((k =
read_key()) !=
'\n' && k !=
'\r' && i <
sizeof(buf)-1)
3818 if (k <= 0 || sscanf(buf,
"%d", &debug)!=1)
3828 if(debug) av_log_set_level(AV_LOG_DEBUG);
3833 "? show this help\n"
3834 "+ increase verbosity\n"
3835 "- decrease verbosity\n"
3836 "c Send command to first matching filter supporting it\n"
3837 "C Send/Queue command to all matching filters\n"
3838 "D cycle through available debug modes\n"
3839 "h dump packets/hex press to cycle through the 3 states\n"
3841 "s Show QP histogram\n"
3848static void *input_thread(
void *arg)
3851 AVPacket *pkt = f->
pkt, *queue_pkt;
3852 unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
3856 ret = av_read_frame(f->
ctx, pkt);
3858 if (ret == AVERROR(EAGAIN)) {
3863 av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
3866 queue_pkt = av_packet_alloc();
3868 av_packet_unref(pkt);
3869 av_thread_message_queue_set_err_recv(f->in_thread_queue, AVERROR(ENOMEM));
3872 av_packet_move_ref(queue_pkt, pkt);
3873 ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags);
3874 if (flags && ret == AVERROR(EAGAIN)) {
3876 ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags);
3877 av_log(f->
ctx, AV_LOG_WARNING,
3878 "Thread message queue blocking; consider raising the "
3879 "thread_queue_size option (current value: %d)\n",
3880 f->thread_queue_size);
3883 if (ret != AVERROR_EOF)
3884 av_log(f->
ctx, AV_LOG_ERROR,
3885 "Unable to send packet to main thread: %s\n",
3887 av_packet_free(&queue_pkt);
3888 av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
3896static void free_input_thread(
int i)
3901 if (!f || !f->in_thread_queue)
3903 av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF);
3904 while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0)
3905 av_packet_free(&pkt);
3907 pthread_join(f->thread, NULL);
3909 av_thread_message_queue_free(&f->in_thread_queue);
3912static void free_input_threads(
void)
3917 free_input_thread(i);
3920static int init_input_thread(
int i)
3925 if (f->thread_queue_size < 0)
3927 if (!f->thread_queue_size)
3930 if (f->
ctx->pb ? !f->
ctx->pb->seekable :
3931 strcmp(f->
ctx->iformat->name,
"lavfi"))
3932 f->non_blocking = 1;
3933 ret = av_thread_message_queue_alloc(&f->in_thread_queue,
3934 f->thread_queue_size,
sizeof(f->
pkt));
3938 if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) {
3939 av_log(NULL, AV_LOG_ERROR,
"pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
3940 av_thread_message_queue_free(&f->in_thread_queue);
3941 return AVERROR(ret);
3947static int init_input_threads(
void)
3952 ret = init_input_thread(i);
3959static int get_input_packet_mt(
InputFile *f, AVPacket **pkt)
3961 return av_thread_message_queue_recv(f->in_thread_queue, pkt,
3963 AV_THREAD_MESSAGE_NONBLOCK : 0);
3971 int64_t file_start =
copy_ts * (
3978 int64_t stream_ts_offset, pts, now;
3980 stream_ts_offset = FFMAX(ist->
first_dts != AV_NOPTS_VALUE ? ist->
first_dts : 0, file_start);
3981 pts = av_rescale(ist->
dts, 1000000, AV_TIME_BASE);
3982 now = (av_gettime_relative() - ist->
start) * scale + stream_ts_offset;
3984 return AVERROR(EAGAIN);
3989 if (f->thread_queue_size)
3990 return get_input_packet_mt(f, pkt);
3993 return av_read_frame(f->
ctx, *pkt);
4015static AVRational
duration_max(int64_t tmp, int64_t *duration, AVRational tmp_time_base,
4016 AVRational time_base)
4022 return tmp_time_base;
4025 ret = av_compare_ts(*duration, time_base, tmp, tmp_time_base);
4028 return tmp_time_base;
4037 AVCodecContext *avctx;
4038 int i, ret, has_audio = 0;
4039 int64_t duration = 0;
4041 ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
4052 if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->
nb_samples)
4061 if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->
nb_samples) {
4070 duration = av_rescale_q(1, av_inv_q(ist->
framerate), ist->
st->time_base);
4071 }
else if (ist->
st->avg_frame_rate.num) {
4072 duration = av_rescale_q(1, av_inv_q(ist->
st->avg_frame_rate), ist->
st->time_base);
4087 if (ifile->
loop > 0)
4103 AVFormatContext *is;
4106 int ret, thread_ret, i, j;
4109 int disable_discontinuity_correction =
copy_ts;
4114 if (ret == AVERROR(EAGAIN)) {
4118 if (ret < 0 && ifile->loop) {
4119 AVCodecContext *avctx;
4128 avcodec_flush_buffers(avctx);
4132 free_input_thread(file_index);
4136 thread_ret = init_input_thread(file_index);
4141 av_log(NULL, AV_LOG_WARNING,
"Seek to start failed.\n");
4144 if (ret == AVERROR(EAGAIN)) {
4150 if (ret != AVERROR_EOF) {
4175 return AVERROR(EAGAIN);
4181 av_pkt_dump_log2(NULL, AV_LOG_INFO, pkt,
do_hex_dump,
4182 is->streams[pkt->stream_index]);
4186 if (pkt->stream_index >= ifile->
nb_streams) {
4188 goto discard_packet;
4197 goto discard_packet;
4199 if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
4201 "%s: corrupt input packet in stream %d\n", is->url, pkt->stream_index);
4207 av_log(NULL, AV_LOG_INFO,
"demuxer -> ist_index:%d type:%s "
4208 "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 duration:%s duration_time:%s off:%s off_time:%s\n",
4209 ifile->
ist_index + pkt->stream_index, av_get_media_type_string(ist->
dec_ctx->codec_type),
4212 av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->
st->time_base),
4213 av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->
st->time_base),
4214 av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ist->
st->time_base),
4220 int64_t stime, stime2;
4224 if ( ist->
next_dts == AV_NOPTS_VALUE
4226 && (is->iformat->flags & AVFMT_TS_DISCONT)) {
4227 int64_t new_start_time = INT64_MAX;
4228 for (i=0; i<is->nb_streams; i++) {
4229 AVStream *st = is->streams[i];
4230 if(st->discard == AVDISCARD_ALL || st->start_time == AV_NOPTS_VALUE)
4232 new_start_time = FFMIN(new_start_time, av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q));
4234 if (new_start_time > is->start_time) {
4235 av_log(is, AV_LOG_VERBOSE,
"Correcting start time by %"PRId64
"\n", new_start_time - is->start_time);
4240 stime = av_rescale_q(is->start_time, AV_TIME_BASE_Q, ist->
st->time_base);
4241 stime2= stime + (1ULL<<ist->
st->pts_wrap_bits);
4244 if(stime2 > stime && pkt->dts != AV_NOPTS_VALUE && pkt->dts > stime + (1LL<<(ist->
st->pts_wrap_bits-1))) {
4245 pkt->dts -= 1ULL<<ist->
st->pts_wrap_bits;
4248 if(stime2 > stime && pkt->pts != AV_NOPTS_VALUE && pkt->pts > stime + (1LL<<(ist->
st->pts_wrap_bits-1))) {
4249 pkt->pts -= 1ULL<<ist->
st->pts_wrap_bits;
4256 for (i = 0; i < ist->
st->nb_side_data; i++) {
4257 AVPacketSideData *src_sd = &ist->
st->side_data[i];
4260 if (src_sd->type == AV_PKT_DATA_DISPLAYMATRIX)
4263 if (av_packet_get_side_data(pkt, src_sd->type, NULL))
4266 dst_data = av_packet_new_side_data(pkt, src_sd->type, src_sd->size);
4270 memcpy(dst_data, src_sd->data, src_sd->size);
4274 if (pkt->dts != AV_NOPTS_VALUE)
4275 pkt->dts += av_rescale_q(ifile->
ts_offset, AV_TIME_BASE_Q, ist->
st->time_base);
4276 if (pkt->pts != AV_NOPTS_VALUE)
4277 pkt->pts += av_rescale_q(ifile->
ts_offset, AV_TIME_BASE_Q, ist->
st->time_base);
4279 if (pkt->pts != AV_NOPTS_VALUE)
4281 if (pkt->dts != AV_NOPTS_VALUE)
4284 pkt_dts = av_rescale_q_rnd(pkt->dts, ist->
st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
4285 if ((ist->
dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO ||
4286 ist->
dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) &&
4287 pkt_dts != AV_NOPTS_VALUE && ist->
next_dts == AV_NOPTS_VALUE && !
copy_ts
4288 && (is->iformat->flags & AVFMT_TS_DISCONT) && ifile->
last_ts != AV_NOPTS_VALUE) {
4289 int64_t delta = pkt_dts - ifile->
last_ts;
4293 av_log(NULL, AV_LOG_DEBUG,
4294 "Inter stream timestamp discontinuity %"PRId64
", new offset= %"PRId64
"\n",
4296 pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->
st->time_base);
4297 if (pkt->pts != AV_NOPTS_VALUE)
4298 pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->
st->time_base);
4303 if (pkt->pts != AV_NOPTS_VALUE) {
4304 pkt->pts += duration;
4309 if (pkt->dts != AV_NOPTS_VALUE)
4310 pkt->dts += duration;
4312 pkt_dts = av_rescale_q_rnd(pkt->dts, ist->
st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
4314 if (
copy_ts && pkt_dts != AV_NOPTS_VALUE && ist->
next_dts != AV_NOPTS_VALUE &&
4315 (is->iformat->flags & AVFMT_TS_DISCONT) && ist->
st->pts_wrap_bits < 60) {
4316 int64_t wrap_dts = av_rescale_q_rnd(pkt->dts + (1LL<<ist->
st->pts_wrap_bits),
4317 ist->
st->time_base, AV_TIME_BASE_Q,
4318 AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
4320 disable_discontinuity_correction = 0;
4323 if ((ist->
dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO ||
4324 ist->
dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) &&
4325 pkt_dts != AV_NOPTS_VALUE && ist->
next_dts != AV_NOPTS_VALUE &&
4326 !disable_discontinuity_correction) {
4327 int64_t delta = pkt_dts - ist->
next_dts;
4328 if (is->iformat->flags & AVFMT_TS_DISCONT) {
4331 pkt_dts + AV_TIME_BASE/10 < FFMAX(ist->
pts, ist->
dts)) {
4333 av_log(NULL, AV_LOG_DEBUG,
4334 "timestamp discontinuity for stream #%d:%d "
4335 "(id=%d, type=%s): %"PRId64
", new offset= %"PRId64
"\n",
4337 av_get_media_type_string(ist->
dec_ctx->codec_type),
4339 pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->
st->time_base);
4340 if (pkt->pts != AV_NOPTS_VALUE)
4341 pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->
st->time_base);
4346 av_log(NULL, AV_LOG_WARNING,
"DTS %"PRId64
", next:%"PRId64
" st:%d invalid dropping\n", pkt->dts, ist->
next_dts, pkt->stream_index);
4347 pkt->dts = AV_NOPTS_VALUE;
4349 if (pkt->pts != AV_NOPTS_VALUE){
4350 int64_t pkt_pts = av_rescale_q(pkt->pts, ist->
st->time_base, AV_TIME_BASE_Q);
4354 av_log(NULL, AV_LOG_WARNING,
"PTS %"PRId64
", next:%"PRId64
" invalid dropping st:%d\n", pkt->pts, ist->
next_dts, pkt->stream_index);
4355 pkt->pts = AV_NOPTS_VALUE;
4361 if (pkt->dts != AV_NOPTS_VALUE)
4362 ifile->
last_ts = av_rescale_q(pkt->dts, ist->
st->time_base, AV_TIME_BASE_Q);
4365 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 duration:%s duration_time:%s off:%s off_time:%s\n",
4366 ifile->
ist_index + pkt->stream_index, av_get_media_type_string(ist->
dec_ctx->codec_type),
4367 av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->
st->time_base),
4368 av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->
st->time_base),
4369 av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ist->
st->time_base),
4380 if (ifile->thread_queue_size)
4381 av_packet_free(&pkt);
4384 av_packet_unref(pkt);
4399 int nb_requests, nb_requests_max = 0;
4404 ret = avfilter_graph_request_oldest(graph->
graph);
4408 if (ret == AVERROR_EOF) {
4414 if (ret != AVERROR(EAGAIN))
4417 for (i = 0; i < graph->
nb_inputs; i++) {
4418 ifilter = graph->
inputs[i];
4423 nb_requests = av_buffersrc_get_nb_failed_requests(ifilter->
filter);
4424 if (nb_requests > nb_requests_max) {
4425 nb_requests_max = nb_requests;
4455 av_log(NULL, AV_LOG_VERBOSE,
"No more inputs to read from, finishing.\n");
4463 av_log(NULL, AV_LOG_ERROR,
"Error reinitializing filters!\n");
4491 if (av_buffersink_get_type(ost->
filter->
filter) == AVMEDIA_TYPE_AUDIO)
4498 }
else if (ost->
filter) {
4517 if (ret == AVERROR(EAGAIN)) {
4524 return ret == AVERROR_EOF ? 0 : ret;
4535 AVFormatContext *os;
4538 int64_t timer_start;
4539 int64_t total_packets_written = 0;
4546 av_log(NULL, AV_LOG_INFO,
"Press [q] to stop, [?] for help\n");
4549 timer_start = av_gettime_relative();
4552 if ((ret = init_input_threads()) < 0)
4557 int64_t cur_time= av_gettime_relative();
4566 av_log(NULL, AV_LOG_VERBOSE,
"No more output streams to write to, finishing.\n");
4571 if (ret < 0 && ret != AVERROR_EOF) {
4572 av_log(NULL, AV_LOG_ERROR,
"Error while filtering: %s\n", av_err2str(ret));
4580 free_input_threads();
4607 if (os && os->oformat && !(os->oformat->flags & AVFMT_NOFILE)) {
4608 if ((ret = avio_closep(&os->pb)) < 0) {
4609 av_log(NULL, AV_LOG_ERROR,
"Error closing file %s: %s\n", os->url, av_err2str(ret));
4623 av_freep(&ost->
enc_ctx->stats_in);
4627 av_log(NULL, AV_LOG_FATAL,
"Empty output on stream %d.\n", i);
4633 av_log(NULL, AV_LOG_FATAL,
"Empty output\n");
4654 free_input_threads();
4663 av_log(NULL, AV_LOG_ERROR,
4664 "Error closing logfile, loss of information possible: %s\n",
4665 av_err2str(AVERROR(errno)));
4669 av_freep(&ost->
apad);
4684 struct rusage rusage;
4686 getrusage(RUSAGE_SELF, &rusage);
4688 (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
4690 (rusage.ru_stime.tv_sec * 1000000LL) + rusage.ru_stime.tv_usec;
4691#elif HAVE_GETPROCESSTIMES
4693 FILETIME c, e, k, u;
4694 proc = GetCurrentProcess();
4695 GetProcessTimes(proc, &c, &e, &k, &u);
4697 ((int64_t)u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
4699 ((int64_t)k.dwHighDateTime << 32 | k.dwLowDateTime) / 10;
4708#if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
4709 struct rusage rusage;
4710 getrusage(RUSAGE_SELF, &rusage);
4711 return (int64_t)rusage.ru_maxrss * 1024;
4712#elif HAVE_GETPROCESSMEMORYINFO
4714 PROCESS_MEMORY_COUNTERS memcounters;
4715 proc = GetCurrentProcess();
4716 memcounters.cb =
sizeof(memcounters);
4717 GetProcessMemoryInfo(proc, &memcounters,
sizeof(memcounters));
4718 return memcounters.PeakPagefileUsage;
4777 char _program_name[] =
"ffmpeg";
4781 #define OFFSET(x) offsetof(OptionsContext, x)
4799 {
"bsfs",
OPT_EXIT, { .func_arg =
show_bsfs },
"show available bit stream filters" },
4809 {
"report", 0, { .func_arg =
opt_report },
"generate a report" },
4810 {
"max_alloc",
HAS_ARG, { .func_arg =
opt_max_alloc },
"set maximum size of a single allocated block",
"bytes" },
4817 "list sources of the input device",
"device" },
4819 "list sinks of the output device",
"device" },
4824 "force format",
"fmt" },
4826 "overwrite output files" },
4828 "never overwrite output files" },
4830 "Ignore unknown stream types" },
4832 "Copy unknown stream types" },
4834 "allow recasting stream type in order to force a decoder of different media type" },
4837 "codec name",
"codec" },
4840 "codec name",
"codec" },
4843 "preset name",
"preset" },
4846 "set input stream mapping",
4847 "[-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]]" },
4849 "map an audio channel from one stream to another",
"file.stream.channel[:syncfile.syncstream]" },
4852 "set metadata information of outfile from infile",
4853 "outfile[,metadata]:infile[,metadata]" },
4856 "set chapters mapping",
"input_file_index" },
4859 "record or transcode \"duration\" seconds of audio/video",
4862 "record or transcode stop time",
"time_stop" },
4864 "set the limit file size in bytes",
"limit_size" },
4867 "set the start time offset",
"time_off" },
4870 "set the start time offset relative to EOF",
"time_off" },
4873 "enable/disable seeking by timestamp with -ss" },
4876 "enable/disable accurate seeking with -ss" },
4879 "Indicate the input index for sync reference",
"sync ref" },
4882 "set the input ts offset",
"time_off" },
4885 "set the input ts scale",
"scale" },
4887 "set the recording timestamp ('now' to set the current time)",
"time" },
4889 "add metadata",
"string=string" },
4891 "add program with specified streams",
"title=string:st=number..." },
4894 "set the number of data frames to output",
"number" },
4896 "add timings for benchmarking" },
4898 "add timings for each task" },
4900 "write program-readable progress information",
"url" },
4902 "enable or disable interaction on standard input" },
4904 "set max runtime in seconds in CPU user time",
"limit" },
4906 "dump each input packet" },
4908 "when dumping packets, also dump the payload" },
4911 "read input at native frame rate; equivalent to -readrate 1",
"" },
4914 "read input at specified rate",
"speed" },
4916 "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\" or \"dv50\" "
4917 "with optional prefixes \"pal-\", \"ntsc-\" or \"film-\")",
"type" },
4919 "set video sync method globally; deprecated, use -fps_mode",
"" },
4921 "frame drop threshold",
"" },
4923 "audio sync method",
"" },
4925 "audio drift threshold",
"threshold" },
4927 "copy timestamps" },
4929 "shift input timestamps to start at 0 when using copyts" },
4931 "copy input stream time base when stream copying",
"mode" },
4934 "finish encoding within shortest input" },
4942 "timestamp discontinuity delta threshold",
"threshold" },
4944 "timestamp error delta threshold",
"threshold" },
4946 "exit on error",
"error" },
4948 "abort on the specified condition flags",
"flags" },
4951 "copy initial non-keyframes" },
4953 "copy or discard frames before start time" },
4955 "set the number of frames to output",
"number" },
4958 "force codec tag/fourcc",
"fourcc/tag" },
4961 "use fixed quality scale (VBR)",
"q" },
4964 "use fixed quality scale (VBR)",
"q" },
4966 "set profile",
"profile" },
4968 "set stream filtergraph",
"filter_graph" },
4970 "number of non-complex filter threads" },
4972 "read stream filtergraph description from a file",
"filename" },
4974 "reinit filtergraph on input parameter changes",
"" },
4976 "create a complex filtergraph",
"graph_description" },
4978 "number of threads for -filter_complex" },
4980 "create a complex filtergraph",
"graph_description" },
4982 "read complex filtergraph description from a file",
"filename" },
4984 "enable automatic conversion filters globally" },
4986 "print progress report during encoding", },
4988 "set the period at which ffmpeg updates stats and -progress output",
"time" },
4991 "add an attachment to the output file",
"filename" },
4994 "extract an attachment into a file",
"filename" },
4996 OPT_OFFSET, { .off =
OFFSET(loop) },
"set number of times input stream shall be looped",
"loop count" },
4998 "print timestamp debugging info" },
5000 "ratio of decoding errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.",
"maximum error rate" },
5006 "disposition",
"" },
5008 { .off =
OFFSET(thread_queue_size) },
5009 "set the maximum number of queued packets from the demuxer" },
5011 "read and decode the streams to fill missing information with heuristics" },
5013 { .off =
OFFSET(bits_per_raw_sample) },
5014 "set the number of bits per raw sample",
"number" },
5018 "set the number of video frames to output",
"number" },
5021 "set frame rate (Hz value, fraction or abbreviation)",
"rate" },
5024 "set max frame rate (Hz value, fraction or abbreviation)",
"rate" },
5027 "set frame size (WxH or abbreviation)",
"size" },
5030 "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)",
"aspect" },
5033 "set pixel format",
"format" },
5038 "rate control override for specific intervals",
"override" },
5041 "force video codec ('copy' to copy stream)",
"codec" },
5043 "set initial TimeCode value.",
"hh:mm:ss[:;.]ff" },
5045 "select the pass number (1 to 3)",
"n" },
5048 "select two pass log file name prefix",
"prefix" },
5050 "calculate PSNR of compressed frames" },
5052 "dump video coding statistics to file" },
5054 "dump video coding statistics to file",
"file" },
5056 "Version of the vstats format to use."},
5058 "set video filters",
"filter_graph" },
5061 "specify intra matrix coeffs",
"matrix" },
5064 "specify inter matrix coeffs",
"matrix" },
5067 "specify intra matrix coeffs",
"matrix" },
5070 "top=1/bottom=0/auto=-1 field first",
"" },
5073 "force video tag/fourcc",
"fourcc/tag" },
5075 "show QP histogram" },
5078 "set framerate mode for matching video streams; overrides vsync" },
5081 "force the selected framerate, disable the best supported framerate selection" },
5084 "set the value of an outfile streamid",
"streamIndex:value" },
5087 "force key frames at specified timestamps",
"timestamps" },
5089 "audio bitrate (please use -b:a)",
"bitrate" },
5091 "video bitrate (please use -b:v)",
"bitrate" },
5094 "use HW accelerated decoding",
"hwaccel name" },
5097 "select a device for HW acceleration",
"devicename" },
5100 "select output format used with HW accelerated decoding",
"format" },
5102 "show available HW acceleration methods" },
5105 "automatically insert correct rotate filters" },
5108 "automatically insert a scale filter at the end of the filter graph" },
5112 "set the number of audio frames to output",
"number" },
5114 "set audio quality (codec-specific)",
"quality", },
5117 "set audio sampling rate (in Hz)",
"rate" },
5120 "set number of audio channels",
"channels" },
5125 "force audio codec ('copy' to copy stream)",
"codec" },
5128 "force audio tag/fourcc",
"fourcc/tag" },
5130 "change audio volume (256=normal)" ,
"volume" },
5133 "set sample format",
"format" },
5136 "set channel layout",
"layout" },
5139 "set channel layout",
"layout" },
5141 "set audio filters",
"filter_graph" },
5143 "set the maximum number of channels to try to guess the channel layout" },
5147 "disable subtitle" },
5149 "force subtitle codec ('copy' to copy stream)",
"codec" },
5151 ,
"force subtitle tag/fourcc",
"fourcc/tag" },
5153 "fix subtitles duration" },
5155 "set canvas size (WxH or abbreviation)",
"size" },
5159 "set the maximum demux-decode delay",
"seconds" },
5161 "set the initial demux-decode delay",
"seconds" },
5163 "specify a file in which to print sdp information",
"file" },
5166 "set the desired time base hint for output stream (1:24, 1:48000 or 0.04166, 2.0833e-5)",
"ratio" },
5168 "set the desired time base for the encoder (1:24, 1:48000 or 0.04166, 2.0833e-5). "
5169 "two special values are defined - "
5170 "0 = use frame rate (video) or sample rate (audio),"
5171 "-1 = match source time base",
"ratio" },
5174 "A comma-separated list of bitstream filters",
"bitstream_filters" },
5176 "deprecated",
"audio bitstream_filters" },
5178 "deprecated",
"video bitstream_filters" },
5181 "set the audio options to the indicated preset",
"preset" },
5183 "set the video options to the indicated preset",
"preset" },
5185 "set the subtitle options to the indicated preset",
"preset" },
5187 "set options from indicated preset file",
"filename" },
5190 "maximum number of packets that can be buffered while waiting for all streams to initialize",
"packets" },
5192 "set the threshold after which max_muxing_queue_size is taken into account",
"bytes" },
5196 "force data codec ('copy' to copy stream)",
"codec" },
5202 "set VAAPI hardware device (DRM path or X11 display name)",
"device" },
5207 "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)",
"device"},
5211 "initialise hardware device",
"args" },
5213 "set hardware device used when filtering",
"device" },
5224 if (savedCode == 0) {
5232 av_log_set_flags(AV_LOG_SKIP_REPEATED);
5236 avdevice_register_all();
5238 avformat_network_init();
5249 av_log(NULL, AV_LOG_WARNING,
"Use -h to get full help or, even better, run 'man %s'\n",
program_name);
5255 av_log(NULL, AV_LOG_FATAL,
"At least one output file must be specified\n");
5268 int64_t utime, stime, rtime;
5273 av_log(NULL, AV_LOG_INFO,
5274 "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n",
5275 utime / 1000000.0, stime / 1000000.0, rtime / 1000000.0);
5277 av_log(NULL, AV_LOG_DEBUG,
"%"PRIu64
" frames successfully decoded, %"PRIu64
" decoding errors\n",
__thread jmp_buf ex_buf__
const AVOutputFormat * format
int64_t start_time
start time in microseconds == AV_TIME_BASE units
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
struct OutputStream * ost
struct FilterGraph * graph
AVChannelLayout ch_layout
int copy_initial_nonkeyframes
double forced_keyframes_expr_const_values[FKF_NB]
AVRational frame_aspect_ratio
double rotate_override_value
int audio_channels_mapped
enum VideoSyncMethod vsync_method
AVRational max_frame_rate
AVCodecParameters * ref_par
const char * attachment_filename
int64_t last_nb0_frames[3]
struct InputStream * sync_ist
AVDictionary * encoder_opts
char * filters
filtergraph associated to the -filter option
int64_t forced_kf_ref_pts
char * filters_script
filtergraph script associated to the -filter_script option
AVExpr * forced_keyframes_pexpr