84 if (memcmp(buf,
"FLV", 3))
88 while (buf_size >= 11 + 4) {
101 }
else if (
type == 0x12) {
117static int hds_write(
void *opaque,
const uint8_t *buf,
int buf_size)
140 for (
i = 0;
i <
s->nb_streams;
i++) {
163 char filename[1024], temp_filename[1024];
167 if (
c->nb_streams > 0)
170 snprintf(filename,
sizeof(filename),
"%s/index.f4m",
s->url);
171 snprintf(temp_filename,
sizeof(temp_filename),
"%s/index.f4m.tmp",
s->url);
178 avio_printf(
out,
"<manifest xmlns=\"http://ns.adobe.com/f4m/1.0\">\n");
181 final ?
"recorded" :
"live");
185 for (
i = 0;
i <
c->nb_streams;
i++) {
195 avio_printf(
out,
"\t<bootstrapInfo profile=\"named\" url=\"stream%d.abst\" id=\"bootstrap%d\" />\n",
i,
i);
196 avio_printf(
out,
"\t<media bitrate=\"%d\" url=\"stream%d\" bootstrapInfoId=\"bootstrap%d\">\n", os->
bitrate/1000,
i,
i);
222 char filename[1024], temp_filename[1024];
225 int start = 0, fragments;
236 snprintf(filename,
sizeof(filename),
237 "%s/stream%d.abst",
s->url,
index);
238 snprintf(temp_filename,
sizeof(temp_filename),
239 "%s/stream%d.abst.tmp",
s->url,
index);
317 if (mkdir(
s->url, 0777) == -1 && errno != EEXIST) {
323 c->streams =
av_calloc(
s->nb_streams,
sizeof(*
c->streams));
328 for (
i = 0;
i <
s->nb_streams;
i++) {
353 os->
bitrate +=
s->streams[
i]->codecpar->bit_rate;
364 ctx->interrupt_callback =
s->interrupt_callback;
365 ctx->flags =
s->flags;
376 s->streams[
i]->id =
c->nb_streams;
386 if (
c->streams[
c->nb_streams].ctx)
389 for (
i = 0;
i <
c->nb_streams;
i++) {
401 "%s/stream%d_temp",
s->url,
i);
406 if (!os->
has_video &&
c->min_frag_duration <= 0) {
408 "No video stream in output stream %d and no min frag duration set\n",
i);
451 char target_filename[1024];
461 snprintf(target_filename,
sizeof(target_filename),
474 if (
c->window_size || (
final &&
c->remove_at_exit)) {
475 int remove = os->
nb_fragments -
c->window_size -
c->extra_window_size;
476 if (
final &&
c->remove_at_exit)
479 for (
i = 0;
i < remove;
i++) {
530 for (
i = 0;
i <
c->nb_streams;
i++)
534 if (
c->remove_at_exit) {
536 snprintf(filename,
sizeof(filename),
"%s/index.f4m",
s->url);
538 for (
i = 0;
i <
c->nb_streams;
i++) {
539 snprintf(filename,
sizeof(filename),
"%s/stream%d.abst",
s->url,
i);
548#define OFFSET(x) offsetof(HDSContext, x)
549#define E AV_OPT_FLAG_ENCODING_PARAM
551 {
"window_size",
"number of fragments kept in the manifest",
OFFSET(window_size),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
E },
552 {
"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 },
553 {
"min_frag_duration",
"minimum fragment duration (in microseconds)",
OFFSET(min_frag_duration),
AV_OPT_TYPE_INT64, { .i64 = 10000000 }, 0, INT_MAX,
E },
554 {
"remove_at_exit",
"remove all fragments when finished",
OFFSET(remove_at_exit),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
559 .class_name =
"HDS muxer",
int ff_rename(const char *url_src, const char *url_dst, void *logctx)
Wrap ffurl_move() and log if error happens.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
void avio_wl32(AVIOContext *s, unsigned int val)
void avio_w8(AVIOContext *s, int b)
void avio_wb32(AVIOContext *s, unsigned int val)
#define AVIO_FLAG_WRITE
write-only
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
void avio_wb64(AVIOContext *s, uint64_t val)
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.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_context_free(AVIOContext **s)
Free the supplied IO context and everything associated with it.
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
#define i(width, name, range_min, range_max)
static void deinit(AVFormatContext *s)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
static int64_t start_time
static void write_header(FFV1Context *f)
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
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_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
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.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
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 char * av_basename(const char *path)
Thread safe basename.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define LIBAVUTIL_VERSION_INT
static void close_file(AVFormatContext *s, OutputStream *os)
static int hds_write_header(AVFormatContext *s)
static int hds_flush(AVFormatContext *s, OutputStream *os, int final, int64_t end_ts)
static void update_size(AVIOContext *out, int64_t pos)
static int add_fragment(OutputStream *os, const char *file, int64_t start_time, int64_t duration)
static const AVClass hds_class
static int parse_header(OutputStream *os, const uint8_t *buf, int buf_size)
static void hds_free(AVFormatContext *s)
static int hds_write_packet(AVFormatContext *s, AVPacket *pkt)
static int write_abst(AVFormatContext *s, OutputStream *os, int final)
static int hds_write(void *opaque, const uint8_t *buf, int buf_size)
static int hds_write_trailer(AVFormatContext *s)
static int write_manifest(AVFormatContext *s, int final)
static int init_file(AVFormatContext *s, OutputStream *os, int64_t start_ts)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define MKTAG(a, b, c, d)
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
miscellaneous OS support macros and functions.
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
enum AVMediaType codec_type
General type of the encoded data.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVIOContext * pb
I/O context.
AVStream ** streams
A list of all streams in the file.
This structure stores compressed data.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int64_t first_dts
Timestamp corresponding to the last dts sync point.
int extra_packet_sizes[2]
atomic_uint_least64_t packets_written
uint8_t * extra_packets[2]
static AVFormatContext * ctx
static int write_trailer(AVFormatContext *s1)