Go to the documentation of this file.
79 static int ism_write(
void *opaque,
const uint8_t *buf,
int buf_size)
96 if (whence != SEEK_SET)
168 for (
i = 0;
i <
s->nb_streams;
i++) {
186 int removed = 0,
i, start = 0;
197 if (!
final || removed)
208 char filename[1024], temp_filename[1024];
209 int ret,
i, video_chunks = 0, audio_chunks = 0, video_streams = 0, audio_streams = 0;
212 snprintf(filename,
sizeof(filename),
"%s/Manifest",
s->url);
213 snprintf(temp_filename,
sizeof(temp_filename),
"%s/Manifest.tmp",
s->url);
220 for (
i = 0;
i <
s->nb_streams;
i++) {
236 video_chunks = audio_chunks = 0;
238 if (
c->window_size) {
239 video_chunks =
FFMIN(video_chunks,
c->window_size);
240 audio_chunks =
FFMIN(audio_chunks,
c->window_size);
242 avio_printf(
out,
"<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" Duration=\"%"PRIu64
"\"",
duration);
244 avio_printf(
out,
" IsLive=\"true\" LookAheadFragmentCount=\"%d\" DVRWindowLength=\"0\"",
c->lookahead_count);
247 int last = -1,
index = 0;
248 avio_printf(
out,
"<StreamIndex Type=\"video\" QualityLevels=\"%d\" Chunks=\"%d\" Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n", video_streams, video_chunks);
249 for (
i = 0;
i <
s->nb_streams;
i++) {
254 avio_printf(
out,
"<QualityLevel Index=\"%d\" Bitrate=\"%"PRId64
"\" FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" CodecPrivateData=\"%s\" />\n",
index,
s->streams[
i]->codecpar->bit_rate, os->
fourcc,
s->streams[
i]->codecpar->width,
s->streams[
i]->codecpar->height, os->
private_str);
261 int last = -1,
index = 0;
262 avio_printf(
out,
"<StreamIndex Type=\"audio\" QualityLevels=\"%d\" Chunks=\"%d\" Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n", audio_streams, audio_chunks);
263 for (
i = 0;
i <
s->nb_streams;
i++) {
268 avio_printf(
out,
"<QualityLevel Index=\"%d\" Bitrate=\"%"PRId64
"\" FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" BitsPerSample=\"16\" PacketSize=\"%d\" AudioTag=\"%d\" CodecPrivateData=\"%s\" />\n",
269 index,
s->streams[
i]->codecpar->bit_rate, os->
fourcc,
s->streams[
i]->codecpar->sample_rate,
288 if (mkdir(
s->url, 0777) == -1 && errno != EEXIST) {
298 c->streams =
av_calloc(
s->nb_streams,
sizeof(*
c->streams));
303 for (
i = 0;
i <
s->nb_streams;
i++) {
309 if (!
s->streams[
i]->codecpar->bit_rate) {
317 if (mkdir(os->
dirname, 0777) == -1 && errno != EEXIST) {
381 if (!
c->has_video &&
c->min_frag_duration <= 0) {
401 if (*moof_size < 8 || *moof_size >
size)
406 if (
len > *moof_size)
418 if (len < 8 || len >= *moof_size)
420 if (
tag ==
MKTAG(
'u',
'u',
'i',
'd')) {
421 static const AVUUID tfxd = {
422 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
423 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
502 for (
i = 0;
i <
s->nb_streams;
i++) {
504 char filename[1024], target_filename[1024], header_filename[1024], curr_dirname[1024];
526 if (!
s->streams[
i]->codecpar->bit_rate) {
535 s->streams[
i]->codecpar->bit_rate =
bitrate;
547 copy_moof(
s, filename, header_filename, moof_size);
555 if (
c->window_size || (
final &&
c->remove_at_exit)) {
556 for (
i = 0;
i <
s->nb_streams;
i++) {
559 int remove = os->
nb_fragments -
c->window_size -
c->extra_window_size -
c->lookahead_count;
560 if (
final &&
c->remove_at_exit)
563 for (j = 0; j < remove; j++) {
571 if (
final &&
c->remove_at_exit)
612 if (
c->remove_at_exit) {
614 snprintf(filename,
sizeof(filename),
"%s/Manifest",
s->url);
622 #define OFFSET(x) offsetof(SmoothStreamingContext, x)
623 #define E AV_OPT_FLAG_ENCODING_PARAM
625 {
"window_size",
"number of fragments kept in the manifest",
OFFSET(window_size),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
E },
626 {
"extra_window_size",
"number of fragments kept outside of the manifest before removing from disk",
OFFSET(extra_window_size),
AV_OPT_TYPE_INT, { .i64 = 5 }, 0, INT_MAX,
E },
627 {
"lookahead_count",
"number of lookahead fragments",
OFFSET(lookahead_count),
AV_OPT_TYPE_INT, { .i64 = 2 }, 0, INT_MAX,
E },
628 {
"min_frag_duration",
"minimum fragment duration (in microseconds)",
OFFSET(min_frag_duration),
AV_OPT_TYPE_INT64, { .i64 = 5000000 }, 0, INT_MAX,
E },
629 {
"remove_at_exit",
"remove all fragments when finished",
OFFSET(remove_at_exit),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
642 .
p.
name =
"smoothstreaming",
static int64_t ffurl_seek(URLContext *h, int64_t pos, int whence)
Change the position that will be used by the next read/write operation on the resource accessed by h.
#define AV_LOG_WARNING
Something somehow does not look correct.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
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.
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.
uint8_t AVUUID[AV_UUID_LEN]
int64_t first_dts
Timestamp corresponding to the last dts sync point.
This struct describes the properties of an encoded stream.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
void avio_context_free(AVIOContext **s)
Free the supplied IO context and everything associated with it.
char * protocol_blacklist
',' separated list of disallowed protocols.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static int ffurl_write(URLContext *h, const uint8_t *buf, int size)
Write size bytes from buf to the resource accessed by h.
atomic_uint_least64_t packets_written
AVStream ** streams
A list of all streams in the file.
static void deinit(AVFormatContext *s)
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, const 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.
static int copy_moof(AVFormatContext *s, const char *infile, const char *outfile, int64_t size)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static void get_private_data(OutputStream *os)
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
const char * stream_type_tag
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int ff_rename(const char *url_src, const char *url_dst, void *logctx)
Wrap ffurl_move() and log if error happens.
unsigned int avio_rb32(AVIOContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it.
static int ism_flush(AVFormatContext *s, int final)
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
static int ism_write_trailer(AVFormatContext *s)
#define AVIO_FLAG_WRITE
write-only
#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.
static int64_t ism_seek(void *opaque, int64_t offset, int whence)
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.
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
static int write_trailer(AVFormatContext *s1)
char * protocol_whitelist
',' separated list of allowed protocols.
const char * av_default_item_name(void *ptr)
Return the context name.
uint64_t avio_rb64(AVIOContext *s)
AVIOContext * pb
I/O context.
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static void ism_free(AVFormatContext *s)
int extradata_size
Size of the extradata content in bytes.
unsigned int avio_rl32(AVIOContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
static int64_t start_time
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
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
int flags
A combination of AV_PKT_FLAG values.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
static int write_manifest(AVFormatContext *s, int final)
static int av_uuid_equal(const AVUUID uu1, const AVUUID uu2)
Compares two UUIDs for equality.
#define i(width, name, range_min, range_max)
#define AVERROR_MUXER_NOT_FOUND
Muxer not found.
#define AV_TIME_BASE
Internal time base represented as integer.
int block_align
Audio only.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_calloc(size_t nmemb, size_t size)
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
static int ism_write_packet(AVFormatContext *s, AVPacket *pkt)
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
const struct AVOutputFormat * oformat
The output container format.
static const AVClass ism_class
static const AVOption options[]
static int parse_fragment(AVFormatContext *s, const char *filename, int64_t *start_ts, int64_t *duration, int64_t *moof_size, int64_t size)
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
int ff_avc_write_annexb_extradata(const uint8_t *in, uint8_t **buf, int *size)
static int ism_write(void *opaque, const uint8_t *buf, int buf_size)
@ AV_OPT_TYPE_INT
Underlying C type is int.
static int ism_write_header(AVFormatContext *s)
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static void output_chunk_list(OutputStream *os, AVIOContext *out, int final, int skip, int window_size)
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
#define AVIO_FLAG_READ
read-only
const 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...
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
#define MKTAG(a, b, c, d)
static void write_header(FFV1Context *f)
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
const FFOutputFormat ff_smoothstreaming_muxer
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
static int add_fragment(OutputStream *os, const char *file, const char *infofile, int64_t start_time, int64_t duration, int64_t start_pos, int64_t size)