29 static int usage(
const char *argv0, 
int ret)
 
   31     fprintf(stderr, 
"%s -out foo.mpd file1\n", argv0);
 
   96         if (tag == 
MKBETAG(
's', 
'i', 
'd', 
'x')) {
 
   97             for (i = start_index; i < tracks->
nb_tracks; i++) {
 
  107         if (
avio_seek(f, pos + size, SEEK_SET) != pos + size)
 
  120     int err = 0, i, orig_tracks = tracks->
nb_tracks;
 
  121     char errbuf[50], *ptr;
 
  127         fprintf(stderr, 
"Unable to open %s: %s\n", file, errbuf);
 
  134         fprintf(stderr, 
"Unable to identify %s: %s\n", file, errbuf);
 
  139         fprintf(stderr, 
"No streams found in %s\n", file);
 
  150             fprintf(stderr, 
"Skipping track %d in %s as it has zero bitrate\n",
 
  171         if ((ptr = strrchr(file, 
'/')))
 
  172             track->
name = ptr + 1;
 
  183                     "Track %d in %s is neither video nor audio, skipping\n",
 
  208     err = 
find_sidx(tracks, orig_tracks, file);
 
  220     int minutes = seconds / 60;
 
  221     int hours = minutes / 60;
 
  227         fprintf(out, 
"%dH", hours);
 
  228     if (hours || minutes)
 
  229         fprintf(out, 
"%dM", minutes);
 
  230     fprintf(out, 
"%d.%0*dS", seconds, decimals, fractions);
 
  237     struct Track **adaptation_sets_buf[2] = { 
NULL };
 
  238     struct Track ***adaptation_sets;
 
  239     int nb_tracks_buf[2] = { 0 };
 
  244         adaptation_sets = adaptation_sets_buf;
 
  245         nb_tracks = nb_tracks_buf;
 
  247         for (i = 0; i < 2; i++) {
 
  249             if (!adaptation_sets[i]) {
 
  254         for (i = 0; i < tracks->
nb_tracks; i++) {
 
  262             adaptation_sets[set_index][nb_tracks[set_index]++] = tracks->
tracks[i];
 
  265         adaptation_sets = &tracks->
tracks;
 
  270     out = fopen(filename, 
"w");
 
  276     fprintf(out, 
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
 
  277     fprintf(out, 
"<MPD xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" 
  278                 "\txmlns=\"urn:mpeg:dash:schema:mpd:2011\"\n" 
  279                 "\txmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" 
  280                 "\txsi:schemaLocation=\"urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd\"\n" 
  281                 "\tprofiles=\"urn:mpeg:dash:profile:isoff-on-demand:2011\"\n" 
  282                 "\ttype=\"static\"\n");
 
  283     fprintf(out, 
"\tmediaPresentationDuration=\"");
 
  285     fprintf(out, 
"\"\n");
 
  286     fprintf(out, 
"\tminBufferTime=\"PT5S\">\n");
 
  288     fprintf(out, 
"\t<Period start=\"PT0.0S\">\n");
 
  290     for (set = 0; set < nb_sets; set++) {
 
  291         if (nb_tracks[set] == 0)
 
  293         fprintf(out, 
"\t\t<AdaptationSet segmentAlignment=\"true\">\n");
 
  295             for (i = 0; i < nb_tracks[
set]; i++) {
 
  296                 struct Track *track = adaptation_sets[
set][i];
 
  297                 if (strcmp(track->
name, adaptation_sets[set][0]->
name))
 
  299                 fprintf(out, 
"\t\t\t<ContentComponent id=\"%d\" contentType=\"%s\" />\n", track->
track_id, track->
is_audio ? 
"audio" : 
"video");
 
  303         for (i = 0; i < nb_tracks[
set]; ) {
 
  304             struct Track *first_track = adaptation_sets[
set][i];
 
  306             fprintf(out, 
"\t\t\t<Representation id=\"%d\" codecs=\"", i);
 
  307             for (j = i; j < nb_tracks[
set]; j++) {
 
  308                 struct Track *track = adaptation_sets[
set][j];
 
  309                 if (strcmp(track->
name, first_track->
name))
 
  316                     width = track->
width;
 
  324             fprintf(out, 
"\" mimeType=\"%s/mp4\" bandwidth=\"%d\"",
 
  325                     width ? 
"video" : 
"audio", 
bitrate);
 
  326             if (width > 0 && 
height > 0)
 
  327                 fprintf(out, 
" width=\"%d\" height=\"%d\"", width, 
height);
 
  329                 fprintf(out, 
" audioSamplingRate=\"%d\"", 
sample_rate);
 
  332                 fprintf(out, 
"\t\t\t\t<AudioChannelConfiguration schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"%d\" />\n", 
channels);
 
  333             fprintf(out, 
"\t\t\t\t<BaseURL>%s</BaseURL>\n", first_track->
name);
 
  334             fprintf(out, 
"\t\t\t\t<SegmentBase indexRange=\"%"PRId64
"-%"PRId64
"\" />\n", first_track->
sidx_start, first_track->
sidx_start + first_track->
sidx_length - 1);
 
  335             fprintf(out, 
"\t\t\t</Representation>\n");
 
  338         fprintf(out, 
"\t\t</AdaptationSet>\n");
 
  340     fprintf(out, 
"\t</Period>\n");
 
  341     fprintf(out, 
"</MPD>\n");
 
  345     for (i = 0; i < 2; i++)
 
  346         av_free(adaptation_sets_buf[i]);
 
  353     for (i = 0; i < tracks->
nb_tracks; i++) {
 
  360 int main(
int argc, 
char **argv)
 
  363     struct Tracks tracks = { 0 };
 
  368     for (i = 1; i < argc; i++) {
 
  369         if (!strcmp(argv[i], 
"-out")) {
 
  372         } 
else if (argv[i][0] == 
'-') {
 
  373             return usage(argv[0], 1);
 
  380         return usage(argv[0], 1);
 
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding. 
 
enum AVCodecID codec_id
Specific type of the encoded data (the codec used). 
 
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext. 
 
#define AVIO_FLAG_READ
read-only 
 
static void clean_tracks(struct Tracks *tracks)
 
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_WB24 unsigned int_TMPL AV_RB16
 
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
 
This struct describes the properties of an encoded stream. 
 
int main(int argc, char **argv)
 
static int find_sidx(struct Tracks *tracks, int start_index, const char *file)
 
unsigned int avio_rb32(AVIOContext *s)
 
int id
Format-specific stream ID. 
 
AVStream ** streams
A list of all streams in the file. 
 
static void write_time(FILE *out, int64_t time, int decimals, enum AVRounding round)
 
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext. 
 
int64_t bit_rate
The average bitrate of the encoded data (in bits per second). 
 
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it. 
 
static int output_mpd(struct Tracks *tracks, const char *filename)
 
enum AVMediaType codec_type
General type of the encoded data. 
 
static int usage(const char *argv0, int ret)
 
static av_always_inline av_const double round(double x)
 
static void set_codec_str(AVCodecParameters *codecpar, char *str, int size)
 
int extradata_size
Size of the extradata content in bytes. 
 
unsigned int nb_streams
Number of elements in AVFormatContext.streams. 
 
#define AV_TIME_BASE
Internal time base represented as integer. 
 
int multiple_tracks_per_file
 
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
 
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url. 
 
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf. 
 
int64_t duration
Decoding: duration of the stream, in stream time base. 
 
int sample_rate
Audio only. 
 
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information. 
 
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
 
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext. 
 
#define MKBETAG(a, b, c, d)
 
static int handle_file(struct Tracks *tracks, const char *file)
 
int eof_reached
true if eof reached 
 
int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header. 
 
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent. 
 
AVCodecParameters * codecpar
 
#define av_malloc_array(a, b)
 
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
 
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols. 
 
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...