31 fprintf(stderr,
"%s -out foo.mpd file1\n", argv0);
95 if (tag ==
MKBETAG(
's',
'i',
'd',
'x')) {
96 for (i = start_index; i < tracks->
nb_tracks; i++) {
106 if (
avio_seek(f, pos + size, SEEK_SET) != pos + size)
119 int err = 0, i, orig_tracks = tracks->
nb_tracks;
120 char errbuf[50], *ptr;
126 fprintf(stderr,
"Unable to open %s: %s\n", file, errbuf);
133 fprintf(stderr,
"Unable to identify %s: %s\n", file, errbuf);
138 fprintf(stderr,
"No streams found in %s\n", file);
149 fprintf(stderr,
"Skipping track %d in %s as it has zero bitrate\n",
170 if ((ptr = strrchr(file,
'/')))
171 track->
name = ptr + 1;
182 "Track %d in %s is neither video nor audio, skipping\n",
207 err =
find_sidx(tracks, orig_tracks, file);
219 int minutes = seconds / 60;
220 int hours = minutes / 60;
226 fprintf(out,
"%dH", hours);
227 if (hours || minutes)
228 fprintf(out,
"%dM", minutes);
229 fprintf(out,
"%d.%0*dS", seconds, decimals, fractions);
236 struct Track **adaptation_sets_buf[2] = {
NULL };
237 struct Track ***adaptation_sets;
238 int nb_tracks_buf[2] = { 0 };
243 adaptation_sets = adaptation_sets_buf;
244 nb_tracks = nb_tracks_buf;
246 for (i = 0; i < 2; i++) {
248 if (!adaptation_sets[i]) {
253 for (i = 0; i < tracks->
nb_tracks; i++) {
261 adaptation_sets[set_index][nb_tracks[set_index]++] = tracks->
tracks[i];
264 adaptation_sets = &tracks->
tracks;
269 out = fopen(filename,
"w");
275 fprintf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
276 fprintf(out,
"<MPD xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
277 "\txmlns=\"urn:mpeg:dash:schema:mpd:2011\"\n"
278 "\txmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
279 "\txsi:schemaLocation=\"urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd\"\n"
280 "\tprofiles=\"urn:mpeg:dash:profile:isoff-on-demand:2011\"\n"
281 "\ttype=\"static\"\n");
282 fprintf(out,
"\tmediaPresentationDuration=\"");
284 fprintf(out,
"\"\n");
285 fprintf(out,
"\tminBufferTime=\"PT5S\">\n");
287 fprintf(out,
"\t<Period start=\"PT0.0S\">\n");
289 for (set = 0; set < nb_sets; set++) {
290 if (nb_tracks[set] == 0)
292 fprintf(out,
"\t\t<AdaptationSet segmentAlignment=\"true\">\n");
294 for (i = 0; i < nb_tracks[
set]; i++) {
295 struct Track *track = adaptation_sets[
set][i];
296 if (strcmp(track->
name, adaptation_sets[set][0]->
name))
298 fprintf(out,
"\t\t\t<ContentComponent id=\"%d\" contentType=\"%s\" />\n", track->
track_id, track->
is_audio ?
"audio" :
"video");
302 for (i = 0; i < nb_tracks[
set]; ) {
303 struct Track *first_track = adaptation_sets[
set][i];
305 fprintf(out,
"\t\t\t<Representation id=\"%d\" codecs=\"", i);
306 for (j = i; j < nb_tracks[
set]; j++) {
307 struct Track *track = adaptation_sets[
set][j];
308 if (strcmp(track->
name, first_track->
name))
315 width = track->
width;
323 fprintf(out,
"\" mimeType=\"%s/mp4\" bandwidth=\"%d\"",
324 width ?
"video" :
"audio",
bitrate);
325 if (width > 0 &&
height > 0)
326 fprintf(out,
" width=\"%d\" height=\"%d\"", width,
height);
328 fprintf(out,
" audioSamplingRate=\"%d\"",
sample_rate);
331 fprintf(out,
"\t\t\t\t<AudioChannelConfiguration schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"%d\" />\n",
channels);
332 fprintf(out,
"\t\t\t\t<BaseURL>%s</BaseURL>\n", first_track->
name);
333 fprintf(out,
"\t\t\t\t<SegmentBase indexRange=\"%"PRId64
"-%"PRId64
"\" />\n", first_track->
sidx_start, first_track->
sidx_start + first_track->
sidx_length - 1);
334 fprintf(out,
"\t\t\t</Representation>\n");
337 fprintf(out,
"\t\t</AdaptationSet>\n");
339 fprintf(out,
"\t</Period>\n");
340 fprintf(out,
"</MPD>\n");
344 for (i = 0; i < 2; i++)
345 av_free(adaptation_sets_buf[i]);
352 for (i = 0; i < tracks->
nb_tracks; i++) {
359 int main(
int argc,
char **argv)
362 struct Tracks tracks = { 0 };
367 for (i = 1; i < argc; i++) {
368 if (!strcmp(argv[i],
"-out")) {
371 }
else if (argv[i][0] ==
'-') {
372 return usage(argv[0], 1);
379 return usage(argv[0], 1);
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
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.
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
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
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.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
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.
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)
static int usage(const char *argv0, int ret)
static av_always_inline av_const double round(double x)
AVCodecContext * codec
Codec context associated with this stream.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int bit_rate
the average bitrate
#define AV_TIME_BASE
Internal time base represented as integer.
int width
picture width / height.
int multiple_tracks_per_file
enum AVMediaType codec_type
static void set_codec_str(AVCodecContext *codec, char *str, int size)
int sample_rate
samples per second
main external API structure.
BYTE int const BYTE int int int height
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 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 channels
number of audio channels
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
#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 ...