33 #include <openssl/rand.h> 48 #if CONFIG_HTTP_PROTOCOL 67 #define LINE_BUFFER_SIZE 1024 68 #define HLS_MICROSECOND_UNIT 1000000 69 #define POSTFIX_PATTERN "_%d" 146 char current_segment_final_filename_fmt[1024];
153 char codec_attr[128];
239 if (!path || !temp) {
243 if (!strncmp(temp,
"/", 1) || !strncmp(temp,
"\\", 1)) {
245 }
else if (!strncmp(temp,
"./", 2) || !strncmp(temp,
".\\", 2)) {
249 for ( ; *pos !=
'\0'; ++
pos) {
250 if (*pos ==
'/' || *pos ==
'\\') {
253 ret = mkdir(temp, 0755);
258 if ((*(pos - 1) !=
'/') || (*(pos - 1) !=
'\\')) {
259 ret = mkdir(temp, 0755);
273 #if CONFIG_HTTP_PROTOCOL 288 #if CONFIG_HTTP_PROTOCOL 304 }
else if (http_base_proto) {
327 if (data && (data[0] | data[1] | data[2]) == 0 && data[3] == 1 && (data[4] & 0x1F) == 7) {
329 "avc1.%02x%02x%02x", data[5], data[6], data[7]);
334 snprintf(attr,
sizeof(attr),
"mp4a.40.33");
336 snprintf(attr,
sizeof(attr),
"mp4a.40.34");
339 snprintf(attr,
sizeof(attr),
"mp4a.40.2");
341 snprintf(attr,
sizeof(attr),
"ac-3");
343 snprintf(attr,
sizeof(attr),
"ec-3");
351 "%s%s", codec_strlen ?
"," :
"", attr);
366 int nd, addchar_count;
377 if (c ==
'%' && *(p+1) ==
'%')
379 else if (c ==
'%' && (
av_isdigit(*(p+1)) || *(p+1) == placeholder)) {
383 nd = nd * 10 + *(p + addchar_count) -
'0';
387 if (*(p + addchar_count) == placeholder) {
388 av_bprintf(&buf,
"%0*"PRId64, (number < 0) ? nd : nd++, number);
389 p += (addchar_count + 1);
447 float playlist_duration = 0.0f;
448 int ret = 0, path_size, sub_path_size;
450 char *dirname =
NULL, *p, *sub_path;
454 const char *proto =
NULL;
458 playlist_duration += segment->
duration;
459 segment = segment->
next;
465 playlist_duration -= segment->
duration;
466 previous_segment = segment;
467 segment = previous_segment->
next;
469 if (playlist_duration <= -previous_segment->
duration) {
495 char * r_dirname = dirname;
530 }
else if (unlink(path) < 0) {
532 path, strerror(errno));
536 sub_path_size = strlen(segment->
sub_filename) + 1 + (dirname ? strlen(dirname) : 0);
553 }
else if (unlink(sub_path) < 0) {
555 sub_path, strerror(errno));
560 previous_segment = segment;
561 segment = previous_segment->
next;
575 gcry_randomize(buf, len, GCRY_VERY_STRONG_RANDOM);
578 if (RAND_bytes(buf, len))
594 len = strlen(s->
url) + 4 + 1;
617 memcpy(iv, hls->
iv,
sizeof(iv));
636 if ((ret =
randomize(key,
sizeof(key))) < 0) {
641 memcpy(key, hls->
key,
sizeof(key));
696 if (ret !=
sizeof(key)) {
773 av_log(s,
AV_LOG_WARNING,
"Multi-file byterange mode is currently unsupported in the HLS muxer.\n");
784 if (byterange_mode) {
806 av_dict_set(&options,
"movflags",
"frag_custom+dash+delay_moov", 0);
826 segment = segment->
next;
847 "Invalid second level segment filename template '%s', " 848 "you can try to remove second_level_segment_size flag\n",
861 "Invalid second level segment filename template '%s', " 862 "you can try to remove second_level_segment_time flag\n",
880 "second_level_segment_duration hls_flag requires use_localtime to be true\n");
885 "second_level_segment_size hls_flag requires use_localtime to be true\n");
890 "second_level_segment_index hls_flag requires use_localtime to be true\n");
900 int segment_renaming_ok = proto && !strcmp(proto,
"file");
905 "second_level_segment_duration hls_flag works only with file protocol segment names\n");
910 "second_level_segment_size hls_flag works only with file protocol segment names\n");
935 "you can try to remove second_level_segment_index flag\n",
946 char *filename =
NULL;
949 "you can try to remove second_level_segment_size flag\n",
957 char *filename =
NULL;
960 "you can try to remove second_level_segment_time flag\n",
996 && !byterange_mode) {
1064 int ret = 0, is_segment = 0;
1065 int64_t new_start_pos;
1076 if (strcmp(line,
"#EXTM3U")) {
1084 if (
av_strstart(line,
"#EXT-X-MEDIA-SEQUENCE:", &ptr)) {
1085 int64_t tmp_sequence = strtoll(ptr,
NULL, 10);
1086 if (tmp_sequence < vs->sequence)
1088 "Found playlist sequence number was smaller """ 1089 "than specified start sequence number: %"PRId64
" < %"PRId64
", " 1092 av_log(hls,
AV_LOG_DEBUG,
"Found playlist sequence number: %"PRId64
"\n", tmp_sequence);
1095 }
else if (
av_strstart(line,
"#EXT-X-DISCONTINUITY", &ptr)) {
1104 ptr += strlen(
"URI=\"");
1115 ptr += strlen(
"IV=0x");
1126 }
else if (line[0]) {
1163 size_t len = strlen(oc->
url);
1167 if (!final_filename)
1169 final_filename[len-4] =
'\0';
1171 oc->
url[len-4] =
'\0';
1177 char *rel_url,
int rel_url_buf_size)
1181 p = strrchr(master_url,
'/') ? strrchr(master_url,
'/') :\
1182 strrchr(master_url,
'\\');
1184 base_len =
FFABS(p - master_url);
1190 av_strlcpy(rel_url, &(media_url[base_len + 1]), rel_url_buf_size);
1217 int m3u8_name_size, ret, bandwidth;
1218 char *m3u8_rel_name, *ccgroup;
1263 m3u8_name_size = strlen(vs->
m3u8_name) + 1;
1264 m3u8_rel_name =
av_malloc(m3u8_name_size);
1265 if (!m3u8_rel_name) {
1271 m3u8_rel_name, m3u8_name_size);
1286 m3u8_name_size = strlen(vs->
m3u8_name) + 1;
1287 m3u8_rel_name =
av_malloc(m3u8_name_size);
1288 if (!m3u8_rel_name) {
1294 m3u8_rel_name, m3u8_name_size);
1309 if (!vid_st && !aud_st) {
1338 bandwidth += bandwidth / 10;
1372 int target_duration = 0;
1374 char temp_filename[1024];
1377 int use_rename = proto && !strcmp(proto,
"file");
1378 static unsigned warned_non_file;
1387 if (byterange_mode) {
1400 if (!use_rename && !warned_non_file++)
1401 av_log(s,
AV_LOG_ERROR,
"Cannot use rename on non file protocol, this may lead to races and temporary partial files\n");
1404 snprintf(temp_filename,
sizeof(temp_filename), use_rename ?
"%s.tmp" :
"%s", vs->
m3u8_name);
1409 if (target_duration <= en->duration)
1415 target_duration, sequence, hls->
pl_type);
1475 if (ret >= 0 && use_rename)
1506 char *filename =
NULL;
1514 av_log(oc,
AV_LOG_ERROR,
"Invalid segment filename template '%s', you can try to use -use_localtime 1 with it\n", vs->
basename);
1521 struct tm *tm, tmpbuf;
1522 int bufsize = strlen(vs->
basename) + 1024;
1529 if (!strftime(oc->
url, bufsize, vs->
basename, tm)) {
1546 if (
mkdir_p(dir) == -1 && errno != EEXIST) {
1547 av_log(oc,
AV_LOG_ERROR,
"Could not create directory %s with use_localtime_mkdir\n", dir);
1554 char *filename =
NULL;
1562 av_log(oc,
AV_LOG_ERROR,
"Invalid segment filename template '%s' you can try to use -use_localtime 1 with it\n", vs->
basename);
1568 char *filename =
NULL;
1601 " ignoring -hls_enc\n");
1620 if ((err =
av_dict_set(&options,
"encryption_iv", iv_string, 0)) < 0)
1649 snprintf(period,
sizeof(period),
"%d", (INT_MAX / 2) - 1);
1673 time_t t = time(
NULL);
1674 struct tm *p, tmbuf;
1681 return (
HAVE_LIBC_MSVCRT || !strftime(b,
sizeof(b),
"%s", p) || !strcmp(b,
"%s")) ?
"-%Y%m%d%H%M%S.m4s" :
"-%s.m4s";
1683 return (
HAVE_LIBC_MSVCRT || !strftime(b,
sizeof(b),
"%s", p) || !strcmp(b,
"%s")) ?
"-%Y%m%d%H%M%S.ts" :
"-%s.ts";
1689 char extension[10] = {
'\0'};
1691 p = strrchr(name,
'.');
1699 if (strlen(extension))
1707 const char *
filename, *subdir_name;
1708 char *fn_dup =
NULL;
1726 av_log(
NULL,
AV_LOG_ERROR,
"More than 1 variant streams are present, %%v is expected in the filename %s\n",
1733 av_log(
NULL,
AV_LOG_ERROR,
"%%v is expected either in filename or in the sub-directory name of file %s\n",
1746 const char *proto, *dir;
1747 char *orig_buf_dup =
NULL, *mod_buf =
NULL, *mod_buf_dup =
NULL;
1754 if (!orig_buf_dup) {
1769 if (
av_stristr(dir,
"%v") && proto && !strcmp(proto,
"file")) {
1777 if (
mkdir_p(dir) == -1 && errno != EEXIST) {
1794 unsigned int stream_index, cnt;
1795 if (stream_id < 0 || stream_id > s->
nb_streams - 1)
1798 for (stream_index = 0; stream_index < s->
nb_streams; stream_index++) {
1801 if (cnt == stream_id)
1802 return stream_index;
1815 char *p, *q, *saveptr1, *saveptr2, *varstr, *keyval;
1846 while (varstr =
av_strtok(p,
" \t", &saveptr1)) {
1849 if (nb_varstreams < hls->nb_varstreams) {
1857 while (q < varstr + strlen(varstr)) {
1868 while (keyval =
av_strtok(varstr,
",", &saveptr2)) {
1876 }
else if (
av_strstart(keyval,
"ccgroup:", &val)) {
1897 if (stream_index >= 0 && nb_streams < vs->nb_streams) {
1915 char *p, *q, *ccstr, *keyval;
1916 char *saveptr1 =
NULL, *saveptr2 =
NULL;
1934 while (ccstr =
av_strtok(p,
" \t", &saveptr1)) {
1937 if (nb_ccstreams < hls->nb_ccstreams)
1942 while (keyval =
av_strtok(ccstr,
",", &saveptr2)) {
1949 }
else if (
av_strstart(keyval,
"instreamid:", &val)) {
1953 }
else if (
av_strstart(keyval,
"language:", &val)) {
1969 if(atoi(val) < 1 || atoi(val) > 4) {
1975 if(atoi(val) < 1 || atoi(val) > 63) {
2058 if (dir && strcmp(dir,
"."))
2103 "(%"PRId64
" > %"PRId64
"), the result maybe not be what you want.",
2143 int64_t end_pts = 0;
2145 int ret = 0, can_split = 1, i, j;
2146 int stream_index = 0;
2147 int range_length = 0;
2182 end_pts = init_list_dur + after_init_list_dur ;
2195 is_ref_pkt = can_split = 0;
2209 av_log(s,
AV_LOG_WARNING,
"pkt->duration = 0, maybe the hls segment duration will not precise\n");
2218 int64_t new_start_pos;
2219 char *old_filename =
NULL;
2228 vs->
size = new_start_pos;
2240 if (!byterange_mode) {
2246 if (!byterange_mode) {
2250 if (!byterange_mode) {
2273 vs->
size = range_length;
2291 if (!old_filename) {
2352 char *old_filename =
NULL;
2364 if (!old_filename) {
2368 int range_length = 0;
2400 if (!old_filename) {
2464 const char *pattern =
"%d.ts";
2466 int basename_size = 0;
2468 const char *vtt_pattern =
"%d.vtt";
2470 int vtt_basename_size = 0;
2482 av_log(s,
AV_LOG_ERROR,
"Periodic re-key not supported when more than one variant streams are present\n");
2522 time_t t = time(
NULL);
2527 struct tm *p, tmbuf;
2530 if (!strftime(b,
sizeof(b),
"%Y%m%d%H%M%S", p))
2559 "'split_by_time' and 'independent_segments' cannot be enabled together. " 2560 "Disabling 'independent_segments' flag\n");
2587 av_log(s,
AV_LOG_WARNING,
"More than a single video stream present, expect issues decoding it.\n");
2628 basename_size = strlen(vs->
m3u8_name) + strlen(pattern_localtime_fmt) + 1;
2630 basename_size = strlen(vs->
m3u8_name) + strlen(pattern) + 1;
2667 fmp4_init_filename_len);
2674 fmp4_init_filename_len = strlen(vs->
m3u8_name) +
2684 fmp4_init_filename_len);
2689 fmp4_init_filename_len);
2692 fmp4_init_filename_len);
2711 vtt_pattern =
".vtt";
2712 vtt_basename_size = strlen(vs->
m3u8_name) + strlen(vtt_pattern) + 1;
2757 " hls_init_time value will have no effect\n");
2800 #define OFFSET(x) offsetof(HLSContext, x) 2801 #define E AV_OPT_FLAG_ENCODING_PARAM 2805 {
"hls_init_time",
"set segment length in seconds at init list",
OFFSET(init_time),
AV_OPT_TYPE_FLOAT, {.dbl = 0}, 0, FLT_MAX, E},
2806 {
"hls_list_size",
"set maximum number of playlist entries",
OFFSET(max_nb_segments),
AV_OPT_TYPE_INT, {.i64 = 5}, 0, INT_MAX, E},
2807 {
"hls_delete_threshold",
"set number of unreferenced segments to keep before deleting",
OFFSET(hls_delete_threshold),
AV_OPT_TYPE_INT, {.i64 = 1}, 1, INT_MAX, E},
2808 {
"hls_ts_options",
"set hls mpegts list of options for the container format used for hls",
OFFSET(format_options_str),
AV_OPT_TYPE_STRING, {.str =
NULL}, 0, 0, E},
2809 {
"hls_vtt_options",
"set hls vtt list of options for the container format used for hls",
OFFSET(vtt_format_options_str),
AV_OPT_TYPE_STRING, {.str =
NULL}, 0, 0, E},
2811 {
"hls_wrap",
"set number after which the index wraps (will be deprecated)",
OFFSET(
wrap),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E},
2813 {
"hls_allow_cache",
"explicitly set whether the client MAY (1) or MUST NOT (0) cache media segments",
OFFSET(allowcache),
AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, E},
2816 {
"hls_segment_size",
"maximum size per segment file, (in bytes)",
OFFSET(max_seg_size),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E},
2826 {
"hls_fmp4_init_filename",
"set fragment mp4 file init filename",
OFFSET(fmp4_init_filename),
AV_OPT_TYPE_STRING, {.str =
"init.mp4"}, 0, 0, E},
2827 {
"hls_flags",
"set flags affecting HLS playlist and media file generation",
OFFSET(
flags),
AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX,
E,
"flags"},
2841 {
"independent_segments",
"add EXT-X-INDEPENDENT-SEGMENTS, whenever applicable", 0,
AV_OPT_TYPE_CONST, { .i64 =
HLS_INDEPENDENT_SEGMENTS }, 0, UINT_MAX,
E,
"flags"},
2842 {
"use_localtime",
"set filename expansion with strftime at segment creation",
OFFSET(use_localtime),
AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
2843 {
"use_localtime_mkdir",
"create last directory component in strftime-generated filename",
OFFSET(use_localtime_mkdir),
AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
2856 {
"master_pl_publish_rate",
"Publish master play list every after this many segment intervals",
OFFSET(master_publish_rate),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, UINT_MAX, E},
2857 {
"http_persistent",
"Use persistent HTTP connections",
OFFSET(http_persistent),
AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
2858 {
"timeout",
"set timeout for socket I/O operations",
OFFSET(timeout),
AV_OPT_TYPE_DURATION, { .i64 = -1 }, -1, INT_MAX, .flags = E },
2873 .extensions =
"m3u8",
2883 .priv_class = &hls_class,
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.
const char const char void * val
char key_uri[LINE_BUFFER_SIZE+1]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
static av_const int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
static int hls_write_trailer(struct AVFormatContext *s)
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
char current_segment_final_filename_fmt[1024]
static int update_variant_stream_info(AVFormatContext *s)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
char * av_stristr(const char *s1, const char *s2)
Locate the first case-independent occurrence in the string haystack of the string needle...
static av_cold int init(AVCodecContext *avctx)
int max_bitrate
Maximum bitrate of the stream, in bits per second.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
char * vtt_format_options_str
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int use_localtime_mkdir
flag to mkdir dirname in timebased filename
int index
stream index in AVFormatContext
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
static int mkdir_p(const char *path)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
const char * av_default_item_name(void *ptr)
Return the context name.
#define AVIO_FLAG_READ
read-only
static int hls_start(AVFormatContext *s, VariantStream *vs)
#define AVIO_FLAG_WRITE
write-only
enum AVMediaType codec_type
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
static int replace_int_data_in_filename(char **s, const char *filename, char placeholder, int64_t number)
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
HLSSegment * old_segments
CodecAttributeStatus attr_status
int ff_hls_write_file_entry(AVIOContext *out, int insert_discont, int byterange_mode, double duration, int round_duration, int64_t size, int64_t pos, char *baseurl, char *filename, double *prog_date_time)
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
static int hls_window(AVFormatContext *s, int last, VariantStream *vs)
static void hlsenc_io_close(AVFormatContext *s, AVIOContext **pb, char *filename)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
int ffurl_shutdown(URLContext *h, int flags)
Signal the URLContext that we are done reading or writing the stream.
static int update_master_pl_info(AVFormatContext *s)
VariantStream * var_streams
static int do_encrypt(AVFormatContext *s, VariantStream *vs)
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.
int av_stristart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str independent of case.
AVOutputFormat * vtt_oformat
const char * av_basename(const char *path)
Thread safe basename.
enum AVCodecID av_codec_get_id(const struct AVCodecTag *const *tags, unsigned int tag)
Get the AVCodecID for the given codec tag tag.
miscellaneous OS support macros and functions.
char * fmp4_init_filename
static av_cold int end(AVCodecContext *avctx)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static void hls_free_segments(HLSSegment *p)
static int append_postfix(char *name, int name_buf_len, int i)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
uint8_t * av_stream_get_side_data(const AVStream *stream, enum AVPacketSideDataType type, int *size)
Get side information from stream.
AVStream ** streams
A list of all streams in the file.
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
char * protocol_whitelist
',' separated list of allowed protocols.
static int get_nth_codec_stream_index(AVFormatContext *s, enum AVMediaType codec_type, int stream_id)
#define AVERROR_EOF
End of file.
char * format_options_str
#define AV_LOG_VERBOSE
Detailed information.
void ff_hls_write_audio_rendition(AVIOContext *out, char *agroup, char *filename, int name_id, int is_default)
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)
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
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.
static const AVOption options[]
static int hls_write_header(AVFormatContext *s)
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.
AVDictionary * metadata
Metadata that applies to the whole file.
#define AV_BPRINT_SIZE_UNLIMITED
#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_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
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. ...
preferred ID for decoding MPEG audio layer 1, 2 or 3
enum AVMediaType codec_type
General type of the encoded data.
AVDictionary * vtt_format_options
static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls, VariantStream *vs)
simple assert() macros that are a bit more flexible than ISO C assert().
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, VariantStream *vs, double duration, int64_t pos, int64_t size)
static av_always_inline av_const double round(double x)
char key_uri[LINE_BUFFER_SIZE+1]
static int hls_rename_temp_file(AVFormatContext *s, AVFormatContext *oc)
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.
static void write_styp(AVIOContext *pb)
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.
static void set_http_options(AVFormatContext *s, AVDictionary **options, HLSContext *c)
char * av_asprintf(const char *fmt,...)
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
static int sls_flag_check_duration_size_index(HLSContext *hls)
void ff_hls_write_playlist_header(AVIOContext *out, int version, int allowcache, int target_duration, int64_t sequence, uint32_t playlist_type)
char key_string[KEYSIZE *2+1]
AVFormatContext * vtt_avf
#define HLS_MICROSECOND_UNIT
static int randomize(uint8_t *buf, int len)
int void avio_flush(AVIOContext *s)
Force flushing of buffered data.
HLSSegment * last_segment
#define AV_TIME_BASE
Internal time base represented as integer.
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_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
AVIOContext * sub_m3u8_out
static struct tm * localtime_r(const time_t *clock, struct tm *result)
static int write_trailer(AVFormatContext *s1)
static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
static int create_master_playlist(AVFormatContext *s, VariantStream *const input_vs)
static int hls_mux_init(AVFormatContext *s, VariantStream *vs)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
ClosedCaptionsStream * cc_streams
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
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...
AVDictionary * format_options
int ff_get_line(AVIOContext *s, char *buf, int maxlen)
Read a whole line of text from AVIOContext.
static void sls_flag_file_rename(HLSContext *hls, VariantStream *vs, char *old_filename)
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 reference_stream_index
char * base_output_dirname
int use_localtime
flag to expand filename with localtime
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
void ff_hls_write_playlist_version(AVIOContext *out, int version)
This structure describes the bitrate properties of an encoded bitstream.
char iv_string[KEYSIZE *2+1]
char * av_strdup(const char *s)
Duplicate a string.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
char * user_agent
holds HTTP user agent set as an AVOption to the HTTP protocol context
AVIOContext * pb
I/O context.
static int hls_encryption_start(AVFormatContext *s)
unsigned int nb_ccstreams
char * fmp4_init_filename
void(* io_close)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
static int64_t get_stream_bit_rate(AVStream *stream)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
static int validate_name(int nb_vs, const char *fn)
Describe the class of an AVClass context structure.
static int hlsenc_io_open(AVFormatContext *s, AVIOContext **pb, char *filename, AVDictionary **options)
char iv_string[KEYSIZE *2+1]
static int flush_dynbuf(VariantStream *vs, int *range_length)
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
static int hls_init(AVFormatContext *s)
int ffio_open_whitelist(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist)
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
URLContext * ffio_geturlcontext(AVIOContext *s)
Return the URLContext associated with the AVIOContext.
char key_file[LINE_BUFFER_SIZE+1]
static HLSSegment * find_segment_by_filename(HLSSegment *segment, const char *filename)
static const char * get_default_pattern_localtime_fmt(AVFormatContext *s)
void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, char *filename, char *agroup, char *codecs, char *ccgroup)
int ff_http_do_new_request(URLContext *h, const char *uri)
Send a new HTTP request, reusing the old connection.
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 write_codec_attr(AVStream *st, VariantStream *vs)
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs)
char * av_append_path_component(const char *path, const char *component)
Append path component to the existing path.
unsigned int nb_varstreams
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...
const char * av_dirname(char *path)
Thread safe dirname.
void ff_hls_write_init_file(AVIOContext *out, char *filename, int byterange_mode, int64_t size, int64_t pos)
int pts_wrap_bits
number of bits in pts (used for wrapping control)
static int sls_flag_check_duration_size(HLSContext *hls, VariantStream *vs)
uint32_t start_sequence_source_type
void * priv_data
Format private data.
This side data corresponds to the AVCPBProperties struct.
static const uint8_t start_sequence[]
static int get_relative_url(const char *master_url, const char *media_url, char *rel_url, int rel_url_buf_size)
static void write_header(FFV1Context *f)
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
static int sls_flags_filename_process(struct AVFormatContext *s, HLSContext *hls, VariantStream *vs, HLSSegment *en, double duration, int64_t pos, int64_t size)
AVOutputFormat ff_hls_muxer
void ff_hls_write_end_list(AVIOContext *out)
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)
char * protocol_blacklist
',' separated list of disallowed protocols.
unsigned int master_publish_rate
static int format_name(char *buf, int buf_len, int index)
#define AVERROR_MUXER_NOT_FOUND
Muxer not found.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
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...
static const AVClass hls_class
unsigned int av_codec_get_tag(const struct AVCodecTag *const *tags, enum AVCodecID id)
Get the codec tag for the given codec id id.
double initial_prog_date_time
int ff_get_chomp_line(AVIOContext *s, char *buf, int maxlen)
Same as ff_get_line but strip the white-space characters in the text tail.
This structure stores compressed data.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
static int parse_variant_stream_mapstring(AVFormatContext *s)
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
static int sls_flag_use_localtime_filename(AVFormatContext *oc, HLSContext *c, VariantStream *vs)
static int parse_cc_stream_mapstring(AVFormatContext *s)