]> rtime.felk.cvut.cz Git - frescor/streamer.git/blob - streamer.c
2774a7a0344f40d4e85bb42d2c69653d190b4cab
[frescor/streamer.git] / streamer.c
1 #include "libavformat/avformat.h"
2 #include "libavdevice/avdevice.h"
3
4 #include "input.h"
5 #include "output.h"
6 #include "codec.h"
7 #include "rt.h"
8
9 static void sdp_print(AVFormatContext *s)
10 {
11     char sdp[2048];
12     FILE *f;
13
14     f = fopen("sdp.txt", "w");
15     avf_sdp_create(&s, 1, sdp, sizeof(sdp));
16     fprintf(f, "%s\n", sdp);
17     fclose(f);
18 }
19
20
21 int main(int argc, char *argv[])
22 {
23   AVFormatContext *s, *os;
24   int done;
25
26   avcodec_register_all();
27   av_register_all();
28   avdevice_register_all();
29
30   s = open_input_stream(argv[1]);
31   if (s == NULL) {
32     fprintf(stderr, "Cannot open input file %s\n", argv[1]);
33
34     return -1;
35   }
36   codec_open(s);
37   os = open_output_stream("224.10.20.30", 20000, CODEC_TYPE_VIDEO);
38   if (os == NULL) {
39     fprintf(stderr, "Cannot open output stream\n");
40
41     return -1;
42   }
43   os->streams[0]->codec->width = s->streams[0]->codec->width;
44   os->streams[0]->codec->height = s->streams[0]->codec->height;
45   os->streams[0]->codec->time_base = s->streams[0]->codec->time_base;
46   codec_connect(s->streams[0]->codec, os->streams[0]->codec);
47   out_codec_open(os);
48   dump_format(os, 0, os->filename, 1);
49   sdp_print(os);
50   done = 0;
51   while (!done) {
52     AVPacket *pkt;
53     pkt = read_input_packet(s);
54     if (pkt == NULL) {
55       done = 1;
56     } else {
57       AVFrame *f;
58       AVPacket *opkt;
59
60       pkt->pts += s->streams[pkt->stream_index]->start_time;
61       rt_job_start(pkt->pts);
62       f = pkt_decode(s, pkt);
63       if (f) {
64         opkt = pkt_encode(os, f);
65         if (opkt) {
66           pkt_send(os, opkt);
67         }
68       }
69       rt_job_end();
70       av_free_packet(pkt);
71     }
72   }
73
74   return 0;
75 }
76