2 * Copyright (c) 2008 Luca Abeni
4 * This is free software; see GPL.txt
9 #include <libavformat/avformat.h>
10 #include <libavdevice/avdevice.h>
11 #include <libswscale/swscale.h>
18 #include "streamer_config.h"
22 #include <ul_logreg.h>
25 #ifdef CONFIG_STREAMER_WITH_FRSH
29 extern long int udp_budget, udp_period;
31 static const char *sdp_file = "sdp.txt";
32 static const char *vdev = "/dev/video0";
33 static const char *dst = "127.0.0.1";
34 static int dport = 20000;
35 static int width = 352;
36 static int height = 288;
38 static const char *impform = "video4linux2";
40 static void sdp_print(AVFormatContext *s, const char *fname)
45 f = fopen(fname, "w");
46 avf_sdp_create(&s, 1, sdp, sizeof(sdp));
47 fprintf(f, "%s\n", sdp);
54 printf("usage: streamer [ options ]\n");
55 printf(" -w <number> send image width\n");
56 printf(" -h <number> send image height\n");
57 printf(" -r <number> refresh rate\n");
58 printf(" -r <path> video device [%s]\n", vdev);
59 printf(" -m <addr> destination IP address\n");
60 printf(" -i <string> input video device format [%s]\n", impform);
62 printf(" -l <number>|<domain>=<number>,...\n");
63 #endif /*CONFIG_OC_ULUT*/
66 static int args_parse(int argc, char *argv[])
70 while ((v = getopt(argc, argv, "w:h:r:d:m:i:l:")) >= 0) {
76 height = atoi(optarg);
89 if(!strcmp(impform, "v4l"))
90 impform = "video4linux";
91 else if(!strcmp(impform, "v4l2"))
92 impform = "video4linux2";
96 ul_log_domain_arg2levels(optarg);
98 #endif /*CONFIG_OC_ULUT*/
100 default: /* unknown option */
101 fprintf(stderr, "%s: illegal option %c\n", argv[0], v);
110 int main(int argc, char *argv[])
112 AVFormatContext *s, *os;
115 #ifdef CONFIG_STREAMER_WITH_FRSH
117 if (ret) PERROR_AND_EXIT(ret, "frsh_init1");
118 #endif /*CONFIG_STREAMER_WITH_FRSH*/
123 avcodec_register_all();
125 avdevice_register_all();
127 args_parse(argc, argv);
129 s = open_input_stream(vdev, width, height, fps, impform);
131 fprintf(stderr, "Cannot open input file %s\n", vdev);
136 os = open_output_stream(dst, dport, CODEC_TYPE_VIDEO);
138 fprintf(stderr, "Cannot open output stream\n");
142 os->streams[0]->codec->width = s->streams[0]->codec->width;
143 os->streams[0]->codec->height = s->streams[0]->codec->height;
144 os->streams[0]->codec->time_base = s->streams[0]->codec->time_base;
145 codec_connect(s->streams[0]->codec, os->streams[0]->codec);
147 dump_format(os, 0, os->filename, 1);
148 sdp_print(os, sdp_file);
152 pkt = read_input_packet(s);
159 pkt->pts += s->streams[pkt->stream_index]->start_time;
160 //rt_job_start(pkt->pts);
161 f = pkt_decode(s, pkt);
163 opkt = pkt_encode(os, f);