40 #define mkdir(a, b) _mkdir(a)
51 fprintf(stderr,
"%s [-split] [-n basename] file1 [file2] ...\n", argv0);
128 char dirname[100], filename[500];
131 for (i = start_index; i < tracks->
nb_tracks; i++) {
134 snprintf(dirname,
sizeof(dirname),
"QualityLevels(%d)", track->
bitrate);
135 if (mkdir(dirname, 0777) == -1)
137 for (j = 0; j < track->
chunks; j++) {
138 snprintf(filename,
sizeof(filename),
"%s/Fragments(%s=%"PRId64
")",
150 int version, fieldlength, i, j;
153 struct Track *track = NULL;
160 for (i = start_index; i < tracks->
nb_tracks && !track; i++)
162 track = tracks->
tracks[i];
175 for (i = 0; i < track->
chunks; i++) {
183 for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++)
185 for (j = 0; j < ((fieldlength >> 2) & 3) + 1; j++)
187 for (j = 0; j < ((fieldlength >> 0) & 3) + 1; j++)
204 const char *file,
int split)
223 while (!
read_tfra(tracks, start_index, f)) {
234 fprintf(stderr,
"Unable to read the MFRA atom in %s\n", file);
251 uint16_t sps_size, pps_size;
283 int err = 0, i, orig_tracks = tracks->
nb_tracks;
284 char errbuf[50], *ptr;
290 fprintf(stderr,
"Unable to open %s: %s\n", file, errbuf);
297 fprintf(stderr,
"Unable to identify %s: %s\n", file, errbuf);
302 fprintf(stderr,
"No streams found in %s\n", file);
327 if ((ptr = strrchr(file,
'/')) != NULL)
328 track->
name = ptr + 1;
340 "Track %d in %s is neither video nor audio, skipping\n",
381 err =
read_mfra(tracks, orig_tracks, file, split);
390 const char *basename)
396 snprintf(filename,
sizeof(filename),
"%s.ism", basename);
397 out = fopen(filename,
"w");
402 fprintf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
403 fprintf(out,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
404 fprintf(out,
"\t<head>\n");
405 fprintf(out,
"\t\t<meta name=\"clientManifestRelativePath\" "
406 "content=\"%s.ismc\" />\n", basename);
407 fprintf(out,
"\t</head>\n");
408 fprintf(out,
"\t<body>\n");
409 fprintf(out,
"\t\t<switch>\n");
410 for (i = 0; i < tracks->
nb_tracks; i++) {
413 fprintf(out,
"\t\t\t<%s src=\"%s\" systemBitrate=\"%d\">\n",
415 fprintf(out,
"\t\t\t\t<param name=\"trackID\" value=\"%d\" "
416 "valueType=\"data\" />\n", track->
track_id);
417 fprintf(out,
"\t\t\t</%s>\n", type);
419 fprintf(out,
"\t\t</switch>\n");
420 fprintf(out,
"\t</body>\n");
421 fprintf(out,
"</smil>\n");
430 for (i = 0; i < track->
chunks; i++) {
431 for (j = main + 1; j < tracks->
nb_tracks; j++) {
434 fprintf(stderr,
"Mismatched duration of %s chunk %d in %s and %s\n",
437 fprintf(out,
"\t\t<c n=\"%d\" d=\"%d\" />\n",
443 const char *basename,
int split)
450 snprintf(filename,
sizeof(filename),
"Manifest");
452 snprintf(filename,
sizeof(filename),
"%s.ismc", basename);
453 out = fopen(filename,
"w");
458 fprintf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
459 fprintf(out,
"<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" "
460 "Duration=\"%"PRId64
"\">\n", tracks->
duration * 10);
463 struct Track *first_track = track;
466 "\t<StreamIndex Type=\"video\" QualityLevels=\"%d\" "
468 "Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n",
470 for (i = 0; i < tracks->
nb_tracks; i++) {
471 track = tracks->
tracks[i];
475 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
476 "FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" "
477 "CodecPrivateData=\"",
481 fprintf(out,
"\" />\n");
484 fprintf(stderr,
"Mismatched number of video chunks in %s and %s\n",
488 fprintf(out,
"\t</StreamIndex>\n");
492 struct Track *first_track = track;
495 "\t<StreamIndex Type=\"audio\" QualityLevels=\"%d\" "
497 "Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n",
499 for (i = 0; i < tracks->
nb_tracks; i++) {
500 track = tracks->
tracks[i];
504 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
505 "FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" "
506 "BitsPerSample=\"16\" PacketSize=\"%d\" "
507 "AudioTag=\"%d\" CodecPrivateData=\"",
512 fprintf(out,
"\" />\n");
515 fprintf(stderr,
"Mismatched number of audio chunks in %s and %s\n",
519 fprintf(out,
"\t</StreamIndex>\n");
521 fprintf(out,
"</SmoothStreamingMedia>\n");
528 for (i = 0; i < tracks->
nb_tracks; i++) {
537 int main(
int argc,
char **argv)
539 const char *basename = NULL;
545 for (i = 1; i < argc; i++) {
546 if (!strcmp(argv[i],
"-n")) {
547 basename = argv[i + 1];
549 }
else if (!strcmp(argv[i],
"-split")) {
551 }
else if (argv[i][0] ==
'-') {
552 return usage(argv[0], 1);
558 if (!tracks.
nb_tracks || (!basename && !split))
559 return usage(argv[0], 1);