40 #define mkdir(a, b) _mkdir(a)
47 static int usage(
const char *argv0,
int ret)
49 fprintf(stderr,
"%s [-split] [-n basename] file1 [file2] ...\n", argv0);
126 char dirname[100], filename[500];
129 for (i = start_index; i < files->
nb_files; i++) {
131 const char *type = vf->
is_video ?
"video" :
"audio";
132 snprintf(dirname,
sizeof(dirname),
"QualityLevels(%d)", vf->
bitrate);
133 mkdir(dirname, 0777);
134 for (j = 0; j < vf->
chunks; j++) {
135 snprintf(filename,
sizeof(filename),
"%s/Fragments(%s=%"PRId64
")",
147 int version, fieldlength, i, j;
157 for (i = start_index; i < files->
nb_files && !vf; i++)
159 vf = files->
files[i];
172 for (i = 0; i < vf->
chunks; i++) {
180 for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++)
182 for (j = 0; j < ((fieldlength >> 2) & 3) + 1; j++)
184 for (j = 0; j < ((fieldlength >> 0) & 3) + 1; j++)
201 const char *file,
int split)
220 while (!
read_tfra(files, start_index, f)) {
231 fprintf(stderr,
"Unable to read the MFRA atom in %s\n", file);
248 uint16_t sps_size, pps_size;
277 int err = 0, i, orig_files = files->
nb_files;
278 char errbuf[50], *ptr;
284 fprintf(stderr,
"Unable to open %s: %s\n", file, errbuf);
291 fprintf(stderr,
"Unable to identify %s: %s\n", file, errbuf);
296 fprintf(stderr,
"No streams found in %s\n", file);
310 if ((ptr = strrchr(file,
'/')) !=
NULL)
323 "Track %d in %s is neither video nor audio, skipping\n",
364 err =
read_mfra(files, orig_files, file, split);
373 const char *basename)
379 snprintf(filename,
sizeof(filename),
"%s.ism", basename);
380 out = fopen(filename,
"w");
385 fprintf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
386 fprintf(out,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
387 fprintf(out,
"\t<head>\n");
388 fprintf(out,
"\t\t<meta name=\"clientManifestRelativePath\" "
389 "content=\"%s.ismc\" />\n", basename);
390 fprintf(out,
"\t</head>\n");
391 fprintf(out,
"\t<body>\n");
392 fprintf(out,
"\t\t<switch>\n");
393 for (i = 0; i < files->
nb_files; i++) {
395 const char *type = vf->
is_video ?
"video" :
"audio";
396 fprintf(out,
"\t\t\t<%s src=\"%s\" systemBitrate=\"%d\">\n",
398 fprintf(out,
"\t\t\t\t<param name=\"trackID\" value=\"%d\" "
399 "valueType=\"data\" />\n", vf->
track_id);
400 fprintf(out,
"\t\t\t</%s>\n", type);
402 fprintf(out,
"\t\t</switch>\n");
403 fprintf(out,
"\t</body>\n");
404 fprintf(out,
"</smil>\n");
409 const char *basename,
int split)
416 snprintf(filename,
sizeof(filename),
"Manifest");
418 snprintf(filename,
sizeof(filename),
"%s.ismc", basename);
419 out = fopen(filename,
"w");
424 fprintf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
425 fprintf(out,
"<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" "
426 "Duration=\"%"PRId64
"\">\n", files->
duration * 10);
432 "\t<StreamIndex Type=\"video\" QualityLevels=\"%d\" "
434 "Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n",
436 for (i = 0; i < files->
nb_files; i++) {
437 vf = files->
files[i];
441 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
442 "FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" "
443 "CodecPrivateData=\"",
447 fprintf(out,
"\" />\n");
450 fprintf(stderr,
"Mismatched number of video chunks in %s and %s\n",
454 for (i = 0; i < vf->
chunks; i++) {
455 for (j = files->
video_file + 1; j < files->nb_files; j++) {
458 fprintf(stderr,
"Mismatched duration of video chunk %d in %s and %s\n",
461 fprintf(out,
"\t\t<c n=\"%d\" d=\"%d\" />\n", i,
464 fprintf(out,
"\t</StreamIndex>\n");
471 "\t<StreamIndex Type=\"audio\" QualityLevels=\"%d\" "
473 "Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n",
475 for (i = 0; i < files->
nb_files; i++) {
476 vf = files->
files[i];
480 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
481 "FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" "
482 "BitsPerSample=\"16\" PacketSize=\"%d\" "
483 "AudioTag=\"%d\" CodecPrivateData=\"",
488 fprintf(out,
"\" />\n");
491 fprintf(stderr,
"Mismatched number of audio chunks in %s and %s\n",
495 for (i = 0; i < vf->
chunks; i++) {
496 for (j = files->
audio_file + 1; j < files->nb_files; j++) {
499 fprintf(stderr,
"Mismatched duration of audio chunk %d in %s and %s\n",
502 fprintf(out,
"\t\t<c n=\"%d\" d=\"%d\" />\n",
505 fprintf(out,
"\t</StreamIndex>\n");
507 fprintf(out,
"</SmoothStreamingMedia>\n");
514 for (i = 0; i < files->
nb_files; i++) {
523 int main(
int argc,
char **argv)
525 const char *basename =
NULL;
531 for (i = 1; i < argc; i++) {
532 if (!strcmp(argv[i],
"-n")) {
533 basename = argv[i + 1];
535 }
else if (!strcmp(argv[i],
"-split")) {
537 }
else if (argv[i][0] ==
'-') {
538 return usage(argv[0], 1);
544 if (!vf.
nb_files || (!basename && !split))
545 return usage(argv[0], 1);
static int copy_tag(AVIOContext *in, AVIOContext *out, int32_t tag_name)
struct MoofOffset * offsets
static int handle_file(struct VideoFiles *files, const char *file, int split)
static void clean_files(struct VideoFiles *files)
int64_t avio_size(AVIOContext *s)
Get the filesize.
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
static int usage(const char *argv0, int ret)
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.
static int read_tfra(struct VideoFiles *files, int start_index, AVIOContext *f)
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
unsigned int avio_rb32(AVIOContext *s)
int id
Format-specific stream ID.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint64_t avio_rb64(AVIOContext *s)
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 int write_fragment(const char *filename, AVIOContext *in)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
struct VideoFile ** files
static void output_server_manifest(struct VideoFiles *files, const char *basename)
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
static char * split(char *message, char delim)
int avio_r8(AVIOContext *s)
AVCodecContext * codec
Codec context associated with this stream.
unsigned int nb_streams
A list of all streams in the file.
int bit_rate
the average bitrate
int void avio_flush(AVIOContext *s)
unsigned int avio_rb24(AVIOContext *s)
int width
picture width / height.
static int get_video_private_data(struct VideoFile *vf, AVCodecContext *codec)
static void output_client_manifest(struct VideoFiles *files, const char *basename, int split)
enum AVMediaType codec_type
int sample_rate
samples per second
main external API structure.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
#define MKBETAG(a, b, c, d)
static int get_private_data(struct VideoFile *vf, AVCodecContext *codec)
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.
static int write_fragments(struct VideoFiles *files, int start_index, AVIOContext *in)
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
static int read_mfra(struct VideoFiles *files, int start_index, const char *file, int split)
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
#define AVERROR_INVALIDDATA
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
int channels
number of audio channels
void avio_wb32(AVIOContext *s, unsigned int val)
int64_t duration
Decoding: duration of the stream, in AV_TIME_BASE fractional seconds.
int main(int argc, char **argv)
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 ...