Commit f920d089 authored by Martin Storsjö's avatar Martin Storsjö
Browse files

ismindex: Add an option for outputting files elsewhere than in the current directory


Signed-off-by: default avatarMartin Storsjö <martin@martin.st>
parent 6bc4934b
......@@ -34,6 +34,11 @@
* ismindex -split foo.ismv
* This step creates a file Manifest and directories QualityLevel(...),
* that can be read directly by a smooth streaming player.
*
* The -output dir option can be used to request that output files
* (both .ism/.ismc, or Manifest/QualityLevels* when splitting)
* should be written to this directory instead of in the current directory.
* (The directory itself isn't created if it doesn't already exist.)
*/
#include <stdio.h>
......@@ -47,7 +52,7 @@
static int usage(const char *argv0, int ret)
{
fprintf(stderr, "%s [-split] [-n basename] [-path-prefix prefix] "
"[-ismc-prefix prefix] file1 [file2] ...\n", argv0);
"[-ismc-prefix prefix] [-output dir] file1 [file2] ...\n", argv0);
return ret;
}
......@@ -122,15 +127,15 @@ static int write_fragment(const char *filename, AVIOContext *in)
}
static int write_fragments(struct Tracks *tracks, int start_index,
AVIOContext *in)
AVIOContext *in, const char *output_prefix)
{
char dirname[100], filename[500];
char dirname[2048], filename[2048];
int i, j;
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), "QualityLevels(%d)", track->bitrate);
snprintf(dirname, sizeof(dirname), "%sQualityLevels(%d)", output_prefix, track->bitrate);
mkdir(dirname, 0777);
for (j = 0; j < track->chunks; j++) {
snprintf(filename, sizeof(filename), "%s/Fragments(%s=%"PRId64")",
......@@ -199,7 +204,7 @@ fail:
}
static int read_mfra(struct Tracks *tracks, int start_index,
const char *file, int split)
const char *file, int split, const char *output_prefix)
{
int err = 0;
AVIOContext *f = NULL;
......@@ -223,7 +228,7 @@ static int read_mfra(struct Tracks *tracks, int start_index,
}
if (split)
write_fragments(tracks, start_index, f);
write_fragments(tracks, start_index, f, output_prefix);
fail:
if (f)
......@@ -272,7 +277,8 @@ fail:
return err;
}
static int handle_file(struct Tracks *tracks, const char *file, int split)
static int handle_file(struct Tracks *tracks, const char *file, int split,
const char *output_prefix)
{
AVFormatContext *ctx = NULL;
int err = 0, i, orig_tracks = tracks->nb_tracks;
......@@ -374,7 +380,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);
err = read_mfra(tracks, orig_tracks, file, split, output_prefix);
fail:
if (ctx)
......@@ -382,15 +388,16 @@ fail:
return err;
}
static void output_server_manifest(struct Tracks *tracks,
const char *basename, const char *path_prefix,
static void output_server_manifest(struct Tracks *tracks, const char *basename,
const char *output_prefix,
const char *path_prefix,
const char *ismc_prefix)
{
char filename[1000];
FILE *out;
int i;
snprintf(filename, sizeof(filename), "%s.ism", basename);
snprintf(filename, sizeof(filename), "%s%s.ism", output_prefix, basename);
out = fopen(filename, "w");
if (!out) {
perror(filename);
......@@ -436,17 +443,17 @@ static void print_track_chunks(FILE *out, struct Tracks *tracks, int main,
}
}
static void output_client_manifest(struct Tracks *tracks,
const char *basename, int split)
static void output_client_manifest(struct Tracks *tracks, const char *basename,
const char *output_prefix, int split)
{
char filename[1000];
FILE *out;
int i, j;
if (split)
snprintf(filename, sizeof(filename), "Manifest");
snprintf(filename, sizeof(filename), "%sManifest", output_prefix);
else
snprintf(filename, sizeof(filename), "%s.ismc", basename);
snprintf(filename, sizeof(filename), "%s%s.ismc", output_prefix, basename);
out = fopen(filename, "w");
if (!out) {
perror(filename);
......@@ -535,6 +542,8 @@ int main(int argc, char **argv)
{
const char *basename = NULL;
const char *path_prefix = "", *ismc_prefix = "";
const char *output_prefix = "";
char output_prefix_buf[2048];
int split = 0, i;
struct Tracks tracks = { 0, .video_track = -1, .audio_track = -1 };
......@@ -550,12 +559,20 @@ int main(int argc, char **argv)
} else if (!strcmp(argv[i], "-ismc-prefix")) {
ismc_prefix = argv[i + 1];
i++;
} else if (!strcmp(argv[i], "-output")) {
output_prefix = argv[i + 1];
i++;
if (output_prefix[strlen(output_prefix) - 1] != '/') {
snprintf(output_prefix_buf, sizeof(output_prefix_buf),
"%s/", output_prefix);
output_prefix = output_prefix_buf;
}
} else if (!strcmp(argv[i], "-split")) {
split = 1;
} else if (argv[i][0] == '-') {
return usage(argv[0], 1);
} else {
if (handle_file(&tracks, argv[i], split))
if (handle_file(&tracks, argv[i], split, output_prefix))
return 1;
}
}
......@@ -563,8 +580,9 @@ int main(int argc, char **argv)
return usage(argv[0], 1);
if (!split)
output_server_manifest(&tracks, basename, path_prefix, ismc_prefix);
output_client_manifest(&tracks, basename, split);
output_server_manifest(&tracks, basename, output_prefix,
path_prefix, ismc_prefix);
output_client_manifest(&tracks, basename, output_prefix, split);
clean_tracks(&tracks);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment