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);