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";
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;
280 int err = 0, i, orig_files = files->
nb_files;
281 char errbuf[50], *ptr;
287 fprintf(stderr,
"Unable to open %s: %s\n", file, errbuf);
294 fprintf(stderr,
"Unable to identify %s: %s\n", file, errbuf);
299 fprintf(stderr,
"No streams found in %s\n", file);
313 if ((ptr = strrchr(file,
'/')) !=
NULL)
326 "Track %d in %s is neither video nor audio, skipping\n",
367 err =
read_mfra(files, orig_files, file, split);
376 const char *basename)
382 snprintf(filename,
sizeof(filename),
"%s.ism", basename);
383 out = fopen(filename,
"w");
388 fprintf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
389 fprintf(out,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
390 fprintf(out,
"\t<head>\n");
391 fprintf(out,
"\t\t<meta name=\"clientManifestRelativePath\" "
392 "content=\"%s.ismc\" />\n", basename);
393 fprintf(out,
"\t</head>\n");
394 fprintf(out,
"\t<body>\n");
395 fprintf(out,
"\t\t<switch>\n");
396 for (i = 0; i < files->
nb_files; i++) {
398 const char *type = vf->
is_video ?
"video" :
"audio";
399 fprintf(out,
"\t\t\t<%s src=\"%s\" systemBitrate=\"%d\">\n",
401 fprintf(out,
"\t\t\t\t<param name=\"trackID\" value=\"%d\" "
402 "valueType=\"data\" />\n", vf->
track_id);
403 fprintf(out,
"\t\t\t</%s>\n", type);
405 fprintf(out,
"\t\t</switch>\n");
406 fprintf(out,
"\t</body>\n");
407 fprintf(out,
"</smil>\n");
412 const char *basename,
int split)
419 snprintf(filename,
sizeof(filename),
"Manifest");
421 snprintf(filename,
sizeof(filename),
"%s.ismc", basename);
422 out = fopen(filename,
"w");
427 fprintf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
428 fprintf(out,
"<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" "
429 "Duration=\"%"PRId64
"\">\n", files->
duration * 10);
435 "\t<StreamIndex Type=\"video\" QualityLevels=\"%d\" "
437 "Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n",
439 for (i = 0; i < files->
nb_files; i++) {
440 vf = files->
files[i];
444 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
445 "FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" "
446 "CodecPrivateData=\"",
450 fprintf(out,
"\" />\n");
453 fprintf(stderr,
"Mismatched number of video chunks in %s and %s\n",
457 for (i = 0; i < vf->
chunks; i++) {
458 for (j = files->
video_file + 1; j < files->nb_files; j++) {
461 fprintf(stderr,
"Mismatched duration of video chunk %d in %s and %s\n",
464 fprintf(out,
"\t\t<c n=\"%d\" d=\"%d\" />\n", i,
467 fprintf(out,
"\t</StreamIndex>\n");
474 "\t<StreamIndex Type=\"audio\" QualityLevels=\"%d\" "
476 "Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n",
478 for (i = 0; i < files->
nb_files; i++) {
479 vf = files->
files[i];
483 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
484 "FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" "
485 "BitsPerSample=\"16\" PacketSize=\"%d\" "
486 "AudioTag=\"%d\" CodecPrivateData=\"",
491 fprintf(out,
"\" />\n");
494 fprintf(stderr,
"Mismatched number of audio chunks in %s and %s\n",
498 for (i = 0; i < vf->
chunks; i++) {
499 for (j = files->
audio_file + 1; j < files->nb_files; j++) {
502 fprintf(stderr,
"Mismatched duration of audio chunk %d in %s and %s\n",
505 fprintf(out,
"\t\t<c n=\"%d\" d=\"%d\" />\n",
508 fprintf(out,
"\t</StreamIndex>\n");
510 fprintf(out,
"</SmoothStreamingMedia>\n");
517 for (i = 0; i < files->
nb_files; i++) {
526 int main(
int argc,
char **argv)
528 const char *basename =
NULL;
534 for (i = 1; i < argc; i++) {
535 if (!strcmp(argv[i],
"-n")) {
536 basename = argv[i + 1];
538 }
else if (!strcmp(argv[i],
"-split")) {
540 }
else if (argv[i][0] ==
'-') {
541 return usage(argv[0], 1);
547 if (!vf.
nb_files || (!basename && !split))
548 return usage(argv[0], 1);