[FFmpeg-devel] [RFC] SDP Generation

Luca Abeni lucabe72
Fri Jun 8 17:24:08 CEST 2007

Hi Michael,

thanks for the comments; I'll fix the code during the weekend.

Michael Niedermayer wrote:
>> There still are some open issues (look at the FIXME's), but I'd like to 
>> have some feedback to know if I am going in the right direction, and if 
>> the interface is ok.
> the interface does not look ok, it depends on a 1 stream per AVFormatContext
> i thought this multi AVFormatContext was only needed for obscure multicast
> cases noone would use in practice anyway, please elaborate on the
> problem ...
Well, the problem is that every single media stream can have a different 
destination address. If the "filename" field in AVFormatContext is used 
for indicating the destination address, then I need an AVFormatContext 
per media stream.

I am not happy with this solution (that's why I asked :), but I did not 
find anything better. And this is the solution currently used by ffmpeg too.
So, using this interface I can modify ffmpeg to generate an SDP file 
when streaming RTP by simply adding something like
sdp = avf_sdp_create(output_files, nb_output_files);
printf("%s", sdp);
in ffmpeg.c:av_encode(), before start streaming.

A different option would be to support both the "multiple 
AVFormatContext" (in which case each AVFormatContext must have only one 
stream) and the "single AVFormatContext" cases (in the second case, all 
the streams have the same destination address, and are inside the same 
AVFormatContext). I did not implement this to simplify the code, but 
maybe it's a better way to go?

>>     res = snprintf(p, size, "s=%s\r\n", s->name);
>>     if (res < 0) {
>>         return NULL;
>>     }
>>     p += res;
>>     size -= res;
> code quadruplification, also the attribute_write() is pretty much the 5th
> copy of this ...
> (and no a macro is not a solution, it still would have the code duplicated
> in the binary)
Ok, I'll try to come up with something smarter during the weekend.

> [...]
>> static char *data_to_hex(char *buff, const uint8_t *src, int s)
>> {
>>     char *p;
>>     int i;
>>     p = buff;
>>     for(i = 0; i < s; i++) {
>>         snprintf(p, 3, "%02x", src[i]);
>>         p += 2;
>>     }
>>     return p;
>> }
> p+buff is redundant
> whats the sense in snprintf() with fixed 3 here? it cant be longer anyway
I tried to use a simple sprintf(), but it is not allowed in  libavformat 
(I got the sprintf_is_forbidden_due_to_security_issues_use_snprintf thing).
Maybe it's better to rewrite this function without using sprintf or 


More information about the ffmpeg-devel mailing list