47 fprintf(stderr,
"%s [-split] [-n basename] file1 [file2] ...\n", argv0);
124 char dirname[100], filename[500];
127 for (i = start_index; i < tracks->
nb_tracks; i++) {
130 snprintf(dirname,
sizeof(dirname),
"QualityLevels(%d)", track->
bitrate);
131 if (mkdir(dirname, 0777) == -1)
133 for (j = 0; j < track->
chunks; j++) {
134 snprintf(filename,
sizeof(filename),
"%s/Fragments(%s=%"PRId64
")",
146 int version, fieldlength, i, j;
149 struct Track *track = NULL;
156 for (i = start_index; i < tracks->
nb_tracks && !track; i++)
158 track = tracks->
tracks[i];
171 for (i = 0; i < track->
chunks; i++) {
179 for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++)
181 for (j = 0; j < ((fieldlength >> 2) & 3) + 1; j++)
183 for (j = 0; j < ((fieldlength >> 0) & 3) + 1; j++)
200 const char *file,
int split)
219 while (!
read_tfra(tracks, start_index, f)) {
230 fprintf(stderr,
"Unable to read the MFRA atom in %s\n", file);
247 uint16_t sps_size, pps_size;
279 int err = 0, i, orig_tracks = tracks->
nb_tracks;
280 char errbuf[50], *ptr;
286 fprintf(stderr,
"Unable to open %s: %s\n", file, errbuf);
293 fprintf(stderr,
"Unable to identify %s: %s\n", file, errbuf);
298 fprintf(stderr,
"No streams found in %s\n", file);
321 if ((ptr = strrchr(file,
'/')) != NULL)
322 track->
name = ptr + 1;
333 "Track %d in %s is neither video nor audio, skipping\n",
378 err =
read_mfra(tracks, orig_tracks, file, split);
387 const char *basename)
393 snprintf(filename,
sizeof(filename),
"%s.ism", basename);
394 out = fopen(filename,
"w");
399 fprintf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
400 fprintf(out,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
401 fprintf(out,
"\t<head>\n");
402 fprintf(out,
"\t\t<meta name=\"clientManifestRelativePath\" "
403 "content=\"%s.ismc\" />\n", basename);
404 fprintf(out,
"\t</head>\n");
405 fprintf(out,
"\t<body>\n");
406 fprintf(out,
"\t\t<switch>\n");
407 for (i = 0; i < tracks->
nb_tracks; i++) {
410 fprintf(out,
"\t\t\t<%s src=\"%s\" systemBitrate=\"%d\">\n",
412 fprintf(out,
"\t\t\t\t<param name=\"trackID\" value=\"%d\" "
413 "valueType=\"data\" />\n", track->
track_id);
414 fprintf(out,
"\t\t\t</%s>\n", type);
416 fprintf(out,
"\t\t</switch>\n");
417 fprintf(out,
"\t</body>\n");
418 fprintf(out,
"</smil>\n");
427 for (i = 0; i < track->
chunks; i++) {
428 for (j = main + 1; j < tracks->
nb_tracks; j++) {
431 fprintf(stderr,
"Mismatched duration of %s chunk %d in %s and %s\n",
434 fprintf(out,
"\t\t<c n=\"%d\" d=\"%"PRId64
"\" />\n",
440 const char *basename,
int split)
447 snprintf(filename,
sizeof(filename),
"Manifest");
449 snprintf(filename,
sizeof(filename),
"%s.ismc", basename);
450 out = fopen(filename,
"w");
455 fprintf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
456 fprintf(out,
"<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" "
457 "Duration=\"%"PRId64
"\">\n", tracks->
duration * 10);
460 struct Track *first_track = track;
463 "\t<StreamIndex Type=\"video\" QualityLevels=\"%d\" "
465 "Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n",
467 for (i = 0; i < tracks->
nb_tracks; i++) {
468 track = tracks->
tracks[i];
472 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
473 "FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" "
474 "CodecPrivateData=\"",
478 fprintf(out,
"\" />\n");
481 fprintf(stderr,
"Mismatched number of video chunks in %s and %s\n",
485 fprintf(out,
"\t</StreamIndex>\n");
489 struct Track *first_track = track;
492 "\t<StreamIndex Type=\"audio\" QualityLevels=\"%d\" "
494 "Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n",
496 for (i = 0; i < tracks->
nb_tracks; i++) {
497 track = tracks->
tracks[i];
501 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
502 "FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" "
503 "BitsPerSample=\"16\" PacketSize=\"%d\" "
504 "AudioTag=\"%d\" CodecPrivateData=\"",
509 fprintf(out,
"\" />\n");
512 fprintf(stderr,
"Mismatched number of audio chunks in %s and %s\n",
516 fprintf(out,
"\t</StreamIndex>\n");
518 fprintf(out,
"</SmoothStreamingMedia>\n");
525 for (i = 0; i < tracks->
nb_tracks; i++) {
534 int main(
int argc,
char **argv)
536 const char *basename = NULL;
542 for (i = 1; i < argc; i++) {
543 if (!strcmp(argv[i],
"-n")) {
544 basename = argv[i + 1];
546 }
else if (!strcmp(argv[i],
"-split")) {
548 }
else if (argv[i][0] ==
'-') {
549 return usage(argv[0], 1);
555 if (!tracks.
nb_tracks || (!basename && !split))
556 return usage(argv[0], 1);