Go to the documentation of this file.
95 .parent_log_context_offset = offsetof(
EncoderPriv, log_parent),
100 Scheduler *sch,
unsigned sch_idx,
void *log_parent)
147 for (
int i = 0;;
i++) {
157 "frames context (format %s) with %s encoder.\n",
173 "(type %s) with %s encoder.\n", dev->
name,
235 frame->sample_rate > 0 &&
236 frame->ch_layout.nb_channels > 0);
243 if (
ost->bits_per_raw_sample)
257 ost->frame_aspect_ratio.num ?
259 frame->sample_aspect_ratio;
263 if (
ost->bits_per_raw_sample)
278 ||
ost->top_field_first >= 0
281 int top_field_first =
283 ost->top_field_first >= 0 ?
284 ost->top_field_first :
300 if (!enc_ctx->
width) {
301 enc_ctx->
width =
ost->ist->par->width;
333 "Encoding hardware device setup failed: %s\n",
av_err2str(
ret));
340 "incorrect parameters such as bit_rate, rate, width or height.\n");
352 " It takes bits/s as argument, not kbits/s\n");
377 int subtitle_out_max_size = 1024 * 1024;
378 int subtitle_out_size, nb,
i,
ret;
405 for (
i = 0;
i < nb;
i++) {
431 if (subtitle_out_size < 0) {
433 return subtitle_out_size;
513 "K" :
"N", 1);
continue;
534 static inline double psnr(
double d)
536 return -10.0 * log10(d);
548 double ti1,
bitrate, avg_bitrate;
549 double psnr_val = -1;
578 fprintf(
vstats_file,
"frame= %5"PRId64
" q= %2.1f ", frame_number,
581 fprintf(
vstats_file,
"out= %2d st= %2d frame= %5"PRId64
" q= %2.1f ",
597 fprintf(
vstats_file,
"s_size= %8.0fKiB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
611 const char *action =
frame ?
"encode" :
"flush";
622 if (
ost->enc_stats_pre.io)
631 "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
637 if (
frame->sample_aspect_ratio.num && !
ost->frame_aspect_ratio.num)
668 }
else if (
ret < 0) {
699 if (
ost->enc_stats_post.io)
705 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s "
706 "duration:%s duration_time:%s\n",
740 }
else if (kf->
pexpr) {
746 "force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n",
797 if (
ost->top_field_first >= 0) {
806 "Audio channel count changed and encoder does not support parameter changes\n");
819 ost->enc->enc_ctx->codec->name);
828 memset(et, 0,
sizeof(*et));
833 memset(et, 0,
sizeof(*et));
856 int ret = 0, input_status = 0;
876 while (!input_status) {
878 if (input_status < 0) {
static int frame_samples(const SyncQueue *sq, SyncQueueFrame frame)
static void error(const char *err)
const uint8_t * subtitle_header
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
int frame_size
Number of samples per channel in an audio frame.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
AVCodecParameters * par_enc
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.
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
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
#define atomic_store(object, desired)
int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int 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.
enum AVColorSpace colorspace
YUV colorspace type.
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
int sample_rate
samples per second
@ AV_PKT_DATA_QUALITY_STATS
This side data contains quality related information from the encoder.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AVERROR_EOF
End of file.
uint8_t * data
The data buffer.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int64_t start_time
start time in microseconds == AV_TIME_BASE units
This structure describes decoded (raw) audio or video data.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
int capabilities
Codec capabilities.
int depth
Number of bits in the component.
enum AVFieldOrder field_order
Field order.
uint8_t * subtitle_header
static enum AVPictureType forced_kf_apply(void *logctx, KeyframeForceCtx *kf, const AVFrame *frame)
#define AV_LOG_VERBOSE
Detailed information.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, const AVFrameSideData *src, unsigned int flags)
Add a new side data entry to an array based on existing side data, taking a reference towards the con...
int nb_channels
Number of channels in this layout.
#define AV_CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
static double psnr(double d)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about quality
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, AVPacket *pkt)
@ AV_FIELD_BT
Bottom coded first, top displayed first.
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
@ AV_FIELD_TT
Top coded_first, top displayed first.
#define AV_CODEC_FLAG_COPY_OPAQUE
const struct AVCodec * codec
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
#define AV_CODEC_FLAG_FRAME_DURATION
Signal to the encoder that the values of AVFrame.duration are valid and should be used (typically for...
AVChannelLayout ch_layout
Audio channel layout.
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
int flags
AV_CODEC_FLAG_*.
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_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
The codec supports this format via the hw_frames_ctx interface.
@ AV_FIELD_TB
Top coded first, bottom displayed first.
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
@ AV_CODEC_ID_DVB_SUBTITLE
static void enc_thread_uninit(EncoderThread *et)
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
AVRational frame_rate_filter
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_FRAME_SIDE_DATA_FLAG_UNIQUE
Remove existing entries before adding new ones.
int encoder_thread(void *arg)
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
EncStatsComponent * components
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
static const AVClass enc_class
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
int global_quality
Global quality for codecs which cannot change it per frame.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static const char * enc_item_name(void *obj)
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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.
void enc_stats_write(OutputStream *ost, EncStats *es, const AVFrame *frame, const AVPacket *pkt, uint64_t frame_num)
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
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.
int sch_enc_receive(Scheduler *sch, unsigned enc_idx, AVFrame *frame)
Called by encoder tasks to obtain frames for encoding.
@ AV_SIDE_DATA_PROP_GLOBAL
The side data type can be used in stream-global structures.
double expr_const_values[FKF_NB]
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
static EncoderPriv * ep_from_enc(Encoder *enc)
static int frame_encode(OutputStream *ost, AVFrame *frame, AVPacket *pkt)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
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).
int64_t bit_rate
the average bitrate
@ AV_PICTURE_TYPE_I
Intra.
int subtitle_header_size
Header containing style information for text subtitles.
int64_t wallclock[LATENCY_PROBE_NB]
int of_stream_init(OutputFile *of, OutputStream *ost, const AVCodecContext *enc_ctx)
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
void avio_w8(AVIOContext *s, int b)
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
int sch_enc_send(Scheduler *sch, unsigned enc_idx, AVPacket *pkt)
Called by encoder tasks to send encoded packets downstream.
#define pthread_mutex_unlock(a)
int enc_loopback(Encoder *enc)
static int enc_thread_init(EncoderThread *et)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
char * stats_out
pass1 encoding statistics output buffer
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
enum AVSampleFormat sample_fmt
audio sample format
#define AV_NOPTS_VALUE
Undefined timestamp value.
static int hw_device_setup_for_encode(Encoder *e, AVCodecContext *enc_ctx, AVBufferRef *frames_ref)
HWDevice * hw_device_get_by_type(enum AVHWDeviceType type)
@ AV_PICTURE_TYPE_NONE
Undefined.
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
uint32_t end_display_time
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)
int flags
A combination of AV_PKT_FLAG values.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
#define AV_LOG_INFO
Standard information.
static void enc_thread_set_name(const OutputStream *ost)
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
#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 av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
@ AV_FIELD_BB
Bottom coded first, bottom displayed first.
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...
const char * name
Name of the codec implementation.
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Supply a raw video or audio frame to the encoder.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
This struct describes a set or pool of "hardware" frames (i.e.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
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
int enc_open(void *opaque, const AVFrame *frame)
static int do_subtitle_out(OutputFile *of, OutputStream *ost, const AVSubtitle *sub, AVPacket *pkt)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
static int check_recording_time(OutputStream *ost, int64_t ts, AVRational tb)
This struct describes the properties of a side data type.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
const AVCodecHWConfig * avcodec_get_hw_config(const AVCodec *codec, int index)
Retrieve supported hardware configurations for a codec.
void enc_free(Encoder **penc)
#define AV_CODEC_CAP_PARAM_CHANGE
Codec supports changed parameters at any point.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
enum AVMediaType codec_type
A reference to a data buffer.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int enc_alloc(Encoder **penc, const AVCodec *codec, Scheduler *sch, unsigned sch_idx, void *log_parent)
int avcodec_parameters_from_context(struct AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
const AVSideDataDescriptor * av_frame_side_data_desc(enum AVFrameSideDataType type)
This structure stores compressed data.
FrameData * packet_data(AVPacket *pkt)
int width
picture width / height.
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
#define AV_PKT_FLAG_TRUSTED
The packet comes from a trusted source.
static int update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
uint32_t start_display_time
AVRational time_base
Time base of the packet's timestamps.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
#define pthread_mutex_lock(a)
static int ff_thread_setname(const char *name)