FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
hlsenc.c File Reference
#include "config.h"
#include <float.h>
#include <stdint.h>
#include "libavutil/avassert.h"
#include "libavutil/mathematics.h"
#include "libavutil/parseutils.h"
#include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/random_seed.h"
#include "libavutil/opt.h"
#include "libavutil/log.h"
#include "libavutil/time_internal.h"
#include "avformat.h"
#include "avio_internal.h"
#include "hlsplaylist.h"
#include "internal.h"
#include "os_support.h"

Go to the source code of this file.

Data Structures

struct  HLSSegment
 
struct  VariantStream
 
struct  HLSContext
 

Macros

#define KEYSIZE   16
 
#define LINE_BUFFER_SIZE   1024
 
#define HLS_MICROSECOND_UNIT   1000000
 
#define POSTFIX_PATTERN   "_%d"
 
#define OFFSET(x)   offsetof(HLSContext, x)
 
#define E   AV_OPT_FLAG_ENCODING_PARAM
 

Enumerations

enum  StartSequenceSourceType { HLS_START_SEQUENCE_AS_START_NUMBER = 0, HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH = 1, HLS_START_SEQUENCE_AS_FORMATTED_DATETIME = 2 }
 
enum  HLSFlags {
  HLS_SINGLE_FILE = (1 << 0), HLS_DELETE_SEGMENTS = (1 << 1), HLS_ROUND_DURATIONS = (1 << 2), HLS_DISCONT_START = (1 << 3),
  HLS_OMIT_ENDLIST = (1 << 4), HLS_SPLIT_BY_TIME = (1 << 5), HLS_APPEND_LIST = (1 << 6), HLS_PROGRAM_DATE_TIME = (1 << 7),
  HLS_SECOND_LEVEL_SEGMENT_INDEX = (1 << 8), HLS_SECOND_LEVEL_SEGMENT_DURATION = (1 << 9), HLS_SECOND_LEVEL_SEGMENT_SIZE = (1 << 10), HLS_TEMP_FILE = (1 << 11),
  HLS_PERIODIC_REKEY = (1 << 12), HLS_INDEPENDENT_SEGMENTS = (1 << 13)
}
 
enum  SegmentType {
  PALETTE_SEGMENT = 0x14, OBJECT_SEGMENT = 0x15, PRESENTATION_SEGMENT = 0x16, WINDOW_SEGMENT = 0x17,
  DISPLAY_SEGMENT = 0x80, SEGMENT_TYPE_MPEGTS, SEGMENT_TYPE_FMP4
}
 

Functions

static int mkdir_p (const char *path)
 
static int is_http_proto (char *filename)
 
static int hlsenc_io_open (AVFormatContext *s, AVIOContext **pb, char *filename, AVDictionary **options)
 
static void hlsenc_io_close (AVFormatContext *s, AVIOContext **pb, char *filename)
 
static void set_http_options (AVFormatContext *s, AVDictionary **options, HLSContext *c)
 
static int replace_int_data_in_filename (char *buf, int buf_size, const char *filename, char placeholder, int64_t number)
 
static void write_styp (AVIOContext *pb)
 
static int hls_delete_old_segments (AVFormatContext *s, HLSContext *hls, VariantStream *vs)
 
static int randomize (uint8_t *buf, int len)
 
static int do_encrypt (AVFormatContext *s, VariantStream *vs)
 
static int hls_encryption_start (AVFormatContext *s)
 
static int read_chomp_line (AVIOContext *s, char *buf, int maxlen)
 
static int hls_mux_init (AVFormatContext *s, VariantStream *vs)
 
static HLSSegmentfind_segment_by_filename (HLSSegment *segment, const char *filename)
 
static int sls_flags_filename_process (struct AVFormatContext *s, HLSContext *hls, VariantStream *vs, HLSSegment *en, double duration, int64_t pos, int64_t size)
 
static int sls_flag_check_duration_size_index (HLSContext *hls)
 
static int sls_flag_check_duration_size (HLSContext *hls, VariantStream *vs)
 
static void sls_flag_file_rename (HLSContext *hls, VariantStream *vs, char *old_filename)
 
static int sls_flag_use_localtime_filename (AVFormatContext *oc, HLSContext *c, VariantStream *vs)
 
static int hls_append_segment (struct AVFormatContext *s, HLSContext *hls, VariantStream *vs, double duration, int64_t pos, int64_t size)
 
static int parse_playlist (AVFormatContext *s, const char *url, VariantStream *vs)
 
static void hls_free_segments (HLSSegment *p)
 
static void hls_rename_temp_file (AVFormatContext *s, AVFormatContext *oc)
 
static int get_relative_url (const char *master_url, const char *media_url, char *rel_url, int rel_url_buf_size)
 
static int create_master_playlist (AVFormatContext *s, VariantStream *const input_vs)
 
static int hls_window (AVFormatContext *s, int last, VariantStream *vs)
 
static int hls_start (AVFormatContext *s, VariantStream *vs)
 
static const char * get_default_pattern_localtime_fmt (AVFormatContext *s)
 
static int format_name (char *name, int name_buf_len, int i)
 
static int get_nth_codec_stream_index (AVFormatContext *s, enum AVMediaType codec_type, int stream_id)
 
static int parse_variant_stream_mapstring (AVFormatContext *s)
 
static int update_variant_stream_info (AVFormatContext *s)
 
static int update_master_pl_info (AVFormatContext *s)
 
static int hls_write_header (AVFormatContext *s)
 
static int hls_write_packet (AVFormatContext *s, AVPacket *pkt)
 
static int hls_write_trailer (struct AVFormatContext *s)
 
static int hls_init (AVFormatContext *s)
 

Variables

static const AVOption options []
 
static const AVClass hls_class
 
AVOutputFormat ff_hls_muxer
 

Macro Definition Documentation

#define KEYSIZE   16

Definition at line 61 of file hlsenc.c.

Referenced by do_encrypt(), hls_encryption_start(), and hls_start().

#define LINE_BUFFER_SIZE   1024

Definition at line 62 of file hlsenc.c.

#define HLS_MICROSECOND_UNIT   1000000

Definition at line 63 of file hlsenc.c.

Referenced by sls_flags_filename_process().

#define POSTFIX_PATTERN   "_%d"

Definition at line 64 of file hlsenc.c.

Referenced by format_name(), and hls_init().

#define OFFSET (   x)    offsetof(HLSContext, x)

Definition at line 2271 of file hlsenc.c.

Definition at line 2272 of file hlsenc.c.

Enumeration Type Documentation

Enumerator
HLS_START_SEQUENCE_AS_START_NUMBER 
HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH 
HLS_START_SEQUENCE_AS_FORMATTED_DATETIME 

Definition at line 55 of file hlsenc.c.

enum HLSFlags
Enumerator
HLS_SINGLE_FILE 
HLS_DELETE_SEGMENTS 
HLS_ROUND_DURATIONS 
HLS_DISCONT_START 
HLS_OMIT_ENDLIST 
HLS_SPLIT_BY_TIME 
HLS_APPEND_LIST 
HLS_PROGRAM_DATE_TIME 
HLS_SECOND_LEVEL_SEGMENT_INDEX 
HLS_SECOND_LEVEL_SEGMENT_DURATION 
HLS_SECOND_LEVEL_SEGMENT_SIZE 
HLS_TEMP_FILE 
HLS_PERIODIC_REKEY 
HLS_INDEPENDENT_SEGMENTS 

Definition at line 80 of file hlsenc.c.

Enumerator
PALETTE_SEGMENT 
OBJECT_SEGMENT 
PRESENTATION_SEGMENT 
WINDOW_SEGMENT 
DISPLAY_SEGMENT 
SEGMENT_TYPE_MPEGTS 
SEGMENT_TYPE_FMP4 

Definition at line 98 of file hlsenc.c.

Function Documentation

static int mkdir_p ( const char *  path)
static

Definition at line 210 of file hlsenc.c.

Referenced by hls_start().

static int is_http_proto ( char *  filename)
static

Definition at line 243 of file hlsenc.c.

Referenced by hlsenc_io_close(), hlsenc_io_open(), and set_http_options().

static int hlsenc_io_open ( AVFormatContext s,
AVIOContext **  pb,
char *  filename,
AVDictionary **  options 
)
static

Definition at line 248 of file hlsenc.c.

Referenced by create_master_playlist(), hls_start(), and hls_window().

static void hlsenc_io_close ( AVFormatContext s,
AVIOContext **  pb,
char *  filename 
)
static

Definition at line 265 of file hlsenc.c.

Referenced by create_master_playlist(), hls_window(), and hls_write_packet().

static void set_http_options ( AVFormatContext s,
AVDictionary **  options,
HLSContext c 
)
static

Definition at line 276 of file hlsenc.c.

Referenced by create_master_playlist(), hls_mux_init(), hls_start(), and hls_window().

static int replace_int_data_in_filename ( char *  buf,
int  buf_size,
const char *  filename,
char  placeholder,
int64_t  number 
)
static
static void write_styp ( AVIOContext pb)
static

Definition at line 345 of file hlsenc.c.

Referenced by hls_start().

static int hls_delete_old_segments ( AVFormatContext s,
HLSContext hls,
VariantStream vs 
)
static

Definition at line 355 of file hlsenc.c.

Referenced by hls_append_segment().

static int randomize ( uint8_t buf,
int  len 
)
static

Definition at line 463 of file hlsenc.c.

Referenced by do_encrypt().

static int do_encrypt ( AVFormatContext s,
VariantStream vs 
)
static

Definition at line 477 of file hlsenc.c.

Referenced by hls_start().

static int hls_encryption_start ( AVFormatContext s)
static

Definition at line 546 of file hlsenc.c.

Referenced by hls_start().

static int read_chomp_line ( AVIOContext s,
char *  buf,
int  maxlen 
)
static

Definition at line 598 of file hlsenc.c.

Referenced by parse_playlist().

static int hls_mux_init ( AVFormatContext s,
VariantStream vs 
)
static

Definition at line 606 of file hlsenc.c.

Referenced by hls_init().

static HLSSegment* find_segment_by_filename ( HLSSegment segment,
const char *  filename 
)
static

Definition at line 711 of file hlsenc.c.

Referenced by hls_append_segment().

static int sls_flags_filename_process ( struct AVFormatContext s,
HLSContext hls,
VariantStream vs,
HLSSegment en,
double  duration,
int64_t  pos,
int64_t  size 
)
static

Definition at line 721 of file hlsenc.c.

Referenced by hls_append_segment().

static int sls_flag_check_duration_size_index ( HLSContext hls)
static

Definition at line 768 of file hlsenc.c.

Referenced by hls_init().

static int sls_flag_check_duration_size ( HLSContext hls,
VariantStream vs 
)
static

Definition at line 791 of file hlsenc.c.

Referenced by hls_init().

static void sls_flag_file_rename ( HLSContext hls,
VariantStream vs,
char *  old_filename 
)
static

Definition at line 811 of file hlsenc.c.

Referenced by hls_write_packet(), and hls_write_trailer().

static int sls_flag_use_localtime_filename ( AVFormatContext oc,
HLSContext c,
VariantStream vs 
)
static

Definition at line 818 of file hlsenc.c.

Referenced by hls_start().

static int hls_append_segment ( struct AVFormatContext s,
HLSContext hls,
VariantStream vs,
double  duration,
int64_t  pos,
int64_t  size 
)
static

Definition at line 872 of file hlsenc.c.

Referenced by hls_write_packet(), hls_write_trailer(), and parse_playlist().

static int parse_playlist ( AVFormatContext s,
const char *  url,
VariantStream vs 
)
static

Definition at line 959 of file hlsenc.c.

Referenced by hls_init().

static void hls_free_segments ( HLSSegment p)
static

Definition at line 1044 of file hlsenc.c.

Referenced by hls_write_trailer().

static void hls_rename_temp_file ( AVFormatContext s,
AVFormatContext oc 
)
static

Definition at line 1055 of file hlsenc.c.

Referenced by hls_write_packet(), and hls_write_trailer().

static int get_relative_url ( const char *  master_url,
const char *  media_url,
char *  rel_url,
int  rel_url_buf_size 
)
static

Definition at line 1066 of file hlsenc.c.

Referenced by create_master_playlist().

static int create_master_playlist ( AVFormatContext s,
VariantStream *const  input_vs 
)
static

Definition at line 1084 of file hlsenc.c.

Referenced by hls_window().

static int hls_window ( AVFormatContext s,
int  last,
VariantStream vs 
)
static

Definition at line 1171 of file hlsenc.c.

Referenced by hls_write_packet(), and hls_write_trailer().

static int hls_start ( AVFormatContext s,
VariantStream vs 
)
static

Definition at line 1288 of file hlsenc.c.

Referenced by hls_init(), and hls_write_packet().

static const char* get_default_pattern_localtime_fmt ( AVFormatContext s)
static

Definition at line 1445 of file hlsenc.c.

Referenced by hls_init().

static int format_name ( char *  name,
int  name_buf_len,
int  i 
)
static

Definition at line 1461 of file hlsenc.c.

Referenced by hls_init().

static int get_nth_codec_stream_index ( AVFormatContext s,
enum AVMediaType  codec_type,
int  stream_id 
)
static

Definition at line 1480 of file hlsenc.c.

Referenced by parse_variant_stream_mapstring().

static int parse_variant_stream_mapstring ( AVFormatContext s)
static

Expected format for var_stream_map string is as below: "a:0,v:0 a:1,v:1" This string specifies how to group the audio, video and subtitle streams into different variant streams. The variant stream groups are separated by space.

a:, v:, s: are keys to specify audio, video and subtitle streams respectively. Allowed values are 0 to 9 digits (limited just based on practical usage)

Definition at line 1498 of file hlsenc.c.

Referenced by update_variant_stream_info().

static int update_variant_stream_info ( AVFormatContext s)
static

Definition at line 1587 of file hlsenc.c.

Referenced by hls_init().

static int update_master_pl_info ( AVFormatContext s)
static

Definition at line 1613 of file hlsenc.c.

Referenced by hls_init().

static int hls_write_header ( AVFormatContext s)
static

Definition at line 1639 of file hlsenc.c.

static int hls_write_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 1689 of file hlsenc.c.

static int hls_write_trailer ( struct AVFormatContext s)
static

Definition at line 1857 of file hlsenc.c.

static int hls_init ( AVFormatContext s)
static

Definition at line 1928 of file hlsenc.c.

Variable Documentation

const AVOption options[]
static
const AVClass hls_class
static
Initial value:
= {
.class_name = "hls muxer",
.item_name = av_default_item_name,
.option = options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:193
static const AVOption options[]
Definition: hlsenc.c:2273

Definition at line 2330 of file hlsenc.c.

AVOutputFormat ff_hls_muxer
Initial value:
= {
.name = "hls",
.long_name = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming"),
.extensions = "m3u8",
.priv_data_size = sizeof(HLSContext),
.audio_codec = AV_CODEC_ID_AAC,
.video_codec = AV_CODEC_ID_H264,
.subtitle_codec = AV_CODEC_ID_WEBVTT,
.priv_class = &hls_class,
}
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:681
static int hls_write_trailer(struct AVFormatContext *s)
Definition: hlsenc.c:1857
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define AVFMT_ALLOW_FLUSH
Format allows flushing.
Definition: avformat.h:478
static int flags
Definition: log.c:57
static int hls_write_header(AVFormatContext *s)
Definition: hlsenc.c:1639
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:94
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:468
static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: hlsenc.c:1689
static int hls_init(AVFormatContext *s)
Definition: hlsenc.c:1928
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:465
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:337
static const AVClass hls_class
Definition: hlsenc.c:2330

Definition at line 2338 of file hlsenc.c.