40 #define mkdir(a, b) _mkdir(a)
49 static int usage(
const char *argv0,
int ret)
51 fprintf(stderr,
"%s [-split] [-n basename] file1 [file2] ...\n", argv0);
128 char dirname[100], filename[500];
131 for (i = start_index; i < files->
nb_files; i++) {
133 const char *type = vf->
is_video ?
"video" :
"audio";
135 mkdir(dirname, 0777);
136 for (j = 0; j < vf->
chunks; j++) {
137 snprintf(filename,
sizeof(filename),
"%s/Fragments(%s=%"PRId64
")",
149 int version, fieldlength, i, j;
159 for (i = start_index; i < files->
nb_files && !vf; i++)
161 vf = files->
files[i];
174 for (i = 0; i < vf->
chunks; i++) {
182 for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++)
184 for (j = 0; j < ((fieldlength >> 2) & 3) + 1; j++)
186 for (j = 0; j < ((fieldlength >> 0) & 3) + 1; j++)
203 const char *file,
int split)
222 while (!
read_tfra(files, start_index, f)) {
233 fprintf(stderr,
"Unable to read the MFRA atom in %s\n", file);
250 uint16_t sps_size, pps_size;
282 int err = 0, i, orig_files = files->
nb_files;
283 char errbuf[50], *ptr;
289 fprintf(stderr,
"Unable to open %s: %s\n", file, errbuf);
296 fprintf(stderr,
"Unable to identify %s: %s\n", file, errbuf);
301 fprintf(stderr,
"No streams found in %s\n", file);
315 if ((ptr = strrchr(file,
'/')) !=
NULL)
328 "Track %d in %s is neither video nor audio, skipping\n",
369 err =
read_mfra(files, orig_files, file, split);
378 const char *basename)
384 snprintf(filename,
sizeof(filename),
"%s.ism", basename);
385 out = fopen(filename,
"w");
390 fprintf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
391 fprintf(out,
"<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
392 fprintf(out,
"\t<head>\n");
393 fprintf(out,
"\t\t<meta name=\"clientManifestRelativePath\" "
394 "content=\"%s.ismc\" />\n", basename);
395 fprintf(out,
"\t</head>\n");
396 fprintf(out,
"\t<body>\n");
397 fprintf(out,
"\t\t<switch>\n");
398 for (i = 0; i < files->
nb_files; i++) {
400 const char *type = vf->
is_video ?
"video" :
"audio";
401 fprintf(out,
"\t\t\t<%s src=\"%s\" systemBitrate=\"%d\">\n",
403 fprintf(out,
"\t\t\t\t<param name=\"trackID\" value=\"%d\" "
404 "valueType=\"data\" />\n", vf->
track_id);
405 fprintf(out,
"\t\t\t</%s>\n", type);
407 fprintf(out,
"\t\t</switch>\n");
408 fprintf(out,
"\t</body>\n");
409 fprintf(out,
"</smil>\n");
414 const char *basename,
int split)
421 snprintf(filename,
sizeof(filename),
"Manifest");
423 snprintf(filename,
sizeof(filename),
"%s.ismc", basename);
424 out = fopen(filename,
"w");
429 fprintf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
430 fprintf(out,
"<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" "
431 "Duration=\"%"PRId64
"\">\n", files->
duration * 10);
437 "\t<StreamIndex Type=\"video\" QualityLevels=\"%d\" "
439 "Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n",
441 for (i = 0; i < files->
nb_files; i++) {
442 vf = files->
files[i];
446 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
447 "FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" "
448 "CodecPrivateData=\"",
452 fprintf(out,
"\" />\n");
455 fprintf(stderr,
"Mismatched number of video chunks in %s and %s\n",
459 for (i = 0; i < vf->
chunks; i++) {
460 for (j = files->
video_file + 1; j < files->nb_files; j++) {
463 fprintf(stderr,
"Mismatched duration of video chunk %d in %s and %s\n",
466 fprintf(out,
"\t\t<c n=\"%d\" d=\"%d\" />\n", i,
469 fprintf(out,
"\t</StreamIndex>\n");
476 "\t<StreamIndex Type=\"audio\" QualityLevels=\"%d\" "
478 "Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n",
480 for (i = 0; i < files->
nb_files; i++) {
481 vf = files->
files[i];
485 "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
486 "FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" "
487 "BitsPerSample=\"16\" PacketSize=\"%d\" "
488 "AudioTag=\"%d\" CodecPrivateData=\"",
493 fprintf(out,
"\" />\n");
496 fprintf(stderr,
"Mismatched number of audio chunks in %s and %s\n",
500 for (i = 0; i < vf->
chunks; i++) {
501 for (j = files->
audio_file + 1; j < files->nb_files; j++) {
504 fprintf(stderr,
"Mismatched duration of audio chunk %d in %s and %s\n",
507 fprintf(out,
"\t\t<c n=\"%d\" d=\"%d\" />\n",
510 fprintf(out,
"\t</StreamIndex>\n");
512 fprintf(out,
"</SmoothStreamingMedia>\n");
519 for (i = 0; i < files->
nb_files; 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 (!vf.
nb_files || (!basename && !split))
550 return usage(argv[0], 1);