Go to the documentation of this file.
19 #include <stdatomic.h>
81 if (
ost->frame_rate.num &&
ost->is_cfr) {
96 av_log(
s,
AV_LOG_WARNING,
"Invalid DTS: %"PRId64
" PTS: %"PRId64
" in output stream %d:%d, replacing by guess\n",
112 av_log(
s, loglevel,
"Non-monotonous DTS in output stream "
113 "%d:%d; previous: %"PRId64
", current: %"PRId64
"; ",
120 av_log(
s, loglevel,
"changing to %"PRId64
". This may result "
121 "in incorrect timestamps in the output file.\n",
138 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s size:%d\n",
166 if (
ost->sq_idx_mux >= 0) {
215 int stream_idx, stream_eof = 0;
218 if (stream_idx < 0) {
243 return (
void*)(intptr_t)
ret;
277 unsigned int are_we_over_size =
282 if (new_size <= cur_size) {
284 "Too many packets buffered for output stream %d:%d.\n",
345 err_msg =
"submitting a packet for bitstream filtering";
356 err_msg =
"applying bitstream filters to a packet";
373 err_msg =
"submitting a packet to the muxer";
386 if (!mux || !mux->
tq)
396 return (
int)(intptr_t)
ret;
427 for (
int i = 0;
i <
fc->nb_streams;
i++) {
484 printf(
"SDP:\n%s\n", sdp);
512 for (
i = 0;
i <
fc->nb_streams;
i++) {
514 if (!
ost->initialized)
535 }
else if (
ret == 1) {
589 if (
ost->sq_idx_mux >= 0)
599 ost->initialized = 1;
612 "Nothing was written into output file, because "
613 "at least one of its streams received no packets.\n");
650 if (fclose(
ost->logfile))
652 "Error closing logfile, loss of information possible: %s\n",
679 #if FFMPEG_OPT_MAP_CHANNEL
681 ost->audio_channels_mapped = 0;
691 for (
int i = 0;
i <
ost->enc_stats_pre.nb_components;
i++)
695 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)
#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)
#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)
#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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
size_t muxing_queue_data_threshold
static void fc_close(AVFormatContext **pfc)
unsigned nb_output_dumped
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.
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.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
The bitstream filter state.
static int queue_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
static int thread_stop(Muxer *mux)
void print_error(const char *filename, int err)
Print an error message to stderr, indicating filename and a human readable description of the error c...
int64_t of_filesize(OutputFile *of)
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.
void of_close(OutputFile **pof)
static int thread_start(Muxer *mux)
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.
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.
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
void sq_set_tb(SyncQueue *sq, unsigned int stream_idx, AVRational tb)
Set the timebase for the stream with index stream_idx.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void enc_stats_write(OutputStream *ost, EncStats *es, const AVFrame *frame, const AVPacket *pkt, uint64_t frame_num)
#define atomic_load(object)
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.
#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.
size_t av_fifo_can_read(const AVFifo *f)
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
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...
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)
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.
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 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...
#define av_malloc_array(a, b)
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
const AVIOInterruptCB int_cb
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)
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.
void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
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...
const AVOutputFormat * format
static void thread_set_name(OutputFile *of)
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 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.