Go to the documentation of this file.
158 "Failed to inject frame into filter network: %s\n",
av_err2str(
ret));
168 const int prev =
d->last_frame_tb.den;
169 const int sr =
frame->sample_rate;
174 if (
frame->sample_rate ==
d->last_frame_sample_rate)
179 if (prev / gcd >= INT_MAX / sr) {
181 "Audio timestamps cannot be represented exactly after "
182 "sample rate change: %d -> %d\n", prev, sr);
191 if (
frame->time_base.num == 1 &&
frame->time_base.den > tb_new.
den &&
192 !(
frame->time_base.den % tb_new.
den))
193 tb_new =
frame->time_base;
197 d->last_frame_tb, tb_new);
198 d->last_frame_duration_est =
av_rescale_q(
d->last_frame_duration_est,
199 d->last_frame_tb, tb_new);
201 d->last_frame_tb = tb_new;
202 d->last_frame_sample_rate =
frame->sample_rate;
205 return d->last_frame_tb;
219 d->last_frame_pts +
d->last_frame_duration_est;
222 frame->pts = pts_pred;
233 &
d->last_filter_in_rescale_delta,
tb);
235 d->last_frame_pts =
frame->pts;
242 frame->time_base = tb_filter;
249 int64_t codec_duration = 0;
259 return frame->duration;
271 return codec_duration;
276 frame->pts >
d->last_frame_pts)
277 return frame->pts -
d->last_frame_pts;
280 if (
frame->duration > 0)
281 return frame->duration;
282 if (codec_duration > 0)
283 return codec_duration;
294 return FFMAX(
d->last_frame_duration_est, 1);
308 "video_delay is larger in decoder than demuxer %d > %d.\n"
309 "If you want to help, upload a sample "
310 "of this file to https://streams.videolan.org/upload/ "
311 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n",
335 if (
frame->format ==
d->hwaccel_pix_fmt) {
353 d->last_frame_pts +
d->last_frame_duration_est;
357 d->last_frame_pts =
frame->pts;
358 d->last_frame_tb =
frame->time_base;
362 "decoder -> pts:%s pts_time:%s "
363 "pkt_dts:%s pkt_dts_time:%s "
364 "duration:%s duration_time:%s "
365 "keyframe:%d frame_type:%d time_base:%d/%d\n",
404 if (end < sub_prev->end_display_time) {
406 "Subtitle duration reduced from %"PRId32
" to %d%s\n",
408 end <= 0 ?
", dropping it" :
"");
441 for (
int oidx = 0; oidx < ist->
nb_outputs; oidx++) {
458 AVSubtitle *prev_subtitle =
d->sub_prev[0]->buf[0] ?
463 !prev_subtitle->
num_rects || signal_pts <= prev_subtitle->
pts)
471 subtitle = (
AVSubtitle*)
d->sub_heartbeat->buf[0]->data;
472 subtitle->pts = signal_pts;
535 d->last_frame_pts +
d->last_frame_duration_est;
565 "This is a bug, please report it.\n");
595 }
else if (
ret < 0) {
607 "corrupt decoded frame\n");
661 memset(dt, 0,
sizeof(*dt));
666 memset(dt, 0,
sizeof(*dt));
689 int ret = 0, input_status = 0;
697 while (!input_status) {
698 int dummy, flush_buffers;
701 flush_buffers = input_status >= 0 && !dt.
pkt->
buf;
704 flush_buffers ?
"flush" :
"EOF");
713 flush_buffers ?
"resetting" :
"finishing");
731 }
else if (
ret < 0) {
763 return (
void*)(intptr_t)
ret;
769 int ret = 0, thread_ret;
800 if (!
d->frame->buf[0])
816 if (thread_ret < 0) {
906 if (
config->pix_fmt == *p)
911 d->hwaccel_pix_fmt = *p;
941 int err, auto_device = 0;
962 "specified for decoder: device %s of type %s is not "
963 "usable with hwaccel %s.\n", dev->
name,
1005 for (
i = 0; !dev;
i++) {
1013 "hwaccel type %s with existing device %s.\n",
1017 for (
i = 0; !dev;
i++) {
1031 "hwaccel type %s with new device created "
1036 "hwaccel type %s with new default device.\n",
1044 "disabled: no device found.\n");
1052 "for decoder: device type %s needed for codec %s.\n",
1072 "Decoding requested, but no decoder found for: %s\n",
1085 if (!
d->sub_prev[
i])
1089 if (!
d->sub_heartbeat)
1100 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");
1116 "Hardware device setup failed for decoder: %s\n",
static int process_subtitle(InputStream *ist, AVFrame *frame)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
static int send_filter_eof(InputStream *ist)
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
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
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Callback to negotiate the pixel format.
static AVRational audio_samplerate_update(void *logctx, Decoder *d, const AVFrame *frame)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AVERROR_EOF
End of file.
static void dec_thread_uninit(DecThreadContext *dt)
static void audio_ts_process(void *logctx, Decoder *d, AVFrame *frame)
static HWDevice * hw_device_match_by_codec(const AVCodec *codec)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
static int dec_thread_init(DecThreadContext *dt)
AVRational avg_frame_rate
Average framerate.
void objpool_free(ObjPool **pop)
#define AV_LOG_VERBOSE
Detailed information.
static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *frame)
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
ObjPool * objpool_alloc_packets(void)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void dec_free(Decoder **pdec)
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
static int hw_device_setup_for_decode(InputStream *ist)
const struct AVCodec * codec
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts)
void update_benchmark(const char *fmt,...)
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
@ AV_ROUND_UP
Round toward +infinity.
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
static int packet_decode(InputStream *ist, const AVPacket *pkt, AVFrame *frame)
static int dec_alloc(Decoder **pdec)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
@ AV_CODEC_ID_DVB_SUBTITLE
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
int enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
int av_thread_message_queue_send(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Send a message on the queue.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
Submit a packet for decoding.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int has_b_frames
Size of the frame reordering buffer in the decoder.
int last_frame_sample_rate
ThreadQueue * queue_in
Queue for sending coded packets from the main thread to the decoder thread.
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
int subtitle_wrap_frame(AVFrame *frame, AVSubtitle *subtitle, int copy)
int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder or encoder (when the AV_CODEC_FLAG_RECON_FRAME flag is used...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static enum AVPixelFormat pix_fmts[]
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static void dec_thread_set_name(const InputStream *ist)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int64_t pts
Same as packet pts, in AV_TIME_BASE.
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
ObjPool * objpool_alloc_frames(void)
int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb)
Rescale a timestamp while preserving known durations.
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the then the processing requires a frame on this link and the filter is expected to make efforts in that direction The status of input links is stored by the fifo and status_out fields
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
void tq_free(ThreadQueue **ptq)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
void tq_receive_finish(ThreadQueue *tq, unsigned int stream_idx)
Mark the given stream finished from the receiving side.
int hw_device_init_from_type(enum AVHWDeviceType type, const char *device, HWDevice **dev_out)
Rational number (pair of numerator and denominator).
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
static void frame_move(void *dst, void *src)
int tq_send(ThreadQueue *tq, unsigned int stream_idx, void *data)
Send an item for the given stream to the queue.
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
OutputFile ** output_files
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference)
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
#define AV_NOPTS_VALUE
Undefined timestamp value.
int check_avoptions(AVDictionary *m)
int dec_open(InputStream *ist)
HWDevice * hw_device_get_by_type(enum AVHWDeviceType type)
static void * decoder_thread(void *arg)
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
uint32_t end_display_time
int fix_sub_duration_heartbeat(InputStream *ist, int64_t signal_pts)
static void pkt_move(void *dst, void *src)
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
ThreadQueue * tq_alloc(unsigned int nb_streams, size_t queue_size, ObjPool *obj_pool, void(*obj_move)(void *dst, void *src))
Allocate a queue for sending data between threads.
static int dec_thread_stop(Decoder *d)
#define AV_LOG_INFO
Standard information.
static void sub2video_flush(InputStream *ist)
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
#define DECODING_FOR_FILTER
#define i(width, name, range_min, range_max)
#define AV_FRAME_FLAG_CORRUPT
The frame data may be corrupted, e.g.
#define AV_TIME_BASE
Internal time base represented as integer.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int64_t last_frame_duration_est
const char * name
Name of the codec implementation.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int tq_receive(ThreadQueue *tq, int *stream_idx, void *data)
Read the next item from the queue.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int transcode_subtitles(InputStream *ist, const AVPacket *pkt, AVFrame *frame)
int64_t frame_num
Frame counter, set by libavcodec.
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
#define FFSWAP(type, a, b)
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal codec state / flush internal buffers.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
void * opaque
Private data of the user, can be used to carry app specific stuff.
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.
static int video_frame_process(InputStream *ist, AVFrame *frame)
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb)
const AVCodecHWConfig * avcodec_get_hw_config(const AVCodec *codec, int index)
Retrieve supported hardware configurations for a codec.
enum AVMediaType codec_type
int video_delay
Video only.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int64_t last_filter_in_rescale_delta
This structure stores compressed data.
int ifilter_sub2video(InputFilter *ifilter, const AVFrame *frame)
ThreadQueue * queue_out
Queue for sending decoded frames from the decoder thread to the main thread.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int width
picture width / height.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq, int err)
Set the receiving error code.
#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...
static int err_merge(int err0, int err1)
Merge two return codes - return one of the error codes if at least one of them was negative,...
static int dec_thread_start(InputStream *ist)
HWDevice * hw_device_get_by_name(const char *name)
enum AVPixelFormat hwaccel_pix_fmt
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame)
static int ff_thread_setname(const char *name)
void tq_send_finish(ThreadQueue *tq, unsigned int stream_idx)
Mark the given stream finished from the sending side.