From e403050c18212723acfc9ef4906bad63cd9b5349 Mon Sep 17 00:00:00 2001 From: Jonathan Rosser Date: Thu, 7 Aug 2008 10:06:39 +0100 Subject: [PATCH] add schro_decode option to write one file per output frame --- src/schro_decode.cpp | 66 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/src/schro_decode.cpp b/src/schro_decode.cpp index fd26081..41bcacf 100644 --- a/src/schro_decode.cpp +++ b/src/schro_decode.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -24,15 +25,14 @@ namespace po = boost::program_options; static std::string inFileName; static std::string outFileName; static bool verbose = false; +static bool split = false; /* function prototypes */ static bool parseCommandLine(int argc, char *argv[]); -static void decode(FILE*, FILE*); +static void decode(); int main(int argc, char **argv) { - FILE *inFile; - FILE *outFile; schro_init(); @@ -40,24 +40,8 @@ int main(int argc, char **argv) exit(1); } - /* open an input and output files */ - inFile = fopen(inFileName.c_str(), "rb"); - if(inFile == NULL) { - fprintf(stderr, "Could not open input file %s\n", inFileName.c_str()); - exit(1); - } - - outFile = fopen(outFileName.c_str(), "wb"); - if(outFile == NULL) { - fprintf(stderr, "Could not open output file %s\n", outFileName.c_str()); - exit(1); - } - - decode(inFile, outFile); + decode(); - if(verbose) printf("\nClosing files\n"); - fclose(inFile); - fclose(outFile); return 0; } @@ -72,6 +56,7 @@ bool parseCommandLine(int argc, char **argv) desc.add_options() ("help", " Show this message") ("verbose,v", " Enable verbose decoding") + ("split,s", " Split output into frames [put %d in filename]") ("input", po::value(&inFileName), "string Dirac bitstream to decode") ("output", po::value(&outFileName), "string YUV planar output file"); @@ -87,6 +72,7 @@ bool parseCommandLine(int argc, char **argv) //decode flags if(vm.count("verbose")) verbose=true; + if(vm.count("split")) split=true; if(vm.count("help")) { std::cout << "Usage : schro_decode [flags] input output" << std::endl; std::cout << desc << std::endl; @@ -117,18 +103,29 @@ buffer_free (SchroBuffer *buf, void *priv) } /* push the data through the decoder */ -static void decode(FILE *infile, FILE *outfile) +static void decode() { + FILE *infile; + FILE *outfile = NULL; + SchroDecoder *decoder; SchroBuffer *buffer; SchroVideoFormat *format = NULL; SchroFrame *frame; bool go; - int it; void *packet; int size=-1; + int it; int ret; int framecount=0; + char formatted_name[1024]; + + /* open an input and output files */ + infile = fopen(inFileName.c_str(), "rb"); + if(infile == NULL) { + fprintf(stderr, "Could not open input file %s\n", inFileName.c_str()); + exit(1); + } decoder = schro_decoder_new(); @@ -193,17 +190,33 @@ static void decode(FILE *infile, FILE *outfile) schro_decoder_add_output_picture (decoder, frame); break; case SCHRO_DECODER_OK: - frame = schro_decoder_pull (decoder); - if (frame) { + { + frame = schro_decoder_pull (decoder); + + if(split == true || outfile == NULL) { + snprintf(formatted_name, 64, outFileName.c_str(), framecount); + + outfile = fopen(formatted_name, "wb"); + if(outfile == NULL) { + fprintf(stderr, "Could not open output file %s\n", formatted_name); + exit(1); + } + } + if(verbose) { - printf("writing output frame %d\r", framecount++); + printf("writing output frame %d to %s\r", framecount, formatted_name); fflush(stdout); } + // write frame data out in planar format fwrite(frame->components[0].data, frame->components[0].length, 1, outfile); fwrite(frame->components[1].data, frame->components[1].length, 1, outfile); fwrite(frame->components[2].data, frame->components[2].length, 1, outfile); schro_frame_unref(frame); + + if(split) fclose(outfile); + + framecount++; } break; case SCHRO_DECODER_EOS: @@ -224,6 +237,9 @@ out: if(verbose) printf("\nFreeing decoder"); schro_decoder_free (decoder); free(format); + + fclose(infile); + fclose(outfile); } -- 2.11.4.GIT