Go to the documentation of this file.
19 #include <stdatomic.h>
102 av_log(
s,
AV_LOG_WARNING,
"Invalid DTS: %"PRId64
" PTS: %"PRId64
" in output stream %d:%d, replacing by guess\n",
118 av_log(
s, loglevel,
"Non-monotonic DTS in output stream "
119 "%d:%d; previous: %"PRId64
", current: %"PRId64
"; ",
126 av_log(
s, loglevel,
"changing to %"PRId64
". This may result "
127 "in incorrect timestamps in the output file.\n",
144 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s size:%d\n",
159 "Error submitting a packet to the muxer: %s\n",
174 if (
ost->sq_idx_mux >= 0) {
229 int stream_idx, stream_eof = 0;
232 if (stream_idx < 0) {
249 }
else if (
ret < 0) {
263 return (
void*)(intptr_t)
ret;
297 unsigned int are_we_over_size =
302 if (new_size <= cur_size) {
304 "Too many packets buffered for output stream %d:%d.\n",
368 err_msg =
"submitting a packet for bitstream filtering";
379 err_msg =
"applying bitstream filters to a packet";
399 err_msg =
"submitting a packet to the muxer";
432 dts < ms->ts_copy_start :
447 opkt->pts -= ts_offset;
452 opkt->pts = opkt->dts - ts_offset;
454 opkt->dts -= ts_offset;
460 "Subtitle heartbeat logic failed in %s! (%s)\n",
479 if (!mux || !mux->
tq)
489 return (
int)(intptr_t)
ret;
515 for (
int i = 0;
i <
fc->nb_streams;
i++) {
568 printf(
"SDP:\n%s\n", sdp);
596 for (
i = 0;
i <
fc->nb_streams;
i++) {
598 if (!
ost->initialized)
619 }
else if (
ret == 1) {
689 ost->initialized = 1;
696 int64_t total_packets_written = 0;
704 total_packets_written += packets_written;
711 if (!packets_written &&
718 if (!total_packets_written) {
726 av_log(of,
level,
"Output file is empty, nothing was encoded%s\n",
727 pass1_used ?
"" :
"(check -ss / -t / -frames parameters if used)");
736 uint64_t total_packets = 0, total_size = 0;
737 uint64_t video_size = 0, audio_size = 0, subtitle_size = 0,
738 extra_size = 0, other_size = 0;
740 uint8_t overhead[16] =
"unknown";
757 default: other_size +=
s;
break;
768 ost->frames_encoded);
781 total_packets, total_size);
783 if (total_size && file_size > 0 && file_size >= total_size) {
784 snprintf(overhead,
sizeof(overhead),
"%f%%",
785 100.0 * (file_size - total_size) / total_size);
789 "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB other streams:%1.0fkB "
790 "global headers:%1.0fkB muxing overhead: %s\n",
793 subtitle_size / 1024.0,
803 int ret, mux_result = 0;
807 "Nothing was written into output file, because "
808 "at least one of its streams received no packets.\n");
851 if (fclose(
ost->logfile))
853 "Error closing logfile, loss of information possible: %s\n",
879 #if FFMPEG_OPT_MAP_CHANNEL
881 ost->audio_channels_mapped = 0;
891 for (
int i = 0;
i <
ost->enc_stats_pre.nb_components;
i++)
895 for (
int i = 0;
i <
ost->enc_stats_post.nb_components;
i++)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
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
size_t av_fifo_can_write(const AVFifo *f)
int of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
#define atomic_store(object, desired)
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)
This struct describes the properties of an encoded stream.
#define AVERROR_EOF
End of file.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static int print_sdp(void)
int max_muxing_queue_size
int64_t start_time
start time in microseconds == AV_TIME_BASE units
size_t muxing_queue_data_threshold
static void fc_close(AVFormatContext **pfc)
unsigned nb_output_dumped
int64_t ts_rescale_delta_last
void objpool_free(ObjPool **pop)
#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)
ObjPool * objpool_alloc_packets(void)
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.
#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
static int thread_stop(Muxer *mux)
int64_t of_filesize(OutputFile *of)
static void mux_final_stats(Muxer *mux)
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
int av_fifo_grow2(AVFifo *f, size_t inc)
Enlarge an AVFifo.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
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
static int thread_start(Muxer *mux)
int64_t duration
Decoding: duration of the stream, in stream time base.
int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#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 av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
int frame_size
Audio only.
EncStatsComponent * components
int mux_check_init(Muxer *mux)
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
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.
#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.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define atomic_load(object)
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.
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
void tq_free(ThreadQueue **ptq)
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.
void tq_receive_finish(ThreadQueue *tq, unsigned int stream_idx)
Mark the given stream finished from the receiving side.
#define avio_print(s,...)
Write strings (const char *) to the context.
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).
size_t av_fifo_can_read(const AVFifo *f)
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
atomic_int_least64_t last_filesize
int extradata_size
Size of the extradata content in bytes.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int tq_send(ThreadQueue *tq, unsigned int stream_idx, void *data)
Send an item for the given stream to the queue.
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...
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.
static int sync_queue_process(Muxer *mux, OutputStream *ost, AVPacket *pkt, int *stream_eof)
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")
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.
static void pkt_move(void *dst, void *src)
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.
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
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.
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.
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.
#define AV_LOG_INFO
Standard information.
static int64_t filesize(AVIOContext *pb)
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_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
size_t muxing_queue_data_size
static int submit_packet(Muxer *mux, AVPacket *pkt, OutputStream *ost)
#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.
int tq_receive(ThreadQueue *tq, int *stream_idx, void *data)
Read the next item from the queue.
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
static double limit(double x)
static void * muxer_thread(void *arg)
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
void enc_free(Encoder **penc)
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.
int index
stream index in AVFormatContext
#define atomic_fetch_add(object, operand)
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
static int queue_packet(OutputStream *ost, AVPacket *pkt)
static void ost_free(OutputStream **post)
This structure stores compressed data.
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
int of_stream_init(OutputFile *of, OutputStream *ost)
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
#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,...
const AVOutputFormat * format
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
#define ABORT_ON_FLAG_EMPTY_OUTPUT
static void thread_set_name(OutputFile *of)
int of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
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.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
static int thread_submit_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
static int bsf_init(MuxStream *ms)
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.