FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
dashenc.c File Reference
#include "config.h"
#include "libavutil/avassert.h"
#include "libavutil/avutil.h"
#include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/rational.h"
#include "libavutil/time_internal.h"
#include "avc.h"
#include "avformat.h"
#include "avio_internal.h"
#include "hlsplaylist.h"
#include "internal.h"
#include "isom.h"
#include "os_support.h"
#include "url.h"
#include "vpcc.h"
#include "dash.h"

Go to the source code of this file.

Data Structures

struct  Segment
 
struct  AdaptationSet
 
struct  OutputStream
 
struct  DASHContext
 
struct  codec_string
 
struct  format_string
 

Macros

#define OFFSET(x)   offsetof(DASHContext, x)
 
#define E   AV_OPT_FLAG_ENCODING_PARAM
 

Enumerations

enum  SegmentType {
  PALETTE_SEGMENT = 0x14, OBJECT_SEGMENT = 0x15, PRESENTATION_SEGMENT = 0x16, WINDOW_SEGMENT = 0x17,
  DISPLAY_SEGMENT = 0x80, SEGMENT_TYPE_MP4 = 0, SEGMENT_TYPE_WEBM, SEGMENT_TYPE_NB,
  SEGMENT_TYPE_MPEGTS, SEGMENT_TYPE_FMP4
}
 

Functions

static int dashenc_io_open (AVFormatContext *s, AVIOContext **pb, char *filename, AVDictionary **options)
 
static void dashenc_io_close (AVFormatContext *s, AVIOContext **pb, char *filename)
 
static const char * get_format_str (SegmentType segment_type)
 
static int check_file_extension (const char *filename, const char *extension)
 
static void set_vp9_codec_str (AVFormatContext *s, AVCodecParameters *par, AVRational *frame_rate, char *str, int size)
 
static void set_codec_str (AVFormatContext *s, AVCodecParameters *par, AVRational *frame_rate, char *str, int size)
 
static int flush_dynbuf (OutputStream *os, int *range_length)
 
static void set_http_options (AVDictionary **options, DASHContext *c)
 
static void get_hls_playlist_name (char *playlist_name, int string_size, const char *base_url, int id)
 
static int flush_init_segment (AVFormatContext *s, OutputStream *os)
 
static void dash_free (AVFormatContext *s)
 
static void output_segment_list (OutputStream *os, AVIOContext *out, AVFormatContext *s, int representation_id, int final)
 
static char * xmlescape (const char *str)
 
static void write_time (AVIOContext *out, int64_t time)
 
static void format_date_now (char *buf, int size)
 
static int write_adaptation_set (AVFormatContext *s, AVIOContext *out, int as_index, int final)
 
static int add_adaptation_set (AVFormatContext *s, AdaptationSet **as, enum AVMediaType type)
 
static int adaptation_set_add_stream (AVFormatContext *s, int as_idx, int i)
 
static int parse_adaptation_sets (AVFormatContext *s)
 
static int write_manifest (AVFormatContext *s, int final)
 
static int dict_copy_entry (AVDictionary **dst, const AVDictionary *src, const char *key)
 
static int dash_init (AVFormatContext *s)
 
static int dash_write_header (AVFormatContext *s)
 
static int add_segment (OutputStream *os, const char *file, int64_t time, int duration, int64_t start_pos, int64_t range_length, int64_t index_length, int next_exp_index)
 
static void write_styp (AVIOContext *pb)
 
static void find_index_range (AVFormatContext *s, const char *full_path, int64_t pos, int *index_length)
 
static int update_stream_extradata (AVFormatContext *s, OutputStream *os, AVCodecParameters *par, AVRational *frame_rate)
 
static void dashenc_delete_file (AVFormatContext *s, char *filename)
 
static int dash_flush (AVFormatContext *s, int final, int stream)
 
static int dash_write_packet (AVFormatContext *s, AVPacket *pkt)
 
static int dash_write_trailer (AVFormatContext *s)
 
static int dash_check_bitstream (struct AVFormatContext *s, const AVPacket *avpkt)
 

Variables

static struct codec_string codecs []
 
static struct format_string formats []
 
static const AVOption options []
 
static const AVClass dash_class
 
AVOutputFormat ff_dash_muxer
 

Macro Definition Documentation

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

Definition at line 1570 of file dashenc.c.

Definition at line 1571 of file dashenc.c.

Enumeration Type Documentation

Enumerator
PALETTE_SEGMENT 
OBJECT_SEGMENT 
PRESENTATION_SEGMENT 
WINDOW_SEGMENT 
DISPLAY_SEGMENT 
SEGMENT_TYPE_MP4 
SEGMENT_TYPE_WEBM 
SEGMENT_TYPE_NB 
SEGMENT_TYPE_MPEGTS 
SEGMENT_TYPE_FMP4 

Definition at line 51 of file dashenc.c.

Function Documentation

static int dashenc_io_open ( AVFormatContext s,
AVIOContext **  pb,
char *  filename,
AVDictionary **  options 
)
static
static void dashenc_io_close ( AVFormatContext s,
AVIOContext **  pb,
char *  filename 
)
static

Definition at line 175 of file dashenc.c.

Referenced by dash_flush(), flush_init_segment(), output_segment_list(), and write_manifest().

static const char* get_format_str ( SegmentType  segment_type)
static

Definition at line 191 of file dashenc.c.

Referenced by dash_init().

static int check_file_extension ( const char *  filename,
const char *  extension 
)
static

Definition at line 199 of file dashenc.c.

Referenced by dash_init().

static void set_vp9_codec_str ( AVFormatContext s,
AVCodecParameters par,
AVRational frame_rate,
char *  str,
int  size 
)
static

Definition at line 209 of file dashenc.c.

Referenced by set_codec_str().

static void set_codec_str ( AVFormatContext s,
AVCodecParameters par,
AVRational frame_rate,
char *  str,
int  size 
)
static

Definition at line 224 of file dashenc.c.

Referenced by dash_init(), and update_stream_extradata().

static int flush_dynbuf ( OutputStream os,
int range_length 
)
static

Definition at line 305 of file dashenc.c.

Referenced by dash_flush(), and flush_init_segment().

static void set_http_options ( AVDictionary **  options,
DASHContext c 
)
static
static void get_hls_playlist_name ( char *  playlist_name,
int  string_size,
const char *  base_url,
int  id 
)
static

Definition at line 340 of file dashenc.c.

Referenced by output_segment_list(), and write_manifest().

static int flush_init_segment ( AVFormatContext s,
OutputStream os 
)
static

Definition at line 348 of file dashenc.c.

Referenced by dash_write_header(), and dash_write_packet().

static void dash_free ( AVFormatContext s)
static

Definition at line 366 of file dashenc.c.

static void output_segment_list ( OutputStream os,
AVIOContext out,
AVFormatContext s,
int  representation_id,
int  final 
)
static

Definition at line 399 of file dashenc.c.

Referenced by write_adaptation_set().

static char* xmlescape ( const char *  str)
static

Definition at line 522 of file dashenc.c.

Referenced by write_manifest().

static void write_time ( AVIOContext out,
int64_t  time 
)
static

Definition at line 562 of file dashenc.c.

Referenced by write_manifest().

static void format_date_now ( char *  buf,
int  size 
)
static

Definition at line 578 of file dashenc.c.

Referenced by dash_write_packet(), and write_manifest().

static int write_adaptation_set ( AVFormatContext s,
AVIOContext out,
int  as_index,
int  final 
)
static

Definition at line 589 of file dashenc.c.

Referenced by write_manifest().

static int add_adaptation_set ( AVFormatContext s,
AdaptationSet **  as,
enum AVMediaType  type 
)
static

Definition at line 642 of file dashenc.c.

Referenced by parse_adaptation_sets().

static int adaptation_set_add_stream ( AVFormatContext s,
int  as_idx,
int  i 
)
static

Definition at line 659 of file dashenc.c.

Referenced by parse_adaptation_sets().

static int parse_adaptation_sets ( AVFormatContext s)
static

Definition at line 677 of file dashenc.c.

Referenced by dash_init().

static int write_manifest ( AVFormatContext s,
int  final 
)
static

Definition at line 776 of file dashenc.c.

Referenced by dash_flush().

static int dict_copy_entry ( AVDictionary **  dst,
const AVDictionary src,
const char *  key 
)
static

Definition at line 943 of file dashenc.c.

Referenced by dash_init().

static int dash_init ( AVFormatContext s)
static

Definition at line 951 of file dashenc.c.

static int dash_write_header ( AVFormatContext s)
static

Definition at line 1127 of file dashenc.c.

static int add_segment ( OutputStream os,
const char *  file,
int64_t  time,
int  duration,
int64_t  start_pos,
int64_t  range_length,
int64_t  index_length,
int  next_exp_index 
)
static

Definition at line 1146 of file dashenc.c.

Referenced by dash_flush().

static void write_styp ( AVIOContext pb)
static

Definition at line 1186 of file dashenc.c.

Referenced by dash_flush(), and dash_write_packet().

static void find_index_range ( AVFormatContext s,
const char *  full_path,
int64_t  pos,
int index_length 
)
static

Definition at line 1196 of file dashenc.c.

Referenced by dash_flush().

static int update_stream_extradata ( AVFormatContext s,
OutputStream os,
AVCodecParameters par,
AVRational frame_rate 
)
static

Definition at line 1219 of file dashenc.c.

Referenced by dash_write_packet().

static void dashenc_delete_file ( AVFormatContext s,
char *  filename 
)
static

Definition at line 1243 of file dashenc.c.

Referenced by dash_flush(), and dash_write_trailer().

static int dash_flush ( AVFormatContext s,
int  final,
int  stream 
)
static

Definition at line 1265 of file dashenc.c.

Referenced by dash_write_packet(), and dash_write_trailer().

static int dash_write_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 1379 of file dashenc.c.

static int dash_write_trailer ( AVFormatContext s)
static

Definition at line 1515 of file dashenc.c.

static int dash_check_bitstream ( struct AVFormatContext s,
const AVPacket avpkt 
)
static

Definition at line 1547 of file dashenc.c.

Variable Documentation

struct codec_string codecs[]
static
Initial value:
= {
{ AV_CODEC_ID_VP8, "vp8" },
{ AV_CODEC_ID_VP9, "vp9" },
{ AV_CODEC_ID_VORBIS, "vorbis" },
{ AV_CODEC_ID_OPUS, "opus" },
{ 0, NULL }
}
#define NULL
Definition: coverity.c:32

Referenced by get_codecs_sorted(), print_codecs(), set_codec_str(), and show_codecs().

struct format_string formats[]
static
Initial value:
= {
{ SEGMENT_TYPE_MP4, "mp4" },
{ SEGMENT_TYPE_WEBM, "webm" },
{ 0, NULL }
}
#define NULL
Definition: coverity.c:32
const AVOption options[]
static
Initial value:
= {
{ "adaptation_sets", "Adaptation sets. Syntax: id=0,streams=0,1,2 id=1,streams=3,4 and so on", OFFSET(adaptation_sets), AV_OPT_TYPE_STRING, { 0 }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
{ "window_size", "number of segments kept in the manifest", OFFSET(window_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, E },
{ "extra_window_size", "number of segments kept outside of the manifest before removing from disk", OFFSET(extra_window_size), AV_OPT_TYPE_INT, { .i64 = 5 }, 0, INT_MAX, E },
{ "seg_duration", "segment duration (in seconds, fractional value can be set)", OFFSET(seg_duration), AV_OPT_TYPE_DURATION, { .i64 = 5000000 }, 0, INT_MAX, E },
{ "remove_at_exit", "remove all segments when finished", OFFSET(remove_at_exit), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E },
{ "use_template", "Use SegmentTemplate instead of SegmentList", OFFSET(use_template), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, E },
{ "use_timeline", "Use SegmentTimeline in SegmentTemplate", OFFSET(use_timeline), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, E },
{ "single_file", "Store all segments in one file, accessed using byte ranges", OFFSET(single_file), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E },
{ "single_file_name", "DASH-templated name to be used for baseURL. Implies storing all segments in one file, accessed using byte ranges", OFFSET(single_file_name), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
{ "init_seg_name", "DASH-templated name to used for the initialization segment", OFFSET(init_seg_name), AV_OPT_TYPE_STRING, {.str = "init-stream$RepresentationID$.m4s"}, 0, 0, E },
{ "media_seg_name", "DASH-templated name to used for the media segments", OFFSET(media_seg_name), AV_OPT_TYPE_STRING, {.str = "chunk-stream$RepresentationID$-$Number%05d$.m4s"}, 0, 0, E },
{ "utc_timing_url", "URL of the page that will return the UTC timestamp in ISO format", OFFSET(utc_timing_url), AV_OPT_TYPE_STRING, { 0 }, 0, 0, E },
{ "method", "set the HTTP method", OFFSET(method), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
{ "http_user_agent", "override User-Agent field in HTTP header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
{ "http_persistent", "Use persistent HTTP connections", OFFSET(http_persistent), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
{ "hls_playlist", "Generate HLS playlist files(master.m3u8, media_%d.m3u8)", OFFSET(hls_playlist), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E },
{ "streaming", "Enable/Disable streaming mode of output. Each frame will be moof fragment", OFFSET(streaming), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E },
{ "timeout", "set timeout for socket I/O operations", OFFSET(timeout), AV_OPT_TYPE_DURATION, { .i64 = -1 }, -1, INT_MAX, .flags = E },
{ "index_correction", "Enable/Disable segment index correction logic", OFFSET(index_correction), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E },
{ "format_options","set list of options for the container format (mp4/webm) used for dash", OFFSET(format_options_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
{ "dash_segment_type", "set dash segment files type", OFFSET(segment_type), AV_OPT_TYPE_INT, {.i64 = SEGMENT_TYPE_MP4 }, 0, SEGMENT_TYPE_NB - 1, E, "segment_type"},
{ "mp4", "make segment file in ISOBMFF format", 0, AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_MP4 }, 0, UINT_MAX, E, "segment_type"},
{ "webm", "make segment file in WebM format", 0, AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_WEBM }, 0, UINT_MAX, E, "segment_type"},
{ NULL },
}
#define NULL
Definition: coverity.c:32
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:276
#define E
Definition: dashenc.c:1571
#define OFFSET(x)
Definition: dashenc.c:1570

Definition at line 1572 of file dashenc.c.

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

Definition at line 1602 of file dashenc.c.

AVOutputFormat ff_dash_muxer
Initial value:
= {
.name = "dash",
.long_name = NULL_IF_CONFIG_SMALL("DASH Muxer"),
.extensions = "mpd",
.priv_data_size = sizeof(DASHContext),
.audio_codec = AV_CODEC_ID_AAC,
.video_codec = AV_CODEC_ID_H264,
.deinit = dash_free,
.check_bitstream = dash_check_bitstream,
.priv_class = &dash_class,
}
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:689
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static int dash_init(AVFormatContext *s)
Definition: dashenc.c:951
static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: dashenc.c:1379
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
static int dash_check_bitstream(struct AVFormatContext *s, const AVPacket *avpkt)
Definition: dashenc.c:1547
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:94
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:468
#define flags(name, subs,...)
Definition: cbs_av1.c:596
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:465
static int dash_write_header(AVFormatContext *s)
Definition: dashenc.c:1127
static int dash_write_trailer(AVFormatContext *s)
Definition: dashenc.c:1515
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:337
static void dash_free(AVFormatContext *s)
Definition: dashenc.c:366
#define AVFMT_TS_NEGATIVE
Format allows muxing negative timestamps.
Definition: avformat.h:484
static const AVClass dash_class
Definition: dashenc.c:1602

Definition at line 1609 of file dashenc.c.