From: Luca Date: Fri, 26 Dec 2008 14:56:12 +0000 (+0100) Subject: Make some parameters configurable X-Git-Url: https://rtime.felk.cvut.cz/gitweb/frescor/streamer.git/commitdiff_plain/ccabc27ccafdf80e57c5d97baf67d4ad37100a82?ds=sidebyside Make some parameters configurable --- diff --git a/input.c b/input.c index 02a8b20..11e6027 100644 --- a/input.c +++ b/input.c @@ -30,7 +30,7 @@ static void time_base_convert(AVPacket *pkt, AVStream *st) } } -AVFormatContext *open_input_stream(const char *fname) +AVFormatContext *open_input_stream(const char *fname, int w, int h, int fps) { AVFormatContext *s; AVInputFormat *fmt; @@ -39,10 +39,10 @@ AVFormatContext *open_input_stream(const char *fname) memset(¶m, 0, sizeof(AVFormatParameters)); /* FIXME: Set these!!! */ - param.width = 352; - param.height = 288; + param.width = w; + param.height = h; param.pix_fmt = PIX_FMT_YUV420P; - param.time_base.den = 25; + param.time_base.den = fps; param.time_base.num = 1; fmt = av_find_input_format("video4linux2"); res = av_open_input_file(&s, fname, fmt, 0, ¶m); diff --git a/input.h b/input.h index 7fa7b9c..6a80683 100644 --- a/input.h +++ b/input.h @@ -1,3 +1,3 @@ -AVFormatContext *open_input_stream(const char *fname); +AVFormatContext *open_input_stream(const char *fname, int w, int h, int fps); void close_input_stream(AVFormatContext *s); AVPacket *read_input_packet(AVFormatContext *s); diff --git a/streamer.c b/streamer.c index 2774a7a..38e46b9 100644 --- a/streamer.c +++ b/streamer.c @@ -1,3 +1,6 @@ +#include +#include + #include "libavformat/avformat.h" #include "libavdevice/avdevice.h" @@ -6,6 +9,13 @@ #include "codec.h" #include "rt.h" +static const char *vdev = "/dev/video0"; +static const char *dst = "224.10.20.30"; +static int dport = 20000; +static int width = 352; +static int height = 288; +static int fps = 25; + static void sdp_print(AVFormatContext *s) { char sdp[2048]; @@ -17,6 +27,35 @@ static void sdp_print(AVFormatContext *s) fclose(f); } +static int args_parse(int argc, char *argv[]) +{ + int v; + + while ((v = getopt(argc, argv, "w:h:r:d:")) >= 0) { + switch (v) { + case 'w': + width = atoi(optarg); + break; + case 'h': + height = atoi(optarg); + break; + case 'r': + fps = atoi(optarg); + break; + case 'd': + vdev = optarg; + break; + case 'm': + dst = optarg; + break; + default: /* ’?’ */ + fprintf(stderr, "%s: illegal option %c\n", argv[0], v); + exit(-1); + } + } + + return 0; +} int main(int argc, char *argv[]) { @@ -27,14 +66,16 @@ int main(int argc, char *argv[]) av_register_all(); avdevice_register_all(); - s = open_input_stream(argv[1]); + args_parse(argc, argv); + + s = open_input_stream(vdev, width, height, fps); if (s == NULL) { - fprintf(stderr, "Cannot open input file %s\n", argv[1]); + fprintf(stderr, "Cannot open input file %s\n", vdev); return -1; } codec_open(s); - os = open_output_stream("224.10.20.30", 20000, CODEC_TYPE_VIDEO); + os = open_output_stream(dst, dport, CODEC_TYPE_VIDEO); if (os == NULL) { fprintf(stderr, "Cannot open output stream\n");