Hi Miguel,

Miguel Miranda. wrote:
[...]
> I wanted to send a video using UDP in a peer to peer
> application. 
> In my understanding in order to be able to send a
> video through UDP I requiere the RTP protocol.
This is not really needed: you can chose if you want
to use standard RTP, but you can also send audio and
video over raw UDP.
I do not know which solution is better in a P2P application,
but I suppose standard RTP is not ok when peers have not
enough upload bandwidth for sending the whole stream.

[...]
> So I tried to follow the advice and I wrote the next
> code in the next application:
> 
>     ctx = av_alloc_format_context();
>     if (!ctx) {
>       printf("I couldn't allocated the format
> context\n");
>       return;
>     }
> 
>     if( url_open(&h, "udp://127.0.0.1:6000",
> URL_WRONLY) < 0 ) {
>       printf("Something wrong with url_open\n");
>       if (h)
>       url_close(h);
>       av_free(ctx);
>       return;
>     }

There seems to be some missing code here (for example,
you do not set the output format, and it is not
clear what your "h" variable is...).

Anyway, I generally use something like this (error checks and
some useless code removed for the sake of simplicity):
static AVFormatContext *prepare_output(const char *dst, int port, int type)
{
     AVFormatContext *s;
     static AVOutputFormat *rtp_format;
     AVStream *st;
     AVCodecContext *c;

     s = av_alloc_format_context();
     rtp_format = guess_format("rtp", NULL, NULL);
     s->oformat = rtp_format;
     st = av_new_stream(s, 0);
     c = st->codec;
     avcodec_get_context_defaults2(c, type);
     /* Set codec parameters... */
     snprintf(s->filename, sizeof(s->filename), "rtp://%s:%d", dst, port);
     url_fopen(&s->pb, s->filename, URL_WRONLY) < 0);
     return s;
}

> The problem is that the application breaks always on
> the url_open function.

I do not know what you mean by "the application breaks": does
it crash? Or is url_open() simply failing?
Anyway, you can try writing your own application that writes to
a file, using output_example.c as a template. Then, change the
output file name to "udp://..." (or change it to "rtp://...",
and change the output format to rtp) and it should work.


                                Luca

_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to