Go to the documentation of this file.
95 "New %s stream %d:%d at pos:%"PRId64
" and DTS:%ss\n",
103 int64_t last_duration)
108 ist->
max_pts - (uint64_t)ist->
min_pts < INT64_MAX - last_duration)
114 d->duration = last_duration;
130 if (
ifile->audio_duration_queue_size) {
134 int got_durations = 0;
136 while (got_durations < ifile->audio_duration_queue_size) {
147 for (
int i = 0;
i <
ifile->nb_streams;
i++) {
178 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s\n",
188 int64_t stime, stime2;
299 "%s: corrupt input packet in stream %d\n",
322 "Thread message queue blocking; consider raising the "
323 "thread_queue_size option (current value: %d)\n",
324 d->thread_queue_size);
329 "Unable to send packet to main thread: %s\n",
352 if (!
d->in_thread_queue)
368 if (
d->thread_queue_size <= 0)
372 (
f->ctx->pb ? !
f->ctx->pb->seekable :
373 strcmp(
f->ctx->iformat->name,
"lavfi")))
381 int nb_audio_dec = 0;
383 for (
int i = 0;
i <
f->nb_streams;
i++) {
394 f->audio_duration_queue_size = nb_audio_dec;
399 av_log(
NULL,
AV_LOG_ERROR,
"pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(
ret));
417 if (!
d->in_thread_queue) {
423 if (
f->readrate ||
f->rate_emu) {
425 int64_t file_start =
copy_ts * (
429 float scale =
f->rate_emu ? 1.0 :
f->readrate;
430 for (
i = 0;
i <
f->nb_streams;
i++) {
432 int64_t stream_ts_offset,
pts, now;
489 for (
int i = 0;
i <
f->nb_streams;
i++)
502 char *codec_name =
NULL;
526 if (
config->device_type == hwaccel_device_type) {
544 char layout_name[256];
561 double rotation = DBL_MAX;
562 int hflip = -1, vflip = -1;
563 int hflip_set = 0, vflip_set = 0, rotation_set = 0;
570 rotation_set = rotation != DBL_MAX;
571 hflip_set = hflip != -1;
572 vflip_set = vflip != -1;
574 if (!rotation_set && !hflip_set && !vflip_set)
584 rotation_set ? -(rotation) : -0.0
f);
587 hflip_set ? hflip : 0,
588 vflip_set ? vflip : 0);
603 const char *hwaccel =
NULL;
604 char *hwaccel_output_format =
NULL;
605 char *codec_tag =
NULL;
607 char *discard_str =
NULL;
630 uint32_t
tag = strtol(codec_tag, &next, 0);
641 hwaccel_output_format, ic, st);
643 if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel,
"cuvid")) {
645 "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
646 "with old commandlines. This behaviour is DEPRECATED and will be removed "
647 "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
649 }
else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel,
"qsv")) {
651 "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
652 "with old commandlines. This behaviour is DEPRECATED and will be removed "
653 "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
655 }
else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel,
"mediacodec")) {
659 }
else if (hwaccel_output_format) {
663 "format: %s", hwaccel_output_format);
671 if (!strcmp(hwaccel,
"nvdec") || !strcmp(hwaccel,
"cuvid"))
674 if (!strcmp(hwaccel,
"none"))
676 else if (!strcmp(hwaccel,
"auto"))
701 if (hwaccel_device) {
781 char *canvas_size =
NULL;
855 char * data_codec_name =
NULL;
856 int scan_all_pmts_set = 0;
863 if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
864 stop_time = INT64_MAX;
868 if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
870 if (stop_time <= start) {
874 recording_time = stop_time - start;
885 if (!strcmp(filename,
"-"))
889 strcmp(filename,
"fd:") &&
890 strcmp(filename,
"/dev/stdin");
960 scan_all_pmts_set = 1;
970 if (scan_all_pmts_set)
987 for (
i = 0;
i < orig_nb_streams;
i++)
1006 if (start_time_eof >= 0) {
1026 int64_t seek_timestamp = timestamp;
1029 int dts_heuristic = 0;
1037 if (dts_heuristic) {
1054 f->recording_time = recording_time;
1065 if (
f->readrate < 0.0f) {
1066 av_log(
NULL,
AV_LOG_ERROR,
"Option -readrate for Input #%d is %0.3f; it must be non-negative.\n",
f->index,
f->readrate);
1069 if (
f->readrate &&
f->rate_emu) {
1084 for (
i = 0;
i <
f->nb_streams;
i++) {
1104 "input file #%d (%s) is not a decoding option.\n", e->
key,
1111 "input file #%d (%s) has not been used for any stream. The most "
1112 "likely reason is either wrong type (e.g. a video option with "
1113 "no video streams) or that it is a private option of some decoder "
1114 "which was not actually used for any stream.\n", e->
key,
static void * input_thread(void *arg)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
#define AV_LOG_WARNING
Something somehow does not look correct.
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
SpecifierOpt * dump_attachment
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)
enum AVMediaType codec_type
General type of the encoded data.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
int ifile_open(const OptionsContext *o, const char *filename)
The official guide to swscale for confused that is
This struct describes the properties of an encoded stream.
#define ALLOC_ARRAY_ELEM(array, nb_elems)
static void ifile_duration_update(Demuxer *d, InputStream *ist, int64_t last_duration)
#define AVERROR_EOF
End of file.
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
#define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
void remove_avoptions(AVDictionary **a, AVDictionary *b)
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
@ AV_THREAD_MESSAGE_NONBLOCK
Perform non-blocking operation.
AVStream ** streams
A list of all streams in the file.
void ifile_close(InputFile **pf)
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
Flip the input matrix horizontally and/or vertically.
static const char * subtitle_codec_name
static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
AVRational avg_frame_rate
Average framerate.
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
Look up an AVHWDeviceType by name.
#define AV_LOG_VERBOSE
Detailed information.
enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
Iterate over supported device types.
void av_display_rotation_set(int32_t matrix[9], double angle)
Initialize a transformation matrix describing a pure clockwise rotation by the specified angle (in de...
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
SpecifierOpt * audio_channels
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
enum AVChannelOrder order
Channel order used in this layout.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
enum AVCodecID video_codec_id
Forced video codec_id.
int nb_channels
Number of channels in this layout.
static const AVInputFormat * file_iformat
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
static const AVCodec * choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st, enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type)
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
static const char *const opt_name_fix_sub_duration[]
void print_error(const char *filename, int err)
Print an error message to stderr, indicating filename and a human readable description of the error c...
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
void assert_file_overwrite(const char *filename)
static const char *const opt_name_display_vflips[]
AVChannelLayout ch_layout
Audio channel layout.
void report_and_exit(int ret)
Reports an error corresponding to the provided AVERROR code and calls exit_program() with the corresp...
static const char *const opt_name_hwaccel_output_formats[]
static const char *const opt_name_autorotate[]
@ AVDISCARD_NONE
discard nothing
int flags
AV_CODEC_FLAG_*.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
static const char *const opt_name_display_hflips[]
static av_always_inline float scale(float x, float s)
int av_thread_message_queue_recv(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Receive a message from the queue.
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
int ifile_get_packet(InputFile *f, AVPacket **pkt)
Get next input packet from the demuxer.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const char *const opt_name_display_rotations[]
const AVCodec * subtitle_codec
Forced subtitle codec.
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
AVDictionary * codec_opts
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate,...
int av_thread_message_queue_send(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Send a message on the queue.
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
static void dump_attachment(AVStream *st, const char *filename)
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
static const char *const opt_name_discard[]
char * specifier
stream/chapter/program/...
static const char *const opt_name_hwaccel_devices[]
int flags
Flags modifying the (de)muxer behaviour.
const struct AVInputFormat * iformat
The input container format.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
SpecifierOpt * audio_ch_layouts
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AVIO_FLAG_WRITE
write-only
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static const char *const opt_name_canvas_sizes[]
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
int av_usleep(unsigned usec)
Sleep for a period of time.
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
static const char *const opt_name_ts_scale[]
void assert_avoptions(AVDictionary *m)
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
int repeat_pict
This field is used for proper frame duration computation in lavf.
@ AVDISCARD_ALL
discard all
enum AVCodecID audio_codec_id
Forced audio codec_id.
AVDictionary * format_opts
static const char *const opt_name_guess_layout_max[]
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static Demuxer * demuxer_from_ifile(InputFile *f)
Describe the class of an AVClass context structure.
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
SpecifierOpt * frame_sizes
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Rational number (pair of numerator and denominator).
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
const AVCodec * audio_codec
Forced audio codec.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
static void report_new_stream(Demuxer *d, const AVPacket *pkt)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poin...
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
int extradata_size
Size of the extradata content in bytes.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int av_codec_is_decoder(const AVCodec *codec)
const AVCodec * data_codec
Forced data codec.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
static const char *const opt_name_hwaccels[]
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static int64_t start_time
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
Guess the frame rate, based on both the container and codec information.
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Setup AVCodecContext options for avformat_find_stream_info().
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
void * allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
Atomically add a new element to an array of pointers, i.e.
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
AVDictionary * strip_specifiers(const AVDictionary *dict)
int flags
A combination of AV_PKT_FLAG values.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
SpecifierOpt * frame_rates
#define AV_LOG_INFO
Standard information.
static const char * video_codec_name
int av_thread_message_queue_alloc(AVThreadMessageQueue **mq, unsigned nelem, unsigned elsize)
Allocate a new message queue.
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
#define AV_TIME_BASE
Internal time base represented as integer.
const AVCodec * find_codec_or_die(void *logctx, const char *name, enum AVMediaType type, int encoder)
SpecifierOpt * audio_sample_rate
void av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq, int err)
Set the sending error code.
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec)
Filter out options for given codec.
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
static int thread_start(Demuxer *d)
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
const AVIOInterruptCB int_cb
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
static void add_input_streams(const OptionsContext *o, Demuxer *d)
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
int av_opt_eval_int(void *obj, const AVOption *o, const char *val, int *int_out)
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
enum AVCodecID data_codec_id
Forced Data codec_id.
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
main external API structure.
int index
stream index in AVFormatContext
AVThreadMessageQueue * in_thread_queue
static const char * audio_codec_name
SpecifierOpt * frame_pix_fmts
const AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
static int seek_to_start(Demuxer *d)
const AVCodecHWConfig * avcodec_get_hw_config(const AVCodec *codec, int index)
Retrieve supported hardware configurations for a codec.
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
char * av_strdup(const char *s)
Duplicate a string.
static int guess_input_channel_layout(InputStream *ist)
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int video_delay
Video only.
static void thread_stop(Demuxer *d)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
void av_thread_message_queue_free(AVThreadMessageQueue **mq)
Free a message queue.
static void add_display_matrix_to_stream(const OptionsContext *o, AVFormatContext *ctx, AVStream *st)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int64_t pos
byte position in stream, -1 if unknown
static const char *const opt_name_reinit_filters[]
uint8_t * av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, size_t size)
Allocate new information from stream.
int width
picture width / height.
static void ist_free(InputStream **pist)
#define flags(name, subs,...)
void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq, int err)
Set the receiving error code.
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
void av_pkt_dump_log2(void *avcl, int level, const AVPacket *pkt, int dump_payload, const AVStream *st)
Send a nice dump of a packet to the log.
int pts_wrap_bits
Number of bits in timestamps.
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
const AVCodec * video_codec
Forced video codec.
static void thread_set_name(InputFile *f)
static int ff_thread_setname(const char *name)
enum AVCodecID subtitle_codec_id
Forced subtitle codec_id.