66 #define SEGMENT_LIST_FLAG_CACHE 1 67 #define SEGMENT_LIST_FLAG_LIVE 2 121 char temp_list_filename[1024];
130 int needs_quoting = !!str[strcspn(str,
"\",\n\r")];
135 for (; *
str; str++) {
183 #if FF_API_LAVF_AVCTX 208 struct tm *tm, tmpbuf;
211 if (!strftime(buf,
sizeof(buf), s->
url, tm)) {
298 double max_duration = 0;
342 "Error writing list entry '%s' in list file\n", list_entry->
filename);
386 memcpy(entry, &seg->
cur_entry,
sizeof(*entry));
430 av_log(s,
AV_LOG_WARNING,
"Could not increment global timecode, error occurred during timecode creation.\n");
440 av_log(s,
AV_LOG_WARNING,
"Could not increment global timecode, no global timecode metadata found.\n");
450 av_log(s,
AV_LOG_WARNING,
"Could not increment stream %d timecode, error occurred during timecode creation.\n", i);
466 static int parse_times(
void *log_ctx, int64_t **times,
int *nb_times,
467 const char *times_str)
472 char *saveptr =
NULL;
477 #define FAIL(err) ret = err; goto end 480 for (p = times_str1; *p; p++)
491 for (i = 0; i < *nb_times; i++) {
493 char *tstr =
av_strtok(p,
",", &saveptr);
496 if (!tstr || !tstr[0]) {
505 "Invalid time duration specification '%s' in times list %s\n", tstr, times_str);
511 if (i && (*times)[i-1] > (*times)[i]) {
513 "Specified time %f is smaller than the last time %f\n",
514 (
float)((*times)[i])/1000000, (
float)((*times)[i-1])/1000000);
525 const char *frames_str)
531 for (p = frames_str; *p; p++)
542 for (i = 0; i < *nb_frames; i++) {
546 if (*p ==
'\0' || *p ==
',') {
551 f = strtol(p, &tailptr, 10);
552 if (*tailptr !=
'\0' && *tailptr !=
',' || f <= 0 || f >= INT_MAX) {
554 "Invalid argument '%s', must be a positive integer < INT_MAX\n",
564 if (i && (*frames)[i-1] > (*frames)[i]) {
566 "Specified frame %d is smaller than the last frame %d\n",
567 (*frames)[i], (*frames)[i-1]);
577 int buf_size = 32768;
604 static const enum AVMediaType type_priority_list[] = {
614 type_index_map[i] = -1;
619 if ((
unsigned)type < AVMEDIA_TYPE_NB && type_index_map[type] == -1
622 type_index_map[
type] =
i;
626 type = type_priority_list[
i];
698 "you can use output_ts_offset instead of it\n");
703 "segment_time, segment_times, and segment_frames options " 704 "are mutually exclusive, select just one of them\n");
716 if (seg->
time <= 0) {
717 av_log(s,
AV_LOG_ERROR,
"Invalid negative segment_time with segment_atclocktime option set\n");
737 seg->
use_rename = proto && !strcmp(proto,
"file");
787 "Some of the provided format options are not recognized\n");
851 int64_t end_pts = INT64_MAX,
offset;
852 int start_frame = INT_MAX;
864 if (pkt_extradata && pkt_extradata_size > 0) {
867 av_log(s,
AV_LOG_WARNING,
"Unable to add extradata to stream. Output segments may be invalid.\n");
884 time_t sec = avgt / 1000000;
886 usecs = (int64_t)(ti.tm_hour * 3600 + ti.tm_min * 60 + ti.tm_sec) * 1000000 + (avgt % 1000000);
888 if (wrapped_val < seg->last_val && wrapped_val < seg->clocktime_wrap_duration)
896 ff_dlog(s,
"packet stream:%d pts:%s pts_time:%s duration_time:%s is_key:%d frame:%d\n",
937 av_log(s,
AV_LOG_VERBOSE,
"segment:'%s' starts with packet stream:%d pts:%s pts_time:%s frame:%d\n",
942 av_log(s,
AV_LOG_DEBUG,
"stream:%d start_pts_time:%s pts:%s pts_time:%s dts:%s dts_time:%s",
1011 #define OFFSET(x) offsetof(SegmentContext, x) 1012 #define E AV_OPT_FLAG_ENCODING_PARAM 1014 {
"reference_stream",
"set reference stream",
OFFSET(reference_stream_specifier),
AV_OPT_TYPE_STRING, {.str =
"auto"}, 0, 0,
E },
1016 {
"segment_format_options",
"set list of options for the container format used for the segments",
OFFSET(format_options),
AV_OPT_TYPE_DICT, {.str =
NULL}, 0, 0, E },
1018 {
"segment_header_filename",
"write a single file containing the header",
OFFSET(header_filename),
AV_OPT_TYPE_STRING, {.str =
NULL}, 0, 0, E },
1024 {
"segment_list_size",
"set the maximum number of playlist entries",
OFFSET(list_size),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
1034 {
"segment_atclocktime",
"set segment to be cut at clocktime",
OFFSET(use_clocktime),
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E},
1035 {
"segment_clocktime_offset",
"set segment clocktime offset",
OFFSET(clocktime_offset),
AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, 86400000000LL, E},
1036 {
"segment_clocktime_wrap_duration",
"set segment clocktime wrapping duration",
OFFSET(clocktime_wrap_duration),
AV_OPT_TYPE_DURATION, {.i64 = INT64_MAX}, 0, INT64_MAX, E},
1038 {
"segment_time_delta",
"set approximation value used for the segment times",
OFFSET(time_delta),
AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, E },
1041 {
"segment_wrap",
"set number after which the index wraps",
OFFSET(segment_idx_wrap),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
1043 {
"segment_start_number",
"set the sequence number of the first segment",
OFFSET(segment_idx),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
1044 {
"segment_wrap_number",
"set the number of wrap before the first segment",
OFFSET(segment_idx_wrap_nb),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
1045 {
"strftime",
"set filename expansion with strftime at segment creation",
OFFSET(use_strftime),
AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
1046 {
"increment_tc",
"increment timecode between each segment",
OFFSET(increment_tc),
AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
1047 {
"break_non_keyframes",
"allow breaking segments on non-keyframes",
OFFSET(break_non_keyframes),
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
1049 {
"individual_header_trailer",
"write header/trailer to each segment",
OFFSET(individual_header_trailer),
AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E },
1050 {
"write_header_trailer",
"write a header to the first segment and a trailer to the last one",
OFFSET(write_header_trailer),
AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E },
1051 {
"reset_timestamps",
"reset timestamps at the beginning of each segment",
OFFSET(reset_timestamps),
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
1052 {
"initial_offset",
"set initial timestamp offset",
OFFSET(initial_offset),
AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, INT64_MAX, E },
1053 {
"write_empty_segments",
"allow writing empty 'filler' segments",
OFFSET(write_empty),
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
1057 #if CONFIG_SEGMENT_MUXER 1058 static const AVClass seg_class = {
1076 .priv_class = &seg_class,
1080 #if CONFIG_STREAM_SEGMENT_MUXER 1081 static const AVClass sseg_class = {
1089 .
name =
"stream_segment,ssegment",
1099 .priv_class = &sseg_class,
struct SegmentListEntry * next
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
AVBSFContext * bsfc
bitstream filter to run on stream
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
char * header_filename
filename to write the output header to
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
char * entry_prefix
prefix to add to list entry filenames
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
static av_cold int init(AVCodecContext *avctx)
int av_escape(char **dst, const char *src, const char *special_chars, enum AVEscapeMode mode, int flags)
Escape string in src, and put the escaped string in an allocated string in *dst, which must be freed ...
AVDictionary * format_options
static int segment_start(AVFormatContext *s, int write_header)
int segment_idx_wrap
number after which the index wraps
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
const char * av_default_item_name(void *ptr)
Return the context name.
#define AVIO_FLAG_WRITE
write-only
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define FF_ARRAY_ELEMS(a)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static __device__ float ceil(float a)
int segment_frame_count
number of reference frames in the segment
if it could not because there are no more frames
This struct describes the properties of an encoded stream.
static int parse_frames(void *log_ctx, int **frames, int *nb_frames, const char *frames_str)
static int seg_write_header(AVFormatContext *s)
static int segment_end(AVFormatContext *s, int write_trailer, int is_last)
int is_nullctx
whether avf->pb is a nullctx
int list_flags
flags affecting list generation
static int segment_mux_init(AVFormatContext *s)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static void close_null_ctxp(AVIOContext **pb)
int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *str, void *log_ctx)
Parse timecode representation (hh:mm:ss[:;.
static int seg_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
const char * av_basename(const char *path)
Thread safe basename.
Opaque data information usually continuous.
char temp_list_filename[1024]
enum AVCodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the AVCodecID for the given codec tag tag.
timestamp utils, mostly useful for debugging/logging purposes
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 offset
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the stream st contained in s is matched by the stream specifier spec.
static int seg_write_trailer(struct AVFormatContext *s)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int flags
Flags modifying the (de)muxer behaviour.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
int start
timecode frame start (first base frame number)
#define AV_LOG_VERBOSE
Detailed information.
int av_match_ext(const char *filename, const char *extensions)
Return a positive value if the given filename has one of the given extensions, 0 otherwise.
#define AVSTREAM_INIT_IN_WRITE_HEADER
stream parameters initialized in avformat_write_header
char * format
format to use for output segment files
static int select_reference_stream(AVFormatContext *s)
int64_t initial_offset
initial timestamps offset, expressed in microseconds
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Allocate and initialize an AVIOContext for buffered I/O.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionary * metadata
Metadata that applies to the whole file.
int individual_header_trailer
Set by a private option.
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
char * url
input or output URL.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
enum AVMediaType codec_type
General type of the encoded data.
simple assert() macros that are a bit more flexible than ISO C assert().
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t *size)
int64_t * times
list of segment interval specification
AVRational avg_frame_rate
Average framerate.
char * reference_stream_specifier
reference stream specifier
static int set_segment_filename(AVFormatContext *s)
int reference_stream_index
static int seg_init(AVFormatContext *s)
int nb_times
number of elments in the times array
static int segment_list_open(AVFormatContext *s)
int flags
A combination of AV_PKT_FLAG values.
int64_t last_val
remember last time for wrap around detection
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.
int extradata_size
Size of the extradata content in bytes.
Use auto-selected escaping mode.
AVIOContext * list_pb
list file put-byte context
common internal API header
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int ff_rename(const char *url_src, const char *url_dst, void *logctx)
Wrap avpriv_io_move and log if error happens.
static void print_csv_escaped_str(AVIOContext *ctx, const char *str)
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
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 int write_trailer(AVFormatContext *s1)
int use_strftime
flag to expand filename with strftime
ff_const59 AVOutputFormat * oformat
int reset_timestamps
reset timestamps at the beginning of each segment
int use_clocktime
flag to cut segments at regular clock time
int avoid_negative_ts
Avoid negative timestamps during muxing.
int increment_tc
flag to increment timecode if found
Opaque data information usually sparse.
av_warn_unused_result int avformat_init_output(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and initialize the codec, but do not write the header.
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
ff_const59 struct AVOutputFormat * oformat
The output container format.
static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
int64_t av_gettime(void)
Get the current time in microseconds.
char * list
filename for the segment list file
char * frames_str
segment frame numbers specification string
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
char * av_strdup(const char *s)
Duplicate a string.
AVStreamInternal * internal
An opaque field for libavformat internal usage.
static void seg_free(AVFormatContext *s)
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int header_written
whether we've already called avformat_write_header
AVIOContext * pb
I/O context.
void avio_w8(AVIOContext *s, int b)
int64_t time
segment duration
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 list
void(* io_close)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
int list_type
set the list type
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 segment_idx
index of the segment file to write, starting from 0
Describe the class of an AVClass context structure.
int * frames
list of frame number specification
ff_const59 AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
Rational number (pair of numerator and denominator).
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
SegmentListEntry * segment_list_entries
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.
#define flags(name, subs,...)
int nb_frames
number of elments in the frames array
char * av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum)
Load timecode string in buf.
int write_header_trailer
Set by a private option.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
static void segment_list_print_entry(AVIOContext *list_ioctx, ListType list_type, const SegmentListEntry *list_entry, void *log_ctx)
#define FF_DISABLE_DEPRECATION_WARNINGS
int64_t clocktime_wrap_duration
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
int disposition
AV_DISPOSITION_* bit field.
void avio_context_free(AVIOContext **s)
Free the supplied IO context and everything associated with it.
#define SEGMENT_LIST_FLAG_CACHE
int pts_wrap_bits
number of bits in pts (used for wrapping control)
static int parse_times(void *log_ctx, int64_t **times, int *nb_times, const char *times_str)
int segment_idx_wrap_nb
number of time the index has wraped
#define FF_ENABLE_DEPRECATION_WARNINGS
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
void * priv_data
Format private data.
static const AVOption options[]
#define AV_ESCAPE_FLAG_WHITESPACE
Consider spaces special and escape them even in the middle of the string.
static int check_bitstream(AVFormatContext *s, AVStream *st, AVPacket *pkt)
static void write_header(FFV1Context *f)
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
static int open_null_ctx(AVIOContext **ctx)
#define AVERROR_MUXER_NOT_FOUND
Muxer not found.
int segment_count
number of segment files already written
AVCodecParameters * codecpar
Codec parameters associated with this stream.
char * times_str
segment times specification string
#define av_malloc_array(a, b)
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
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
SegmentListEntry cur_entry
#define MKTAG(a, b, c, d)
unsigned int av_codec_get_tag(const struct AVCodecTag *const *tags, enum AVCodecID id)
Get the codec tag for the given codec id id.
int list_size
number of entries for the segment list file
This structure stores compressed data.
int frame_count
total number of reference frames
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
#define SEGMENT_LIST_FLAG_LIVE
SegmentListEntry * segment_list_entries_end
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
#define AV_TIMECODE_STR_SIZE