43 static int usage(
const char *argv0,
int ret)
45 fprintf(stderr,
"%s [-split] [-n basename] file1 [file2] ...\n", argv0);
122 char dirname[100], filename[500];
125 for (i = start_index; i < tracks->
nb_tracks; i++) {
127 const char *type = track->
is_video ?
"video" :
"audio";
128 snprintf(dirname,
sizeof(dirname),
"QualityLevels(%d)", track->
bitrate);
129 mkdir(dirname, 0777);
130 for (j = 0; j < track->
chunks; j++) {
131 snprintf(filename,
sizeof(filename),
"%s/Fragments(%s=%"PRId64
")",
143 int version, fieldlength, i, j;
153 for (i = start_index; i < tracks->
nb_tracks && !track; i++)
155 track = tracks->
tracks[i];
168 for (i = 0; i < track->
chunks; i++) {
176 for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++)
178 for (j = 0; j < ((fieldlength >> 2) & 3) + 1; j++)
180 for (j = 0; j < ((fieldlength >> 0) & 3) + 1; j++)
197 const char *file,
int split)
216 while (!
read_tfra(tracks, start_index, f)) {
227 fprintf(stderr,
"Unable to read the MFRA atom in %s\n", file);
244 uint16_t sps_size, pps_size;
273 int err = 0, i, orig_tracks = tracks->
nb_tracks;
274 char errbuf[50], *ptr;
280 fprintf(stderr,
"Unable to open %s: %s\n", file, errbuf);
287 fprintf(stderr,
"Unable to identify %s: %s\n", file, errbuf);
292 fprintf(stderr,
"No streams found in %s\n", file);
315 if ((ptr = strrchr(file,
'/')) !=
NULL)
316 track->
name = ptr + 1;
327 "Track %d in %s is neither video nor audio, skipping\n",
372 err =
read_mfra(tracks, orig_tracks, file, split);
381 const char *basename)
387 snprintf(filename,
sizeof(filename),
"%s.ism", basename);
388 out = fopen(filename,
"w");
393 fprintf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
394 fprintf(out,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
395 fprintf(out,
"\t<head>\n");
396 fprintf(out,
"\t\t<meta name=\"clientManifestRelativePath\" "
397 "content=\"%s.ismc\" />\n", basename);
398 fprintf(out,
"\t</head>\n");
399 fprintf(out,
"\t<body>\n");
400 fprintf(out,
"\t\t<switch>\n");
401 for (i = 0; i < tracks->
nb_tracks; i++) {
403 const char *type = track->
is_video ?
"video" :
"audio";
404 fprintf(out,
"\t\t\t<%s src=\"%s\" systemBitrate=\"%d\">\n",
406 fprintf(out,
"\t\t\t\t<param name=\"trackID\" value=\"%d\" "
407 "valueType=\"data\" />\n", track->
track_id);
408 fprintf(out,
"\t\t\t</%s>\n", type);
410 fprintf(out,
"\t\t</switch>\n");
411 fprintf(out,
"\t</body>\n");
412 fprintf(out,
"</smil>\n");
421 for (i = 0; i < track->
chunks; i++) {
422 for (j = main + 1; j < tracks->
nb_tracks; j++) {
425 fprintf(stderr,
"Mismatched duration of %s chunk %d in %s and %s\n",
428 fprintf(out,
"\t\t<c n=\"%d\" d=\"%"PRId64
"\" />\n",
434 const char *basename,
int split)
441 snprintf(filename,
sizeof(filename),
"Manifest");
443 snprintf(filename,
sizeof(filename),
"%s.ismc", basename);
444 out = fopen(filename,
"w");
449 fprintf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
450 fprintf(out,
"<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" "
451 "Duration=\"%"PRId64
"\">\n", tracks->
duration * 10);
454 struct Track *first_track = track;
457 "\t<StreamIndex Type=\"video\" QualityLevels=\"%d\" "
459 "Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n",
461 for (i = 0; i < tracks->
nb_tracks; i++) {
462 track = tracks->
tracks[i];
466 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
467 "FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" "
468 "CodecPrivateData=\"",
472 fprintf(out,
"\" />\n");
475 fprintf(stderr,
"Mismatched number of video chunks in %s and %s\n",
479 fprintf(out,
"\t</StreamIndex>\n");
483 struct Track *first_track = track;
486 "\t<StreamIndex Type=\"audio\" QualityLevels=\"%d\" "
488 "Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n",
490 for (i = 0; i < tracks->
nb_tracks; i++) {
491 track = tracks->
tracks[i];
495 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
496 "FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" "
497 "BitsPerSample=\"16\" PacketSize=\"%d\" "
498 "AudioTag=\"%d\" CodecPrivateData=\"",
503 fprintf(out,
"\" />\n");
506 fprintf(stderr,
"Mismatched number of audio chunks in %s and %s\n",
510 fprintf(out,
"\t</StreamIndex>\n");
512 fprintf(out,
"</SmoothStreamingMedia>\n");
519 for (i = 0; i < tracks->
nb_tracks; i++) {
528 int main(
int argc,
char **argv)
530 const char *basename =
NULL;
536 for (i = 1; i < argc; i++) {
537 if (!strcmp(argv[i],
"-n")) {
538 basename = argv[i + 1];
540 }
else if (!strcmp(argv[i],
"-split")) {
542 }
else if (argv[i][0] ==
'-') {
543 return usage(argv[0], 1);
549 if (!tracks.
nb_tracks || (!basename && !split))
550 return usage(argv[0], 1);