This is a non-standard file that maps the MSS segment names to offsets
in the ISMV file. This can be used to build a custom MSS streaming
server without splitting the ISMV into separate files.
---
tools/ismindex.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 71 insertions(+), 13 deletions(-)
diff --git a/tools/ismindex.c b/tools/ismindex.c
index a6a9763..658249c 100644
--- a/tools/ismindex.c
+++ b/tools/ismindex.c
@@ -23,7 +23,9 @@
* avconv <normal input/transcoding options> -movflags frag_keyframe foo.ismv
* ismindex -n foo foo.ismv
* This step creates foo.ism and foo.ismc that is required by IIS for
- * serving it.
+ * serving it. It also creates foo.ismf, which maps fragment names to
+ * start-end offsets in the ismv, for use in your own streaming server
+ * (the .ismf file is not created if -split is given).
*
* By adding -path-prefix path/, the produced foo.ism will refer to the
* files foo.ismv as "path/foo.ismv" - the prefix for the generated ismc
@@ -118,6 +120,21 @@ static int copy_tag(AVIOContext *in, AVIOContext *out,
int32_t tag_name)
return 0;
}
+static int skip_tag(AVIOContext *in, int32_t tag_name)
+{
+ int64_t pos = avio_tell(in);
+ int32_t size, tag;
+
+ size = avio_rb32(in);
+ tag = avio_rb32(in);
+ if (tag != tag_name) {
+ fprintf(stderr, "wanted tag %d, got %d", tag_name, tag);
+ return -1;
+ }
+ avio_seek(in, pos + size, SEEK_SET);
+ return 0;
+}
+
static int write_fragment(const char *filename, AVIOContext *in)
{
AVIOContext *out = NULL;
@@ -139,25 +156,65 @@ static int write_fragment(const char *filename,
AVIOContext *in)
return ret;
}
+static int skip_fragment(AVIOContext *in)
+{
+ int ret;
+ ret = skip_tag(in, MKBETAG('m', 'o', 'o', 'f'));
+ if (!ret)
+ ret = skip_tag(in, MKBETAG('m', 'd', 'a', 't'));
+ return ret;
+}
+
static int write_fragments(struct Tracks *tracks, int start_index,
- AVIOContext *in, const char *output_prefix)
+ AVIOContext *in, const char *basename,
+ int split, const char* output_prefix)
{
- char dirname[2048], filename[2048];
- int i, j;
+ char dirname[2048], filename[2048], idxname[2048];
+ int i, j, ret, fragment_ret;
+ FILE* out;
+ out = NULL;
+ ret = 0;
+ if (!split) {
+ snprintf(idxname, sizeof(idxname), "%s%s.ismf", output_prefix,
basename);
+ out = fopen(idxname, "w");
+ if (!out) {
+ ret = AVERROR(errno);
+ perror(idxname);
+ goto fail;
+ }
+ }
for (i = start_index; i < tracks->nb_tracks; i++) {
struct Track *track = tracks->tracks[i];
const char *type = track->is_video ? "video" : "audio";
snprintf(dirname, sizeof(dirname), "%sQualityLevels(%d)",
output_prefix, track->bitrate);
- mkdir(dirname, 0777);
+ if (split) {
+ if (mkdir(dirname, 0777) == -1) {
+ ret = AVERROR(errno);
+ perror(dirname);
+ goto fail;
+ }
+ }
for (j = 0; j < track->chunks; j++) {
snprintf(filename, sizeof(filename), "%s/Fragments(%s=%"PRId64")",
dirname, type, track->offsets[j].time);
avio_seek(in, track->offsets[j].offset, SEEK_SET);
- write_fragment(filename, in);
+ if (split) {
+ fragment_ret = write_fragment(filename, in);
+ } else {
+ fprintf(out, "%s %"PRId64, filename, avio_tell(in));
+ fragment_ret = skip_fragment(in);
+ fprintf(out, " %"PRId64"\n", avio_tell(in));
+ }
+ if (fragment_ret != 0) {
+ fprintf(stderr, "failed fragment\n");
+ ret = fragment_ret;
+ }
}
}
- return 0;
+fail:
+ if (out) fclose(out);
+ return ret;
}
static int read_tfra(struct Tracks *tracks, int start_index, AVIOContext *f)
@@ -217,7 +274,8 @@ fail:
}
static int read_mfra(struct Tracks *tracks, int start_index,
- const char *file, int split, const char *output_prefix)
+ const char *file, int split, const char *basename,
+ const char* output_prefix)
{
int err = 0;
const char* err_str = "";
@@ -243,8 +301,8 @@ static int read_mfra(struct Tracks *tracks, int start_index,
/* Empty */
}
- if (split)
- write_fragments(tracks, start_index, f, output_prefix);
+ err = write_fragments(tracks, start_index, f, basename, split,
output_prefix);
+ err_str = "error in write_fragments";
fail:
if (f)
@@ -296,7 +354,7 @@ fail:
}
static int handle_file(struct Tracks *tracks, const char *file, int split,
- const char *output_prefix)
+ const char *basename, const char* output_prefix)
{
AVFormatContext *ctx = NULL;
int err = 0, i, orig_tracks = tracks->nb_tracks;
@@ -404,7 +462,7 @@ static int handle_file(struct Tracks *tracks, const char
*file, int split,
avformat_close_input(&ctx);
- err = read_mfra(tracks, orig_tracks, file, split, output_prefix);
+ err = read_mfra(tracks, orig_tracks, file, split, basename, output_prefix);
fail:
if (ctx)
@@ -607,7 +665,7 @@ int main(int argc, char **argv)
} else if (argv[i][0] == '-') {
return usage(argv[0], 1);
} else {
- if (handle_file(&tracks, argv[i], split, output_prefix))
+ if (handle_file(&tracks, argv[i], split, basename, output_prefix))
return 1;
}
}
--
1.8.5.2 (Apple Git-48)
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel