2 * Copyright (c) 2008 Luca Abeni
4 * This is free software; see GPL.txt
6 #include <libavformat/avformat.h>
10 AVFormatContext *open_output_stream(const char *dst, int port, enum CodecType codec_type)
13 static AVOutputFormat *rtp_format;
16 s = av_alloc_format_context();
17 rtp_format = guess_format("rtp", NULL, NULL);
19 fprintf(stderr, "Unable for find the RTP format for output\n");
24 s->oformat = rtp_format;
25 st = av_new_stream(s, 0);
27 fprintf(stderr, "Cannot allocate stream\n");
32 snprintf(s->filename, sizeof(s->filename), "rtp://%s:%d", dst, port);
34 /* open the UDP sockets for RTP and RTCP */
35 if (url_fopen(&s->pb, s->filename, URL_WRONLY) < 0) {
36 fprintf(stderr, "Cannot open '%s'\n", s->filename);
37 /* FIXME: Free the stream! */
41 avcodec_get_context_defaults2(s->streams[0]->codec, codec_type);
42 s->streams[0]->codec->codec_id = av_guess_codec(s->oformat, NULL, s->filename, NULL, codec_type);
43 s->streams[0]->codec->codec_id = CODEC_ID_MPEG4;
44 s->streams[0]->codec->pix_fmt = PIX_FMT_YUV420P;
45 s->streams[0]->codec->mb_decision = 2;
46 s->streams[0]->codec->me_cmp = 2;
47 //s->streams[0]->codec->me_sub_cmp = 6;
48 s->streams[0]->codec->trellis = 1;
53 int close_output_stream(AVFormatContext *s)
59 int pkt_send(AVFormatContext *ctx, AVPacket *pkt)
61 static int inited; /* FIXME: HACK! */
67 fprintf(stderr,"initing!\n");
68 res = av_write_header(ctx);
70 fprintf(stderr, "Cannot open the out RTP stream!\n");
77 return av_write_frame(ctx, pkt);