From f6c52856cbf124e57f202ac33f6e74bab2a24161 Mon Sep 17 00:00:00 2001 From: Nathan Caldwell Date: Thu, 15 Jan 2009 23:30:57 -0700 Subject: [PATCH] More basics. --- frameshot.c | 92 +++++++++++++++++++++++++++++++++++++++++++++---------------- input/y4m.c | 1 + 2 files changed, 69 insertions(+), 24 deletions(-) diff --git a/frameshot.c b/frameshot.c index 190cacc..6d037f1 100644 --- a/frameshot.c +++ b/frameshot.c @@ -44,25 +44,50 @@ int (*p_close_infile)( hnd_t handle ); /* output file function pointers */ static int (*p_open_outfile)( char *psz_filename, hnd_t *p_handle, int i_compression ); -static int (*p_write_image)( hnd_t handle ); +// static int (*p_write_image)( hnd_t handle ); static int (*p_close_outfile)( hnd_t handle ); static int parse_options( int argc, char **argv, cli_opt_t *opt ); -static void show_help(void); +static int grab_frames( cli_opt_t *opt ); int main(int argc, char **argv) { cli_opt_t opt; - int fmt = 0; + int ret = 0; parse_options(argc, argv, &opt); - return 0; + ret = grab_frames( &opt ); + + return ret; +} + +static void show_help(void) +{ + #define HELP printf + HELP( "Syntax: frameshot [options] infile\n" + "\n" + "Infile is a raw bitstream of one of the following codecs:\n" + " YUV4MPEG\n" + "\n" + "Options:\n" + "\n" + " -h, --help Displays this message.\n" + ); + HELP( " -f, --frames Frames numbers to grab.\n" ); + HELP( " -o, --output Prefix to use for each output image.\n" ); + HELP( " -z, --compression Ammount of compression to use.\n" ); + HELP( " -1, --fast Use fastest compression.\n" ); + HELP( " -9, --best Use best (slowest) compression.\n" ); + HELP( "\n" ); } static int parse_options( int argc, char **argv, cli_opt_t *opt ) { + char *psz_filename = NULL; int i_zlevel = Z_DEFAULT_COMPRESSION; + char *psz; + int b_y4m = 0; memset( opt, 0, sizeof(*opt) ); @@ -75,15 +100,16 @@ static int parse_options( int argc, char **argv, cli_opt_t *opt ) int long_options_index = -1; static struct option long_options[] = { + { "fast", no_argument, NULL, '1' }, + { "best", no_argument, NULL, '9' }, + { "frames", required_argument, NULL, 'f' }, { "help", no_argument, NULL, 'h' }, { "output", required_argument, NULL, 'o' }, { "compression", required_argument, NULL, 'z' }, - { "best", no_argument, NULL, '9' }, - { "fast", no_argument, NULL, '1' }, {0, 0, 0, 0} }; - int c = getopt_long( argc, argv, "19ho:z:", + int c = getopt_long( argc, argv, "19f:ho:z:", long_options, &long_options_index); if( c == -1 ) @@ -99,6 +125,8 @@ static int parse_options( int argc, char **argv, cli_opt_t *opt ) case '9': i_zlevel = Z_BEST_COMPRESSION; break; + case 'f': + case 'o': break; case 'z': @@ -112,24 +140,40 @@ static int parse_options( int argc, char **argv, cli_opt_t *opt ) exit(0); } } + + /* Get the input file name */ + if( optind > argc - 1 ) + { + fprintf( stderr, "[error]: No input file.\n" ); + show_help(); + return -1; + } + psz_filename = argv[optind++]; + + psz = strrchr( psz_filename, '.' ); + if( !strncasecmp( psz, ".y4m", 4 ) ) + b_y4m = 1; + + if( b_y4m ) + { + p_open_infile = open_file_y4m; + p_read_frame = read_frame_y4m; + p_close_infile = close_file_y4m; + } + + if( p_open_infile( psz_filename, &opt->hin ) ) + { + fprintf( stderr, "ERROR: could not open input file '%s'\n", psz_filename ); + return -1; + } + + return 0; } -static void show_help(void) +static int grab_frames( cli_opt_t *opt ) { -#define HELP printf - HELP( "Syntax: frameshot [options] infile \n" - "\n" - "Infile is a raw bitstream of one of the following codecs:\n" - " YUV4MPEG\n" - "\n" - "Options:\n" - "\n" - " -h, --help Displays this message.\n" - ); - HELP( " -o, --output Prefix to use for each output image.\n" ); - HELP( " -z, --compression Ammount of compression to use.\n" ); - HELP( " -1, --fast Use fastest compression.\n" ); - HELP( " -9, --best Use best (slowest) compression.\n" ); - HELP( "\n" ); + + p_close_infile( opt->hin ); -} \ No newline at end of file + return 0; +} diff --git a/input/y4m.c b/input/y4m.c index 0145835..4948d89 100644 --- a/input/y4m.c +++ b/input/y4m.c @@ -1,3 +1,4 @@ +#include #include #include #include -- 2.11.4.GIT