66 static const char *
desc[] = {
80 if (
pkt->opaque_ref) {
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");
159 pkt->time_base =
ost->st->time_base;
180 av_log(
ost, loglevel,
"Non-monotonic DTS; "
181 "previous: %"PRId64
", current: %"PRId64
"; ",
187 av_log(
ost, loglevel,
"changing to %"PRId64
". This may result "
188 "in incorrect timestamps in the output file.\n",
226 pkt->stream_index =
ost->index;
234 "Error submitting a packet to the muxer: %s\n",
266 return ret ==
AVERROR(EAGAIN) ? 0 : ret;
323 err_msg =
"submitting a packet for bitstream filtering";
335 "Error applying bitstream filters to a packet: %s",
359 err_msg =
"submitting a packet to the muxer";
380 memset(mt, 0,
sizeof(*mt));
385 memset(mt, 0,
sizeof(*mt));
419 int stream_idx, stream_eof = 0;
423 if (stream_idx < 0) {
443 }
else if (ret < 0) {
474 dts < ms->ts_copy_start :
485 pkt->pts -= ts_offset;
490 pkt->pts =
pkt->dts - ts_offset;
493 pkt->dts -= ts_offset;
532 printf(
"SDP:\n%s\n", sdp);
585 ctx->time_base_in =
ost->st->time_base;
597 ost->st->time_base =
ctx->time_base_out;
615 if (
ost->st->time_base.num <= 0 ||
ost->st->time_base.den <= 0)
624 "Error initializing the output stream codec parameters.\n");
649 int64_t total_packets_written = 0;
657 total_packets_written += packets_written;
664 if (!packets_written &&
671 if (!total_packets_written) {
679 av_log(of,
level,
"Output file is empty, nothing was encoded%s\n",
680 pass1_used ?
"" :
"(check -ss / -t / -frames parameters if used)");
689 uint64_t total_packets = 0, total_size = 0;
690 uint64_t video_size = 0, audio_size = 0, subtitle_size = 0,
691 extra_size = 0, other_size = 0;
693 uint8_t overhead[16] =
"unknown";
710 default: other_size +=
s;
break;
721 ost->enc->frames_encoded);
734 total_packets, total_size);
736 if (total_size && file_size > 0 && file_size >= total_size) {
737 snprintf(overhead,
sizeof(overhead),
"%f%%",
738 100.0 * (file_size - total_size) / total_size);
742 "video:%1.0fKiB audio:%1.0fKiB subtitle:%1.0fKiB other streams:%1.0fKiB "
743 "global headers:%1.0fKiB muxing overhead: %s\n",
746 subtitle_size / 1024.0,
756 int ret, mux_result = 0;
760 "Nothing was written into output file, because "
761 "at least one of its streams received no packets.\n");
814 if (fclose(
ost->logfile))
816 "Error closing logfile, loss of information possible: %s\n",
static double val(void *priv, double ch)
static AVFormatContext * ctx
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 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.
int64_t avio_size(AVIOContext *s)
Get the filesize.
#define avio_print(s,...)
Write strings (const char *) to the context.
#define AVIO_FLAG_WRITE
write-only
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
#define i(width, name, range_min, range_max)
#define fs(width, name, subs,...)
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
void avcodec_parameters_free(AVCodecParameters **ppar)
__device__ int printf(const char *,...)
static const uint16_t fc[]
#define atomic_store(object, desired)
#define atomic_load(object)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
const AVIOInterruptCB int_cb
atomic_uint nb_output_dumped
OutputFile ** output_files
@ PKT_OPAQUE_FIX_SUB_DURATION
@ LATENCY_PROBE_FILTER_POST
@ LATENCY_PROBE_FILTER_PRE
#define ABORT_ON_FLAG_EMPTY_OUTPUT
void enc_free(Encoder **penc)
#define ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM
void fg_free(FilterGraph **pfg)
void enc_stats_write(OutputStream *ost, EncStats *es, const AVFrame *frame, const AVPacket *pkt, uint64_t frame_num)
static int64_t filesize(AVIOContext *pb)
static int check_written(OutputFile *of)
static void fc_close(AVFormatContext **pfc)
static void thread_set_name(Muxer *mux)
int muxer_thread(void *arg)
static int bsf_init(MuxStream *ms)
int64_t of_filesize(OutputFile *of)
static void mux_log_debug_ts(OutputStream *ost, const AVPacket *pkt)
int of_stream_init(OutputFile *of, OutputStream *ost, const AVCodecContext *enc_ctx)
static Muxer * mux_from_of(OutputFile *of)
static int of_streamcopy(OutputFile *of, OutputStream *ost, AVPacket *pkt)
int print_sdp(const char *filename)
static int mux_packet_filter(Muxer *mux, MuxThreadContext *mt, OutputStream *ost, AVPacket *pkt, int *stream_eof)
static void mux_final_stats(Muxer *mux)
void of_free(OutputFile **pof)
static int mux_fixup_ts(Muxer *mux, MuxStream *ms, AVPacket *pkt)
int of_write_trailer(OutputFile *of)
static void enc_stats_uninit(EncStats *es)
static int mux_thread_init(MuxThreadContext *mt)
static void mux_thread_uninit(MuxThreadContext *mt)
static void ost_free(OutputStream **post)
int mux_check_init(void *arg)
static int sync_queue_process(Muxer *mux, MuxStream *ms, AVPacket *pkt, int *stream_eof)
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
static MuxStream * ms_from_ost(OutputStream *ost)
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.
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.
int sch_mux_sub_heartbeat(Scheduler *sch, unsigned mux_idx, unsigned stream_idx, const AVPacket *pkt)
int sch_mux_receive(Scheduler *sch, unsigned mux_idx, AVPacket *pkt)
Called by muxer tasks to obtain packets for muxing.
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 int64_t start_time
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PKT_FLAG_TRUSTED
The packet comes from a trusted source.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default 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.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
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.
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size)
Generate an SDP for an RTP session.
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,...
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVRational av_add_q(AVRational b, AVRational c)
Add two rationals.
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.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
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.
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,...
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
static int ff_thread_setname(const char *name)
Memory handling functions.
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
#define FF_ARRAY_ELEMS(a)
The bitstream filter state.
AVRational time_base_out
The timebase used for the timestamps of the output packets.
AVRational time_base_in
The timebase used for the timestamps of the input packets.
main external API structure.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
This struct describes the properties of an encoded stream.
int extradata_size
Size of the extradata content in bytes.
enum AVMediaType codec_type
General type of the encoded data.
const struct AVOutputFormat * oformat
The output container format.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void * opaque
for some private data of the user
AVRational time_base
Time base of the packet's timestamps.
Rational number (pair of numerator and denominator).
EncStatsComponent * components
int64_t wallclock[LATENCY_PROBE_NB]
AVCodecParameters * par_in
Codec parameters for packets submitted to the muxer (i.e.
int copy_initial_nonkeyframes
int64_t ts_rescale_delta_last
AVRational stream_duration_tb
AVPacket * fix_sub_duration_pkt
AVDictionary * enc_opts_used
atomic_int_least64_t last_filesize
int64_t start_time
start time in microseconds == AV_TIME_BASE units
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame)
Submit a frame for the stream with index stream_idx.
int sq_receive(SyncQueue *sq, int stream_idx, SyncQueueFrame frame)
Read a frame from the queue.
void sq_free(SyncQueue **psq)
#define av_malloc_array(a, b)
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
timestamp utils, mostly useful for debugging/logging purposes
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
#define atomic_fetch_add(object, operand)