You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

629 lines
21KB

  1. /*
  2. * Copyright (c) 2012 Martin Storsjo
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /*
  21. * To create a simple file for smooth streaming:
  22. * ffmpeg <normal input/transcoding options> -movflags frag_keyframe foo.ismv
  23. * ismindex -n foo foo.ismv
  24. * This step creates foo.ism and foo.ismc that is required by IIS for
  25. * serving it.
  26. *
  27. * By adding -path-prefix path/, the produced foo.ism will refer to the
  28. * files foo.ismv as "path/foo.ismv" - the prefix for the generated ismc
  29. * file can be set with the -ismc-prefix option similarly.
  30. *
  31. * To pre-split files for serving as static files by a web server without
  32. * any extra server support, create the ismv file as above, and split it:
  33. * ismindex -split foo.ismv
  34. * This step creates a file Manifest and directories QualityLevel(...),
  35. * that can be read directly by a smooth streaming player.
  36. *
  37. * The -output dir option can be used to request that output files
  38. * (both .ism/.ismc, or Manifest/QualityLevels* when splitting)
  39. * should be written to this directory instead of in the current directory.
  40. * (The directory itself isn't created if it doesn't already exist.)
  41. */
  42. #include <stdio.h>
  43. #include <string.h>
  44. #include "cmdutils.h"
  45. #include "libavformat/avformat.h"
  46. #include "libavformat/os_support.h"
  47. #include "libavutil/intreadwrite.h"
  48. #include "libavutil/mathematics.h"
  49. static int usage(const char *argv0, int ret)
  50. {
  51. fprintf(stderr, "%s [-split] [-n basename] [-path-prefix prefix] "
  52. "[-ismc-prefix prefix] [-output dir] file1 [file2] ...\n", argv0);
  53. return ret;
  54. }
  55. struct MoofOffset {
  56. int64_t time;
  57. int64_t offset;
  58. int64_t duration;
  59. };
  60. struct Track {
  61. const char *name;
  62. int64_t duration;
  63. int bitrate;
  64. int track_id;
  65. int is_audio, is_video;
  66. int width, height;
  67. int chunks;
  68. int sample_rate, channels;
  69. uint8_t *codec_private;
  70. int codec_private_size;
  71. struct MoofOffset *offsets;
  72. int timescale;
  73. const char *fourcc;
  74. int blocksize;
  75. int tag;
  76. };
  77. struct Tracks {
  78. int nb_tracks;
  79. int64_t duration;
  80. struct Track **tracks;
  81. int video_track, audio_track;
  82. int nb_video_tracks, nb_audio_tracks;
  83. };
  84. static int copy_tag(AVIOContext *in, AVIOContext *out, int32_t tag_name)
  85. {
  86. int32_t size, tag;
  87. size = avio_rb32(in);
  88. tag = avio_rb32(in);
  89. avio_wb32(out, size);
  90. avio_wb32(out, tag);
  91. if (tag != tag_name) {
  92. char tag_str[4], tag_name_str[4];
  93. AV_WB32(tag_str, tag);
  94. AV_WB32(tag_name_str, tag_name);
  95. fprintf(stderr, "wanted tag %.4s, got %.4s\n", tag_name_str, tag_str);
  96. return -1;
  97. }
  98. size -= 8;
  99. while (size > 0) {
  100. char buf[1024];
  101. int len = FFMIN(sizeof(buf), size);
  102. int got;
  103. if ((got = avio_read(in, buf, len)) != len) {
  104. fprintf(stderr, "short read, wanted %d, got %d\n", len, got);
  105. break;
  106. }
  107. avio_write(out, buf, len);
  108. size -= len;
  109. }
  110. return 0;
  111. }
  112. static int write_fragment(const char *filename, AVIOContext *in)
  113. {
  114. AVIOContext *out = NULL;
  115. int ret;
  116. if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, NULL, NULL)) < 0) {
  117. char errbuf[100];
  118. av_strerror(ret, errbuf, sizeof(errbuf));
  119. fprintf(stderr, "Unable to open %s: %s\n", filename, errbuf);
  120. return ret;
  121. }
  122. ret = copy_tag(in, out, MKBETAG('m', 'o', 'o', 'f'));
  123. if (!ret)
  124. ret = copy_tag(in, out, MKBETAG('m', 'd', 'a', 't'));
  125. avio_flush(out);
  126. avio_close(out);
  127. return ret;
  128. }
  129. static int write_fragments(struct Tracks *tracks, int start_index,
  130. AVIOContext *in, const char *output_prefix)
  131. {
  132. char dirname[2048], filename[2048];
  133. int i, j;
  134. for (i = start_index; i < tracks->nb_tracks; i++) {
  135. struct Track *track = tracks->tracks[i];
  136. const char *type = track->is_video ? "video" : "audio";
  137. snprintf(dirname, sizeof(dirname), "%sQualityLevels(%d)", output_prefix, track->bitrate);
  138. if (mkdir(dirname, 0777) == -1)
  139. return AVERROR(errno);
  140. for (j = 0; j < track->chunks; j++) {
  141. snprintf(filename, sizeof(filename), "%s/Fragments(%s=%"PRId64")",
  142. dirname, type, track->offsets[j].time);
  143. avio_seek(in, track->offsets[j].offset, SEEK_SET);
  144. write_fragment(filename, in);
  145. }
  146. }
  147. return 0;
  148. }
  149. static int read_tfra(struct Tracks *tracks, int start_index, AVIOContext *f)
  150. {
  151. int ret = AVERROR_EOF, track_id;
  152. int version, fieldlength, i, j;
  153. int64_t pos = avio_tell(f);
  154. uint32_t size = avio_rb32(f);
  155. struct Track *track = NULL;
  156. if (avio_rb32(f) != MKBETAG('t', 'f', 'r', 'a'))
  157. goto fail;
  158. version = avio_r8(f);
  159. avio_rb24(f);
  160. track_id = avio_rb32(f); /* track id */
  161. for (i = start_index; i < tracks->nb_tracks && !track; i++)
  162. if (tracks->tracks[i]->track_id == track_id)
  163. track = tracks->tracks[i];
  164. if (!track) {
  165. /* Ok, continue parsing the next atom */
  166. ret = 0;
  167. goto fail;
  168. }
  169. fieldlength = avio_rb32(f);
  170. track->chunks = avio_rb32(f);
  171. track->offsets = av_mallocz_array(track->chunks, sizeof(*track->offsets));
  172. if (!track->offsets) {
  173. ret = AVERROR(ENOMEM);
  174. goto fail;
  175. }
  176. for (i = 0; i < track->chunks; i++) {
  177. if (version == 1) {
  178. track->offsets[i].time = avio_rb64(f);
  179. track->offsets[i].offset = avio_rb64(f);
  180. } else {
  181. track->offsets[i].time = avio_rb32(f);
  182. track->offsets[i].offset = avio_rb32(f);
  183. }
  184. for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++)
  185. avio_r8(f);
  186. for (j = 0; j < ((fieldlength >> 2) & 3) + 1; j++)
  187. avio_r8(f);
  188. for (j = 0; j < ((fieldlength >> 0) & 3) + 1; j++)
  189. avio_r8(f);
  190. if (i > 0)
  191. track->offsets[i - 1].duration = track->offsets[i].time -
  192. track->offsets[i - 1].time;
  193. }
  194. if (track->chunks > 0)
  195. track->offsets[track->chunks - 1].duration = track->duration -
  196. track->offsets[track->chunks - 1].time;
  197. ret = 0;
  198. fail:
  199. avio_seek(f, pos + size, SEEK_SET);
  200. return ret;
  201. }
  202. static int read_mfra(struct Tracks *tracks, int start_index,
  203. const char *file, int split, const char *output_prefix)
  204. {
  205. int err = 0;
  206. const char* err_str = "";
  207. AVIOContext *f = NULL;
  208. int32_t mfra_size;
  209. if ((err = avio_open2(&f, file, AVIO_FLAG_READ, NULL, NULL)) < 0)
  210. goto fail;
  211. avio_seek(f, avio_size(f) - 4, SEEK_SET);
  212. mfra_size = avio_rb32(f);
  213. avio_seek(f, -mfra_size, SEEK_CUR);
  214. if (avio_rb32(f) != mfra_size) {
  215. err = AVERROR_INVALIDDATA;
  216. err_str = "mfra size mismatch";
  217. goto fail;
  218. }
  219. if (avio_rb32(f) != MKBETAG('m', 'f', 'r', 'a')) {
  220. err = AVERROR_INVALIDDATA;
  221. err_str = "mfra tag mismatch";
  222. goto fail;
  223. }
  224. while (!read_tfra(tracks, start_index, f)) {
  225. /* Empty */
  226. }
  227. if (split)
  228. err = write_fragments(tracks, start_index, f, output_prefix);
  229. fail:
  230. if (f)
  231. avio_close(f);
  232. if (err)
  233. fprintf(stderr, "Unable to read the MFRA atom in %s (%s)\n", file, err_str);
  234. return err;
  235. }
  236. static int get_private_data(struct Track *track, AVCodecContext *codec)
  237. {
  238. track->codec_private_size = codec->extradata_size;
  239. track->codec_private = av_mallocz(codec->extradata_size);
  240. if (!track->codec_private)
  241. return AVERROR(ENOMEM);
  242. memcpy(track->codec_private, codec->extradata, codec->extradata_size);
  243. return 0;
  244. }
  245. static int get_video_private_data(struct Track *track, AVCodecContext *codec)
  246. {
  247. AVIOContext *io = NULL;
  248. uint16_t sps_size, pps_size;
  249. int err;
  250. if (codec->codec_id == AV_CODEC_ID_VC1)
  251. return get_private_data(track, codec);
  252. if ((err = avio_open_dyn_buf(&io)) < 0)
  253. goto fail;
  254. err = AVERROR(EINVAL);
  255. if (codec->extradata_size < 11 || codec->extradata[0] != 1)
  256. goto fail;
  257. sps_size = AV_RB16(&codec->extradata[6]);
  258. if (11 + sps_size > codec->extradata_size)
  259. goto fail;
  260. avio_wb32(io, 0x00000001);
  261. avio_write(io, &codec->extradata[8], sps_size);
  262. pps_size = AV_RB16(&codec->extradata[9 + sps_size]);
  263. if (11 + sps_size + pps_size > codec->extradata_size)
  264. goto fail;
  265. avio_wb32(io, 0x00000001);
  266. avio_write(io, &codec->extradata[11 + sps_size], pps_size);
  267. err = 0;
  268. fail:
  269. track->codec_private_size = avio_close_dyn_buf(io, &track->codec_private);
  270. return err;
  271. }
  272. static int handle_file(struct Tracks *tracks, const char *file, int split,
  273. const char *output_prefix)
  274. {
  275. AVFormatContext *ctx = NULL;
  276. int err = 0, i, orig_tracks = tracks->nb_tracks;
  277. char errbuf[50], *ptr;
  278. struct Track *track;
  279. err = avformat_open_input(&ctx, file, NULL, NULL);
  280. if (err < 0) {
  281. av_strerror(err, errbuf, sizeof(errbuf));
  282. fprintf(stderr, "Unable to open %s: %s\n", file, errbuf);
  283. return 1;
  284. }
  285. err = avformat_find_stream_info(ctx, NULL);
  286. if (err < 0) {
  287. av_strerror(err, errbuf, sizeof(errbuf));
  288. fprintf(stderr, "Unable to identify %s: %s\n", file, errbuf);
  289. goto fail;
  290. }
  291. if (ctx->nb_streams < 1) {
  292. fprintf(stderr, "No streams found in %s\n", file);
  293. goto fail;
  294. }
  295. for (i = 0; i < ctx->nb_streams; i++) {
  296. struct Track **temp;
  297. AVStream *st = ctx->streams[i];
  298. if (st->codec->bit_rate == 0) {
  299. fprintf(stderr, "Skipping track %d in %s as it has zero bitrate\n", i, file);
  300. continue;
  301. }
  302. track = av_mallocz(sizeof(*track));
  303. if (!track) {
  304. err = AVERROR(ENOMEM);
  305. goto fail;
  306. }
  307. temp = av_realloc(tracks->tracks,
  308. sizeof(*tracks->tracks) * (tracks->nb_tracks + 1));
  309. if (!temp) {
  310. av_free(track);
  311. err = AVERROR(ENOMEM);
  312. goto fail;
  313. }
  314. tracks->tracks = temp;
  315. tracks->tracks[tracks->nb_tracks] = track;
  316. track->name = file;
  317. if ((ptr = strrchr(file, '/')))
  318. track->name = ptr + 1;
  319. track->bitrate = st->codec->bit_rate;
  320. track->track_id = st->id;
  321. track->timescale = st->time_base.den;
  322. track->duration = st->duration;
  323. track->is_audio = st->codec->codec_type == AVMEDIA_TYPE_AUDIO;
  324. track->is_video = st->codec->codec_type == AVMEDIA_TYPE_VIDEO;
  325. if (!track->is_audio && !track->is_video) {
  326. fprintf(stderr,
  327. "Track %d in %s is neither video nor audio, skipping\n",
  328. track->track_id, file);
  329. av_freep(&tracks->tracks[tracks->nb_tracks]);
  330. continue;
  331. }
  332. tracks->duration = FFMAX(tracks->duration,
  333. av_rescale_rnd(track->duration, AV_TIME_BASE,
  334. track->timescale, AV_ROUND_UP));
  335. if (track->is_audio) {
  336. if (tracks->audio_track < 0)
  337. tracks->audio_track = tracks->nb_tracks;
  338. tracks->nb_audio_tracks++;
  339. track->channels = st->codec->channels;
  340. track->sample_rate = st->codec->sample_rate;
  341. if (st->codec->codec_id == AV_CODEC_ID_AAC) {
  342. track->fourcc = "AACL";
  343. track->tag = 255;
  344. track->blocksize = 4;
  345. } else if (st->codec->codec_id == AV_CODEC_ID_WMAPRO) {
  346. track->fourcc = "WMAP";
  347. track->tag = st->codec->codec_tag;
  348. track->blocksize = st->codec->block_align;
  349. }
  350. get_private_data(track, st->codec);
  351. }
  352. if (track->is_video) {
  353. if (tracks->video_track < 0)
  354. tracks->video_track = tracks->nb_tracks;
  355. tracks->nb_video_tracks++;
  356. track->width = st->codec->width;
  357. track->height = st->codec->height;
  358. if (st->codec->codec_id == AV_CODEC_ID_H264)
  359. track->fourcc = "H264";
  360. else if (st->codec->codec_id == AV_CODEC_ID_VC1)
  361. track->fourcc = "WVC1";
  362. get_video_private_data(track, st->codec);
  363. }
  364. tracks->nb_tracks++;
  365. }
  366. avformat_close_input(&ctx);
  367. err = read_mfra(tracks, orig_tracks, file, split, output_prefix);
  368. fail:
  369. if (ctx)
  370. avformat_close_input(&ctx);
  371. return err;
  372. }
  373. static void output_server_manifest(struct Tracks *tracks, const char *basename,
  374. const char *output_prefix,
  375. const char *path_prefix,
  376. const char *ismc_prefix)
  377. {
  378. char filename[1000];
  379. FILE *out;
  380. int i;
  381. snprintf(filename, sizeof(filename), "%s%s.ism", output_prefix, basename);
  382. out = fopen(filename, "w");
  383. if (!out) {
  384. perror(filename);
  385. return;
  386. }
  387. fprintf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
  388. fprintf(out, "<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
  389. fprintf(out, "\t<head>\n");
  390. fprintf(out, "\t\t<meta name=\"clientManifestRelativePath\" "
  391. "content=\"%s%s.ismc\" />\n", ismc_prefix, basename);
  392. fprintf(out, "\t</head>\n");
  393. fprintf(out, "\t<body>\n");
  394. fprintf(out, "\t\t<switch>\n");
  395. for (i = 0; i < tracks->nb_tracks; i++) {
  396. struct Track *track = tracks->tracks[i];
  397. const char *type = track->is_video ? "video" : "audio";
  398. fprintf(out, "\t\t\t<%s src=\"%s%s\" systemBitrate=\"%d\">\n",
  399. type, path_prefix, track->name, track->bitrate);
  400. fprintf(out, "\t\t\t\t<param name=\"trackID\" value=\"%d\" "
  401. "valueType=\"data\" />\n", track->track_id);
  402. fprintf(out, "\t\t\t</%s>\n", type);
  403. }
  404. fprintf(out, "\t\t</switch>\n");
  405. fprintf(out, "\t</body>\n");
  406. fprintf(out, "</smil>\n");
  407. fclose(out);
  408. }
  409. static void print_track_chunks(FILE *out, struct Tracks *tracks, int main,
  410. const char *type)
  411. {
  412. int i, j;
  413. struct Track *track = tracks->tracks[main];
  414. int should_print_time_mismatch = 1;
  415. for (i = 0; i < track->chunks; i++) {
  416. for (j = main + 1; j < tracks->nb_tracks; j++) {
  417. if (tracks->tracks[j]->is_audio == track->is_audio) {
  418. if (track->offsets[i].duration != tracks->tracks[j]->offsets[i].duration) {
  419. fprintf(stderr, "Mismatched duration of %s chunk %d in %s (%d) and %s (%d)\n",
  420. type, i, track->name, main, tracks->tracks[j]->name, j);
  421. should_print_time_mismatch = 1;
  422. }
  423. if (track->offsets[i].time != tracks->tracks[j]->offsets[i].time) {
  424. if (should_print_time_mismatch)
  425. fprintf(stderr, "Mismatched (start) time of %s chunk %d in %s (%d) and %s (%d)\n",
  426. type, i, track->name, main, tracks->tracks[j]->name, j);
  427. should_print_time_mismatch = 0;
  428. }
  429. }
  430. }
  431. fprintf(out, "\t\t<c n=\"%d\" d=\"%"PRId64"\" />\n",
  432. i, track->offsets[i].duration);
  433. }
  434. }
  435. static void output_client_manifest(struct Tracks *tracks, const char *basename,
  436. const char *output_prefix, int split)
  437. {
  438. char filename[1000];
  439. FILE *out;
  440. int i, j;
  441. if (split)
  442. snprintf(filename, sizeof(filename), "%sManifest", output_prefix);
  443. else
  444. snprintf(filename, sizeof(filename), "%s%s.ismc", output_prefix, basename);
  445. out = fopen(filename, "w");
  446. if (!out) {
  447. perror(filename);
  448. return;
  449. }
  450. fprintf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
  451. fprintf(out, "<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" "
  452. "Duration=\"%"PRId64 "\">\n", tracks->duration * 10);
  453. if (tracks->video_track >= 0) {
  454. struct Track *track = tracks->tracks[tracks->video_track];
  455. struct Track *first_track = track;
  456. int index = 0;
  457. fprintf(out,
  458. "\t<StreamIndex Type=\"video\" QualityLevels=\"%d\" "
  459. "Chunks=\"%d\" "
  460. "Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n",
  461. tracks->nb_video_tracks, track->chunks);
  462. for (i = 0; i < tracks->nb_tracks; i++) {
  463. track = tracks->tracks[i];
  464. if (!track->is_video)
  465. continue;
  466. fprintf(out,
  467. "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
  468. "FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" "
  469. "CodecPrivateData=\"",
  470. index, track->bitrate, track->fourcc, track->width, track->height);
  471. for (j = 0; j < track->codec_private_size; j++)
  472. fprintf(out, "%02X", track->codec_private[j]);
  473. fprintf(out, "\" />\n");
  474. index++;
  475. if (track->chunks != first_track->chunks)
  476. fprintf(stderr, "Mismatched number of video chunks in %s (id: %d, chunks %d) and %s (id: %d, chunks %d)\n",
  477. track->name, track->track_id, track->chunks, first_track->name, first_track->track_id, first_track->chunks);
  478. }
  479. print_track_chunks(out, tracks, tracks->video_track, "video");
  480. fprintf(out, "\t</StreamIndex>\n");
  481. }
  482. if (tracks->audio_track >= 0) {
  483. struct Track *track = tracks->tracks[tracks->audio_track];
  484. struct Track *first_track = track;
  485. int index = 0;
  486. fprintf(out,
  487. "\t<StreamIndex Type=\"audio\" QualityLevels=\"%d\" "
  488. "Chunks=\"%d\" "
  489. "Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n",
  490. tracks->nb_audio_tracks, track->chunks);
  491. for (i = 0; i < tracks->nb_tracks; i++) {
  492. track = tracks->tracks[i];
  493. if (!track->is_audio)
  494. continue;
  495. fprintf(out,
  496. "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
  497. "FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" "
  498. "BitsPerSample=\"16\" PacketSize=\"%d\" "
  499. "AudioTag=\"%d\" CodecPrivateData=\"",
  500. index, track->bitrate, track->fourcc, track->sample_rate,
  501. track->channels, track->blocksize, track->tag);
  502. for (j = 0; j < track->codec_private_size; j++)
  503. fprintf(out, "%02X", track->codec_private[j]);
  504. fprintf(out, "\" />\n");
  505. index++;
  506. if (track->chunks != first_track->chunks)
  507. fprintf(stderr, "Mismatched number of audio chunks in %s and %s\n",
  508. track->name, first_track->name);
  509. }
  510. print_track_chunks(out, tracks, tracks->audio_track, "audio");
  511. fprintf(out, "\t</StreamIndex>\n");
  512. }
  513. fprintf(out, "</SmoothStreamingMedia>\n");
  514. fclose(out);
  515. }
  516. static void clean_tracks(struct Tracks *tracks)
  517. {
  518. int i;
  519. for (i = 0; i < tracks->nb_tracks; i++) {
  520. av_freep(&tracks->tracks[i]->codec_private);
  521. av_freep(&tracks->tracks[i]->offsets);
  522. av_freep(&tracks->tracks[i]);
  523. }
  524. av_freep(&tracks->tracks);
  525. tracks->nb_tracks = 0;
  526. }
  527. int main(int argc, char **argv)
  528. {
  529. const char *basename = NULL;
  530. const char *path_prefix = "", *ismc_prefix = "";
  531. const char *output_prefix = "";
  532. char output_prefix_buf[2048];
  533. int split = 0, i;
  534. struct Tracks tracks = { 0, .video_track = -1, .audio_track = -1 };
  535. av_register_all();
  536. for (i = 1; i < argc; i++) {
  537. if (!strcmp(argv[i], "-n")) {
  538. basename = argv[i + 1];
  539. i++;
  540. } else if (!strcmp(argv[i], "-path-prefix")) {
  541. path_prefix = argv[i + 1];
  542. i++;
  543. } else if (!strcmp(argv[i], "-ismc-prefix")) {
  544. ismc_prefix = argv[i + 1];
  545. i++;
  546. } else if (!strcmp(argv[i], "-output")) {
  547. output_prefix = argv[i + 1];
  548. i++;
  549. if (output_prefix[strlen(output_prefix) - 1] != '/') {
  550. snprintf(output_prefix_buf, sizeof(output_prefix_buf),
  551. "%s/", output_prefix);
  552. output_prefix = output_prefix_buf;
  553. }
  554. } else if (!strcmp(argv[i], "-split")) {
  555. split = 1;
  556. } else if (argv[i][0] == '-') {
  557. return usage(argv[0], 1);
  558. } else {
  559. if (handle_file(&tracks, argv[i], split, output_prefix))
  560. return 1;
  561. }
  562. }
  563. if (!tracks.nb_tracks || (!basename && !split))
  564. return usage(argv[0], 1);
  565. if (!split)
  566. output_server_manifest(&tracks, basename, output_prefix,
  567. path_prefix, ismc_prefix);
  568. output_client_manifest(&tracks, basename, output_prefix, split);
  569. clean_tracks(&tracks);
  570. return 0;
  571. }