Go to the documentation of this file.
100 ost->enc_ctx->pix_fmt) {
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);
213 if (
ost->bits_per_raw_sample)
224 ost->frame_aspect_ratio.num ?
230 if (
ost->bits_per_raw_sample)
245 ||
ost->top_field_first >= 0
248 int top_field_first =
250 ost->top_field_first >= 0 ?
251 ost->top_field_first :
265 if (
ost->enc_timebase.num)
267 "-enc_time_base not supported for subtitles, ignoring\n");
270 if (!enc_ctx->
width) {
271 enc_ctx->
width =
ost->ist->par->width;
307 "Encoding hardware device setup failed: %s\n",
av_err2str(
ret));
314 "incorrect parameters such as bit_rate, rate, width or height.\n");
320 if (
ost->sq_idx_encode >= 0) {
326 if (
ost->enc_ctx->frame_size) {
329 ost->sq_idx_encode,
ost->enc_ctx->frame_size);
336 if (
ost->enc_ctx->bit_rate &&
ost->enc_ctx->bit_rate < 1000 &&
339 " It takes bits/s as argument, not kbits/s\n");
344 "Error initializing the output stream codec context.\n");
361 &
ost->par_in->nb_coded_side_data,
398 int subtitle_out_max_size = 1024 * 1024;
399 int subtitle_out_size, nb,
i,
ret;
428 for (
i = 0;
i < nb;
i++) {
451 ost->frames_encoded++;
454 if (subtitle_out_size < 0) {
456 return subtitle_out_size;
491 int64_t ptsi = INT64_MAX;
550 return -10.0 * log10(
d);
560 int64_t frame_number;
561 double ti1,
bitrate, avg_bitrate;
562 double psnr_val = -1;
588 fprintf(
vstats_file,
"frame= %5"PRId64
" q= %2.1f ", frame_number,
591 fprintf(
vstats_file,
"out= %2d st= %2d frame= %5"PRId64
" q= %2.1f ",
ost->file_index,
ost->
index, frame_number,
606 fprintf(
vstats_file,
"s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
619 const char *action =
frame ?
"encode" :
"flush";
623 if (
ost->enc_stats_pre.io)
625 ost->frames_encoded);
627 ost->frames_encoded++;
632 "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
670 }
else if (
ret < 0) {
681 if (
ost->enc_stats_post.io)
687 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s "
688 "duration:%s duration_time:%s\n",
697 "Subtitle heartbeat logic failed in %s! (%s)\n",
720 if (
ost->sq_idx_encode < 0)
746 }
else if (
ret < 0) {
770 "Audio channel count changed and encoder does not support parameter changes\n");
794 }
else if (kf->
pexpr) {
800 "force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n",
840 if (
ost->top_field_first >= 0) {
869 if (
ost->sq_idx_encode >= 0)
static void error(const char *err)
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.
#define AV_LOG_WARNING
Something somehow does not look correct.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
static AVCodecContext * dec_ctx
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.
void close_output_stream(OutputStream *ost)
int sample_rate
samples per second
@ AV_PKT_DATA_QUALITY_STATS
This side data contains quality related information from the encoder.
static enum AVPictureType forced_kf_apply(void *logctx, KeyframeForceCtx *kf, AVRational tb, const AVFrame *in_picture)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
@ AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
The codec supports this format via the hw_frames_ctx interface.
#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.
static int do_audio_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
AVRational avg_frame_rate
Average framerate.
uint8_t * subtitle_header
Header containing style information for text subtitles.
#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 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
static double psnr(double d)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
@ AV_FIELD_BT
Bottom coded first, top displayed first.
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
#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_*.
int enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub)
void update_benchmark(const char *fmt,...)
AVChannelLayout ch_layout
Channel layout of the audio data.
int sq_receive(SyncQueue *sq, int stream_idx, SyncQueueFrame frame)
Read a frame from the queue.
int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt)
@ 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...
static int do_video_out(OutputFile *of, OutputStream *ost, AVFrame *in_picture)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
@ AV_CODEC_ID_DVB_SUBTITLE
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_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.
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.
#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 enc_frame(OutputStream *ost, AVFrame *frame)
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 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.
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
#define AV_DICT_MULTIKEY
Allow to store several equal keys in the dictionary.
int enc_open(OutputStream *ost, const AVFrame *frame)
Rational number (pair of numerator and denominator).
enum AVPacketSideDataType type
@ AV_PICTURE_TYPE_I
Intra.
OutputStream * ost_iter(OutputStream *prev)
#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
void sq_frame_samples(SyncQueue *sq, unsigned int stream_idx, int frame_samples)
Set a constant output audio frame size, in samples.
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 av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
OutputFile ** output_files
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
int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame)
Submit a frame for the stream with index stream_idx.
#define AV_NOPTS_VALUE
Undefined timestamp value.
int check_avoptions(AVDictionary *m)
static int submit_encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
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.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
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)
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
#define AV_LOG_INFO
Standard information.
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
int of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
@ 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...
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.
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
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
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.
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)
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.
int enc_alloc(Encoder **penc, const AVCodec *codec)
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.