Go to the documentation of this file.
19 #include <stdatomic.h>
66 static const char *
desc[] = {
95 if (total == INT64_MIN) {
97 snprintf(latency,
sizeof(latency),
"total:%gms", total / 1e3);
106 if (val_next == INT64_MIN)
111 if (100. *
diff > 5. * total) {
120 av_strlcatf(latency,
sizeof(latency),
" %gms/%d%%",
121 diff / 1e3, (
int)(100. *
diff / total));
131 "duration:%s duration_time:%s size:%d latency(%s)\n",
135 pkt->
size, *latency ? latency :
"N/A");
142 #if FFMPEG_OPT_VSYNC_DROP
185 av_log(
ost, loglevel,
"Non-monotonic DTS; "
186 "previous: %"PRId64
", current: %"PRId64
"; ",
192 av_log(
ost, loglevel,
"changing to %"PRId64
". This may result "
193 "in incorrect timestamps in the output file.\n",
239 "Error submitting a packet to the muxer: %s\n",
328 err_msg =
"submitting a packet for bitstream filtering";
340 "Error applying bitstream filters to a packet: %s",
364 err_msg =
"submitting a packet to the muxer";
385 memset(mt, 0,
sizeof(*mt));
390 memset(mt, 0,
sizeof(*mt));
424 int stream_idx, stream_eof = 0;
428 if (stream_idx < 0) {
448 }
else if (
ret < 0) {
479 dts < ms->ts_copy_start :
537 printf(
"SDP:\n%s\n", sdp);
629 "Error initializing the output stream codec parameters.\n");
654 int64_t total_packets_written = 0;
662 total_packets_written += packets_written;
669 if (!packets_written &&
676 if (!total_packets_written) {
684 av_log(of,
level,
"Output file is empty, nothing was encoded%s\n",
685 pass1_used ?
"" :
"(check -ss / -t / -frames parameters if used)");
694 uint64_t total_packets = 0, total_size = 0;
695 uint64_t video_size = 0, audio_size = 0, subtitle_size = 0,
696 extra_size = 0, other_size = 0;
698 uint8_t overhead[16] =
"unknown";
715 default: other_size +=
s;
break;
726 ost->enc->frames_encoded);
739 total_packets, total_size);
741 if (total_size && file_size > 0 && file_size >= total_size) {
742 snprintf(overhead,
sizeof(overhead),
"%f%%",
743 100.0 * (file_size - total_size) / total_size);
747 "video:%1.0fKiB audio:%1.0fKiB subtitle:%1.0fKiB other streams:%1.0fKiB "
748 "global headers:%1.0fKiB muxing overhead: %s\n",
751 subtitle_size / 1024.0,
761 int ret, mux_result = 0;
765 "Nothing was written into output file, because "
766 "at least one of its streams received no packets.\n");
819 if (fclose(
ost->logfile))
821 "Error closing logfile, loss of information possible: %s\n",
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
int copy_initial_nonkeyframes
#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 atomic_store(object, desired)
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 MuxStream * ms_from_ost(OutputStream *ost)
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 AVMediaType codec_type
General type of the encoded data.
static Muxer * mux_from_of(OutputFile *of)
void sch_mux_receive_finish(Scheduler *sch, unsigned mux_idx, unsigned stream_idx)
Called by muxer tasks to signal that a stream will no longer accept input.
This struct describes the properties of an encoded stream.
#define atomic_fetch_add(object, operand)
#define AVERROR_EOF
End of file.
uint8_t * data
The data buffer.
void fg_free(FilterGraph **pfg)
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int64_t start_time
start time in microseconds == AV_TIME_BASE units
static void fc_close(AVFormatContext **pfc)
static void enc_stats_uninit(EncStats *es)
AVRational avg_frame_rate
Average framerate.
static int mux_thread_init(MuxThreadContext *mt)
int64_t ts_rescale_delta_last
#define AV_LOG_VERBOSE
Detailed information.
#define fc(width, name, range_min, range_max)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
void enc_stats_write(OutputStream *ost, EncStats *es, const AVFrame *frame, const AVPacket *pkt, uint64_t frame_num)
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
int64_t avio_size(AVIOContext *s)
Get the filesize.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
#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.
The bitstream filter state.
AVRational stream_duration_tb
int sch_mux_stream_ready(Scheduler *sch, unsigned mux_idx, unsigned stream_idx)
Signal to the scheduler that the specified muxed stream is initialized and ready.
int64_t of_filesize(OutputFile *of)
static void mux_final_stats(Muxer *mux)
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
static void mux_log_debug_ts(OutputStream *ost, const AVPacket *pkt)
int muxer_thread(void *arg)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static double val(void *priv, double ch)
int sq_receive(SyncQueue *sq, int stream_idx, SyncQueueFrame frame)
Read a frame from the queue.
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
int64_t duration
Decoding: duration of the stream, in stream time base.
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
@ LATENCY_PROBE_FILTER_PRE
static int of_streamcopy(OutputFile *of, OutputStream *ost, AVPacket *pkt)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
#define ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM
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 frame_size
Audio only.
EncStatsComponent * components
#define AVIO_FLAG_WRITE
write-only
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
AVRational time_base_in
The timebase used for the timestamps of the input packets.
static void thread_set_name(Muxer *mux)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static int sync_queue_process(Muxer *mux, MuxStream *ms, AVPacket *pkt, int *stream_eof)
#define atomic_load(object)
void * opaque
for some private data of the user
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.
av_warn_unused_result int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
void of_free(OutputFile **pof)
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
#define fs(width, name, subs,...)
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
#define avio_print(s,...)
Write strings (const char *) to the context.
atomic_uint nb_output_dumped
Rational number (pair of numerator and denominator).
AVCodecParameters * par_in
Codec parameters for packets submitted to the muxer (i.e.
int64_t wallclock[LATENCY_PROBE_NB]
atomic_int_least64_t last_filesize
int extradata_size
Size of the extradata content in bytes.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int of_write_trailer(OutputFile *of)
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static void mux_thread_uninit(MuxThreadContext *mt)
OutputFile ** output_files
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
#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 sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame)
Submit a frame for the stream with index stream_idx.
void sq_free(SyncQueue **psq)
#define AV_NOPTS_VALUE
Undefined timestamp value.
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
printf("static const uint8_t my_array[100] = {\n")
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size)
Generate an SDP for an RTP session.
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.
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.
AVPacket * fix_sub_duration_pkt
#define AV_LOG_INFO
Standard information.
int mux_check_init(void *arg)
static int64_t filesize(AVIOContext *pb)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
#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...
static int check_written(OutputFile *of)
#define av_malloc_array(a, b)
const AVIOInterruptCB int_cb
AVRational time_base_out
The timebase used for the timestamps of the output packets.
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
void enc_free(Encoder **penc)
const struct AVOutputFormat * oformat
The output container format.
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,...
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
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
int of_stream_init(OutputFile *of, OutputStream *ost, const AVCodecContext *enc_ctx)
int avio_open2(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
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.
static void ost_free(OutputStream **post)
This structure stores compressed data.
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
AVDictionary * enc_opts_used
int print_sdp(const char *filename)
static int mux_fixup_ts(Muxer *mux, MuxStream *ms, AVPacket *pkt)
int sch_mux_sub_heartbeat(Scheduler *sch, unsigned mux_idx, unsigned stream_idx, const AVPacket *pkt)
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
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.
@ PKT_OPAQUE_FIX_SUB_DURATION
#define ABORT_ON_FLAG_EMPTY_OUTPUT
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
AVRational time_base
Time base of the packet's timestamps.
static int mux_packet_filter(Muxer *mux, MuxThreadContext *mt, OutputStream *ost, AVPacket *pkt, int *stream_eof)
int sch_mux_receive(Scheduler *sch, unsigned mux_idx, AVPacket *pkt)
Called by muxer tasks to obtain packets for muxing.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
static int bsf_init(MuxStream *ms)
static int ff_thread_setname(const char *name)
@ LATENCY_PROBE_FILTER_POST