93 static int64_t
ism_seek(
void *opaque, int64_t offset,
int whence)
97 if (whence != SEEK_SET)
118 if (offset >= frag->
start_pos && offset < frag->start_pos + frag->
size) {
157 for (i = 0; i <
size; i++)
158 snprintf(&os->
private_str[2*i], 3,
"%02x", ptr[i]);
191 int removed = 0, i, start = 0;
202 if (!
final || removed)
214 int ret, i, video_chunks = 0, audio_chunks = 0, video_streams = 0, audio_streams = 0;
217 snprintf(filename,
sizeof(filename),
"%s/Manifest", s->
filename);
223 avio_printf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
240 video_chunks = audio_chunks = 0;
246 avio_printf(out,
"<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" Duration=\"%"PRIu64
"\"", duration);
251 int last = -1,
index = 0;
252 avio_printf(out,
"<StreamIndex Type=\"video\" QualityLevels=\"%d\" Chunks=\"%d\" Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n", video_streams, video_chunks);
265 int last = -1,
index = 0;
266 avio_printf(out,
"<StreamIndex Type=\"audio\" QualityLevels=\"%d\" Chunks=\"%d\" Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n", audio_streams, audio_chunks);
403 if (*moof_size < 8 || *moof_size > size)
408 if (len > *moof_size)
420 if (len < 8 || len >= *moof_size)
422 if (tag ==
MKTAG(
'u',
'u',
'i',
'd')) {
424 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
425 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
429 if (!memcmp(uuid, tfxd, 16) && len >= 8 + 16 + 4 + 16) {
480 int n =
FFMIN(size,
sizeof(buf));
502 char filename[1024], target_filename[1024], header_filename[1024];
504 int64_t start_ts,
duration, moof_size;
508 snprintf(filename,
sizeof(filename),
"%s/temp", os->
dirname);
524 snprintf(header_filename,
sizeof(header_filename),
"%s/FragmentInfo(%s=%"PRIu64
")", os->
dirname, os->
stream_type_tag, start_ts);
525 snprintf(target_filename,
sizeof(target_filename),
"%s/Fragments(%s=%"PRIu64
")", os->
dirname, os->
stream_type_tag, start_ts);
526 copy_moof(s, filename, header_filename, moof_size);
527 rename(filename, target_filename);
528 add_fragment(os, target_filename, header_filename, start_ts, duration, start_pos,
size);
539 for (j = 0; j <
remove; j++) {
589 snprintf(filename,
sizeof(filename),
"%s/Manifest", s->
filename);
598 #define OFFSET(x) offsetof(SmoothStreamingContext, x)
599 #define E AV_OPT_FLAG_ENCODING_PARAM
601 {
"window_size",
"number of fragments kept in the manifest",
OFFSET(window_size),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
E },
602 {
"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 },
603 {
"lookahead_count",
"number of lookahead fragments",
OFFSET(lookahead_count),
AV_OPT_TYPE_INT, { .i64 = 2 }, 0, INT_MAX,
E },
604 {
"min_frag_duration",
"minimum fragment duration (in microseconds)",
OFFSET(min_frag_duration),
AV_OPT_TYPE_INT64, { .i64 = 5000000 }, 0, INT_MAX,
E },
605 {
"remove_at_exit",
"remove all fragments when finished",
OFFSET(remove_at_exit),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
E },
618 .
name =
"smoothstreaming",
static int write_manifest(AVFormatContext *s, int final)
static int ism_flush(AVFormatContext *s, int final)
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
static int ism_write(void *opaque, uint8_t *buf, int buf_size)
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_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
static int ism_write_header(AVFormatContext *s)
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
static void output_chunk_list(OutputStream *os, AVIOContext *out, int final, int skip, int window_size)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
static int ism_write_packet(AVFormatContext *s, AVPacket *pkt)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
static void ism_free(AVFormatContext *s)
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
Copy the settings of the source AVCodecContext into the destination AVCodecContext.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
miscellaneous OS support macros and functions.
unsigned int avio_rb32(AVIOContext *s)
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)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
int ff_avc_write_annexb_extradata(const uint8_t *in, uint8_t **buf, int *size)
#define MKTAG(a, b, c, d)
uint64_t avio_rb64(AVIOContext *s)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
#define AVFMT_GLOBALHEADER
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
struct AVOutputFormat * oformat
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.
static int64_t start_time
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
unsigned int avio_rl32(AVIOContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
static const AVOption options[]
static const AVClass ism_class
static int parse_fragment(AVFormatContext *s, const char *filename, int64_t *start_ts, int64_t *duration, int64_t *moof_size, int64_t size)
void av_log(void *avcl, int level, const char *fmt,...)
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
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.
const AVCodecTag ff_mp4_obj_type[]
int flags
A combination of AV_PKT_FLAG values.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare 2 timestamps each in its own timebases.
AVCodecContext * codec
Codec context associated with this stream.
unsigned int nb_streams
A list of all streams in the file.
int bit_rate
the average bitrate
int void avio_flush(AVIOContext *s)
char filename[1024]
input or output filename
int width
picture width / height.
struct OutputStream OutputStream
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...
const char * stream_type_tag
enum AVMediaType codec_type
#define AVIO_FLAG_READ_WRITE
int sample_rate
samples per second
AVIOContext * pb
I/O context.
main external API structure.
static int64_t ism_seek(void *opaque, int64_t offset, int whence)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Describe the class of an AVClass context structure.
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.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
static int ism_write_trailer(AVFormatContext *s)
AVOutputFormat ff_smoothstreaming_muxer
int ffurl_close(URLContext *h)
Close the resource accessed by the URLContext h, and free the memory used by it.
#define AVERROR_MUXER_NOT_FOUND
static int copy_moof(AVFormatContext *s, const char *infile, const char *outfile, int64_t size)
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...
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
int ffurl_open(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
int channels
number of audio channels
void * priv_data
Format private data.
static void write_header(FFV1Context *f)
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.
unbuffered private I/O API
static void get_private_data(OutputStream *os)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)