Go to the documentation of this file.
100 ost->enc_ctx->pix_fmt) {
106 for (
int i = 0;;
i++) {
114 config->pix_fmt ==
ost->enc_ctx->pix_fmt)) {
116 "frames context (format %s) with %s encoder.\n",
118 ost->enc_ctx->codec->name);
120 if (!
ost->enc_ctx->hw_frames_ctx)
132 "(type %s) with %s encoder.\n", dev->
name,
135 if (!
ost->enc_ctx->hw_device_ctx)
145 const char *cname =
ost->enc_ctx->codec->name;
146 uint8_t *encoder_string;
147 int encoder_string_len;
153 encoder_string =
av_mallocz(encoder_string_len);
160 av_strlcpy(encoder_string,
"Lavc ", encoder_string_len);
161 av_strlcat(encoder_string, cname, encoder_string_len);
217 if (
ost->bits_per_raw_sample)
231 ost->frame_aspect_ratio.num ?
237 if (
ost->bits_per_raw_sample)
258 "failed to configure video encoder: %s!\n",
267 ||
ost->top_field_first >= 0
270 int top_field_first =
272 ost->top_field_first >= 0 ?
273 ost->top_field_first :
287 if (
ost->enc_timebase.num)
289 "-enc_time_base not supported for subtitles, ignoring\n");
292 if (!enc_ctx->
width) {
293 enc_ctx->
width =
ost->ist->par->width;
331 "Encoding hardware device setup failed: %s\n",
av_err2str(
ret));
338 "incorrect parameters such as bit_rate, rate, width or height.\n");
344 if (
ost->enc_ctx->frame_size)
351 if (
ost->enc_ctx->bit_rate &&
ost->enc_ctx->bit_rate < 1000 &&
354 " It takes bits/s as argument, not kbits/s\n");
359 "Error initializing the output stream codec context.\n");
375 &
ost->par_in->nb_coded_side_data,
412 int subtitle_out_max_size = 1024 * 1024;
413 int subtitle_out_size, nb,
i,
ret;
440 for (
i = 0;
i < nb;
i++) {
463 ost->frames_encoded++;
466 if (subtitle_out_size < 0) {
468 return subtitle_out_size;
547 "K" :
"N", 1);
continue;
570 return -10.0 * log10(
d);
581 double ti1,
bitrate, avg_bitrate;
582 double psnr_val = -1;
611 fprintf(
vstats_file,
"frame= %5"PRId64
" q= %2.1f ", frame_number,
614 fprintf(
vstats_file,
"out= %2d st= %2d frame= %5"PRId64
" q= %2.1f ",
630 fprintf(
vstats_file,
"s_size= %8.0fKiB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
643 const char *action =
frame ?
"encode" :
"flush";
654 if (
ost->enc_stats_pre.io)
656 ost->frames_encoded);
658 ost->frames_encoded++;
663 "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
700 }
else if (
ret < 0) {
731 if (
ost->enc_stats_post.io)
737 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s "
738 "duration:%s duration_time:%s\n",
772 }
else if (kf->
pexpr) {
778 "force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n",
828 if (
ost->top_field_first >= 0) {
837 "Audio channel count changed and encoder does not support parameter changes\n");
850 ost->enc_ctx->codec->name);
859 memset(et, 0,
sizeof(*et));
864 memset(et, 0,
sizeof(*et));
886 int ret = 0, input_status = 0;
906 while (!input_status) {
908 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)
enum AVColorTransferCharacteristic color_trc
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
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.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
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.
enum AVColorPrimaries color_primaries
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
enum AVColorSpace colorspace
YUV colorspace type.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
int capabilities
Codec capabilities.
int depth
Number of bits in the component.
enum AVFieldOrder field_order
Field order.
AVRational avg_frame_rate
Average framerate.
uint8_t * subtitle_header
static enum AVPictureType forced_kf_apply(void *logctx, KeyframeForceCtx *kf, const AVFrame *frame)
#define AV_LOG_VERBOSE
Detailed information.
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.
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
#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.
static int set_encoder_id(OutputFile *of, OutputStream *ost)
#define AV_CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
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.
AVBufferRef * opaque_ref
Frame owner's private data.
enum AVChromaLocation chroma_location
@ AV_FIELD_TT
Top coded_first, top displayed first.
const struct AVCodec * codec
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
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,...)
AVChannelLayout ch_layout
Channel layout of the audio data.
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_FIELD_TB
Top coded first, bottom displayed first.
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
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
int encoder_thread(void *arg)
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
EncStatsComponent * components
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#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.
int nb_coded_side_data
Amount of entries in coded_side_data.
double expr_const_values[FKF_NB]
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
static int frame_encode(OutputStream *ost, AVFrame *frame, AVPacket *pkt)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
#define AV_DICT_MULTIKEY
Allow to store several equal keys in the dictionary.
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Rational number (pair of numerator and denominator).
enum AVPacketSideDataType type
@ AV_PICTURE_TYPE_I
Intra.
int subtitle_header_size
Header containing style information for text subtitles.
int64_t wallclock[LATENCY_PROBE_NB]
#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.
void avio_w8(AVIOContext *s, int b)
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
enum AVPictureType pict_type
Picture type of the frame.
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int sample_rate
Sample rate of the audio data.
enum AVSampleFormat sample_fmt
audio sample format
#define AV_NOPTS_VALUE
Undefined timestamp value.
int check_avoptions(AVDictionary *m)
AVRational time_base
Time base for the timestamps in this frame.
HWDevice * hw_device_get_by_type(enum AVHWDeviceType type)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
@ AV_PICTURE_TYPE_NONE
Undefined.
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 enc_alloc(Encoder **penc, const AVCodec *codec, Scheduler *sch, unsigned sch_idx)
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.
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
int nb_samples
number of audio samples (per channel) described by this frame
#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...
void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd)
Free all side data entries and their contents, then zeroes out the values which the pointers are poin...
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...
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
AVFrameSideData ** side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
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.
This struct describes a set or pool of "hardware" frames (i.e.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes,...
static int hw_device_setup_for_encode(OutputStream *ost, AVBufferRef *frames_ref)
AVPacketSideData * av_packet_side_data_new(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, size_t size, int flags)
Allocate a new packet side data.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
@ AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
The codec supports this format via the hw_frames_ctx interface.
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
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)
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 avcodec_parameters_from_context(struct AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
AVRational av_add_q(AVRational b, AVRational c)
Add two rationals.
This structure stores compressed data.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
FrameData * packet_data(AVPacket *pkt)
int width
picture width / height.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
#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
int of_stream_init(OutputFile *of, OutputStream *ost)
#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)