2 * Copyright (c) 2008 Luca Abeni
4 * This is free software; see GPL.txt
6 #include <libavformat/avformat.h>
9 AVFormatContext *open_output_stream(const char *dst, int port, enum CodecType codec_type, int fps)
12 static AVOutputFormat *rtp_format;
15 s = av_alloc_format_context();
16 rtp_format = guess_format("rtp", NULL, NULL);
18 fprintf(stderr, "Unable for find the RTP format for output\n");
23 s->oformat = rtp_format;
24 st = av_new_stream(s, 0);
26 fprintf(stderr, "Cannot allocate stream\n");
31 snprintf(s->filename, sizeof(s->filename), "rtp://%s:%d", dst, port);
33 /* open the UDP sockets for RTP and RTCP */
34 if (url_fopen(&s->pb, s->filename, URL_WRONLY) < 0) {
35 fprintf(stderr, "Cannot open '%s'\n", s->filename);
36 /* FIXME: Free the stream! */
40 avcodec_get_context_defaults2(s->streams[0]->codec, codec_type);
41 s->streams[0]->codec->codec_id = av_guess_codec(s->oformat, NULL, s->filename, NULL, codec_type);
42 s->streams[0]->codec->codec_id = CODEC_ID_MPEG4;
43 s->streams[0]->codec->pix_fmt = PIX_FMT_YUV420P;
44 s->streams[0]->codec->mb_decision = 2;
45 s->streams[0]->codec->me_cmp = 2;
46 /* s->streams[0]->codec->time_base.den = fps; */
47 /* s->streams[0]->codec->time_base.num = 1; */
48 /* st->codec->time_base.den = fps; */
49 /* st->codec->time_base.num = 1; */
50 //s->streams[0]->codec->me_sub_cmp = 6;
51 s->streams[0]->codec->trellis = 1;
56 int close_output_stream(AVFormatContext *s)
62 int pkt_send(AVFormatContext *ctx, AVPacket *pkt)
64 static int inited; /* FIXME: HACK! */
70 fprintf(stderr,"initing!\n");
71 res = av_write_header(ctx);
73 fprintf(stderr, "Cannot open the out RTP stream!\n");
80 return av_write_frame(ctx, pkt);