83 if (memcmp(buf,
"FLV", 3))
87 while (buf_size >= 11 + 4) {
92 if (type == 8 || type == 9) {
101 }
else if (type == 0x12) {
165 char filename[1024], temp_filename[1024];
173 snprintf(temp_filename,
sizeof(temp_filename),
"%s/index.f4m.tmp", s->
filename);
179 avio_printf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
180 avio_printf(out,
"<manifest xmlns=\"http://ns.adobe.com/f4m/1.0\">\n");
182 avio_printf(out,
"\t<streamType>%s</streamType>\n",
183 final ?
"recorded" :
"live");
184 avio_printf(out,
"\t<deliveryType>streaming</deliveryType>\n");
186 avio_printf(out,
"\t<duration>%f</duration>\n", duration);
197 avio_printf(out,
"\t<bootstrapInfo profile=\"named\" url=\"stream%d.abst\" id=\"bootstrap%d\" />\n", i, i);
198 avio_printf(out,
"\t<media bitrate=\"%d\" url=\"stream%d\" bootstrapInfoId=\"bootstrap%d\">\n", os->
bitrate/1000, i, i);
199 avio_printf(out,
"\t\t<metadata>%s</metadata>\n", base64);
206 return ff_rename(temp_filename, filename, s);
224 char filename[1024], temp_filename[1024];
226 int64_t asrt_pos, afrt_pos;
227 int start = 0, fragments;
229 int64_t cur_media_time = 0;
238 snprintf(filename,
sizeof(filename),
239 "%s/stream%d.abst", s->
filename, index);
240 snprintf(temp_filename,
sizeof(temp_filename),
241 "%s/stream%d.abst.tmp", s->
filename, index);
251 avio_w8(out,
final ? 0 : 0x20);
286 return ff_rename(temp_filename, filename, s);
320 if (mkdir(s->
filename, 0777) == -1 && errno != EEXIST) {
415 "%s/stream%d_temp", s->
filename, i);
422 "No video stream in output stream %d and no min frag duration set\n", i);
469 char target_filename[1024];
479 snprintf(target_filename,
sizeof(target_filename),
497 for (i = 0; i <
remove; i++) {
566 #define OFFSET(x) offsetof(HDSContext, x)
567 #define E AV_OPT_FLAG_ENCODING_PARAM
569 {
"window_size",
"number of fragments kept in the manifest",
OFFSET(window_size),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
E },
570 {
"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 },
571 {
"min_frag_duration",
"minimum fragment duration (in microseconds)",
OFFSET(min_frag_duration),
AV_OPT_TYPE_INT64, { .i64 = 10000000 }, 0, INT_MAX,
E },
572 {
"remove_at_exit",
"remove all fragments when finished",
OFFSET(remove_at_exit),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
593 .priv_class = &hds_class,
void avio_wb64(AVIOContext *s, uint64_t val)
int64_t first_dts
Timestamp corresponding to the last dts sync point.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void hds_free(AVFormatContext *s)
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
static int hds_write_header(AVFormatContext *s)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AVIO_FLAG_WRITE
write-only
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
uint8_t * extra_packets[2]
AVOutputFormat ff_hds_muxer
static int write_manifest(AVFormatContext *s, int final)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int64_t start_time
const char * av_basename(const char *path)
Thread safe basename.
void avio_wl32(AVIOContext *s, unsigned int val)
miscellaneous OS support macros and functions.
static av_cold int end(AVCodecContext *avctx)
int id
Format-specific stream ID.
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.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
int extra_packet_sizes[2]
int flags
Flags modifying the (de)muxer behaviour.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static const AVClass hds_class
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
struct AVOutputFormat * oformat
The output container format.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
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.
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int hds_write_packet(AVFormatContext *s, AVPacket *pkt)
enum AVMediaType codec_type
General type of the encoded data.
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
static void * av_mallocz_array(size_t nmemb, size_t size)
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.
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 two timestamps each in its own time base.
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
static int hds_write_trailer(AVFormatContext *s)
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int void avio_flush(AVIOContext *s)
Force flushing of buffered data.
char filename[1024]
input or output filename
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
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)
static void update_size(AVIOContext *out, int64_t pos)
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...
static int init_file(AVFormatContext *s, OutputStream *os, int64_t start_ts)
static int hds_flush(AVFormatContext *s, OutputStream *os, int final, int64_t end_ts)
#define FF_ARRAY_ELEMS(a)
static int write_abst(AVFormatContext *s, OutputStream *os, int final)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
AVIOContext * pb
I/O context.
void avio_w8(AVIOContext *s, int b)
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
Describe the class of an AVClass context structure.
static int hds_write(void *opaque, uint8_t *buf, int buf_size)
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
static int add_fragment(OutputStream *os, const char *file, int64_t start_time, int64_t duration)
static int parse_header(OutputStream *os, const uint8_t *buf, int buf_size)
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.
void avio_wb32(AVIOContext *s, unsigned int val)
static void close_file(AVFormatContext *s, OutputStream *os)
#define AVERROR_MUXER_NOT_FOUND
Muxer not found.
AVCodecParameters * codecpar
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
static const AVOption options[]
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define MKTAG(a, b, c, d)
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
This structure stores compressed data.
#define AV_NOPTS_VALUE
Undefined timestamp value.
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2