Merge commit 'f920d089535bf7cf10aeda900cc43201c5e18cd0'

* commit 'f920d089535bf7cf10aeda900cc43201c5e18cd0':
  ismindex: Add an option for outputting files elsewhere than in the current directory

Conflicts:
	tools/ismindex.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2014-07-03 21:02:56 +02:00
commit 524eeaca22

View File

@ -34,6 +34,11 @@
* ismindex -split foo.ismv * ismindex -split foo.ismv
* This step creates a file Manifest and directories QualityLevel(...), * This step creates a file Manifest and directories QualityLevel(...),
* that can be read directly by a smooth streaming player. * 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> #include <stdio.h>
@ -49,7 +54,7 @@
static int usage(const char *argv0, int ret) static int usage(const char *argv0, int ret)
{ {
fprintf(stderr, "%s [-split] [-n basename] [-path-prefix prefix] " 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; return ret;
} }
@ -124,15 +129,15 @@ static int write_fragment(const char *filename, AVIOContext *in)
} }
static int write_fragments(struct Tracks *tracks, int start_index, 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; int i, j;
for (i = start_index; i < tracks->nb_tracks; i++) { for (i = start_index; i < tracks->nb_tracks; i++) {
struct Track *track = tracks->tracks[i]; struct Track *track = tracks->tracks[i];
const char *type = track->is_video ? "video" : "audio"; 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);
if (mkdir(dirname, 0777) == -1) if (mkdir(dirname, 0777) == -1)
return AVERROR(errno); return AVERROR(errno);
for (j = 0; j < track->chunks; j++) { for (j = 0; j < track->chunks; j++) {
@ -202,7 +207,7 @@ fail:
} }
static int read_mfra(struct Tracks *tracks, int start_index, 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; int err = 0;
AVIOContext *f = NULL; AVIOContext *f = NULL;
@ -226,7 +231,7 @@ static int read_mfra(struct Tracks *tracks, int start_index,
} }
if (split) if (split)
err = write_fragments(tracks, start_index, f); err = write_fragments(tracks, start_index, f, output_prefix);
fail: fail:
if (f) if (f)
@ -278,7 +283,8 @@ fail:
return err; 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; AVFormatContext *ctx = NULL;
int err = 0, i, orig_tracks = tracks->nb_tracks; int err = 0, i, orig_tracks = tracks->nb_tracks;
@ -380,7 +386,7 @@ static int handle_file(struct Tracks *tracks, const char *file, int split)
avformat_close_input(&ctx); avformat_close_input(&ctx);
err = read_mfra(tracks, orig_tracks, file, split); err = read_mfra(tracks, orig_tracks, file, split, output_prefix);
fail: fail:
if (ctx) if (ctx)
@ -388,15 +394,16 @@ fail:
return err; return err;
} }
static void output_server_manifest(struct Tracks *tracks, static void output_server_manifest(struct Tracks *tracks, const char *basename,
const char *basename, const char *path_prefix, const char *output_prefix,
const char *path_prefix,
const char *ismc_prefix) const char *ismc_prefix)
{ {
char filename[1000]; char filename[1000];
FILE *out; FILE *out;
int i; int i;
snprintf(filename, sizeof(filename), "%s.ism", basename); snprintf(filename, sizeof(filename), "%s%s.ism", output_prefix, basename);
out = fopen(filename, "w"); out = fopen(filename, "w");
if (!out) { if (!out) {
perror(filename); perror(filename);
@ -442,17 +449,17 @@ static void print_track_chunks(FILE *out, struct Tracks *tracks, int main,
} }
} }
static void output_client_manifest(struct Tracks *tracks, static void output_client_manifest(struct Tracks *tracks, const char *basename,
const char *basename, int split) const char *output_prefix, int split)
{ {
char filename[1000]; char filename[1000];
FILE *out; FILE *out;
int i, j; int i, j;
if (split) if (split)
snprintf(filename, sizeof(filename), "Manifest"); snprintf(filename, sizeof(filename), "%sManifest", output_prefix);
else else
snprintf(filename, sizeof(filename), "%s.ismc", basename); snprintf(filename, sizeof(filename), "%s%s.ismc", output_prefix, basename);
out = fopen(filename, "w"); out = fopen(filename, "w");
if (!out) { if (!out) {
perror(filename); perror(filename);
@ -541,6 +548,8 @@ int main(int argc, char **argv)
{ {
const char *basename = NULL; const char *basename = NULL;
const char *path_prefix = "", *ismc_prefix = ""; const char *path_prefix = "", *ismc_prefix = "";
const char *output_prefix = "";
char output_prefix_buf[2048];
int split = 0, i; int split = 0, i;
struct Tracks tracks = { 0, .video_track = -1, .audio_track = -1 }; struct Tracks tracks = { 0, .video_track = -1, .audio_track = -1 };
@ -556,12 +565,20 @@ int main(int argc, char **argv)
} else if (!strcmp(argv[i], "-ismc-prefix")) { } else if (!strcmp(argv[i], "-ismc-prefix")) {
ismc_prefix = argv[i + 1]; ismc_prefix = argv[i + 1];
i++; 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")) { } else if (!strcmp(argv[i], "-split")) {
split = 1; split = 1;
} else if (argv[i][0] == '-') { } else if (argv[i][0] == '-') {
return usage(argv[0], 1); return usage(argv[0], 1);
} else { } else {
if (handle_file(&tracks, argv[i], split)) if (handle_file(&tracks, argv[i], split, output_prefix))
return 1; return 1;
} }
} }
@ -569,8 +586,9 @@ int main(int argc, char **argv)
return usage(argv[0], 1); return usage(argv[0], 1);
if (!split) if (!split)
output_server_manifest(&tracks, basename, path_prefix, ismc_prefix); output_server_manifest(&tracks, basename, output_prefix,
output_client_manifest(&tracks, basename, split); path_prefix, ismc_prefix);
output_client_manifest(&tracks, basename, output_prefix, split);
clean_tracks(&tracks); clean_tracks(&tracks);