[FFmpeg-devel] [PATCH] sdp: optional 'vbr' parameter for Speex RTP payload

Dmitry Samonenko shreddingwork at gmail.com
Sat Oct 13 17:36:59 CEST 2012

On Wed, Oct 10, 2012 at 02:22:35PM +0400, Dmitry Samonenko wrote:
> On Tue, Oct 09, 2012 at 10:50:33PM +0200, Michael Niedermayer wrote:
> > I dont think this will work with stream copy, that is for example
> > something like:
> > 
> > ffmpeg -i test.mov -acodec copy -f rtp rtp://
> > the mov file here would contain a speex stream
> > 
> Yeah, I understand this too now.
> Well, I guess in that case each avformat supporting speex should be
> made capable (if it can be) to spot vbr operation mode.
> As for your example concerning mov, I made some research: stsd atom
> doesn't have a place for a such flag (vbr operation). But QuickTime
> file generated by ffmpeg contains glbl atom with full speex header
> (vbr field is present). I haven't found anything about if it's a
> regular behavior among QuickTime muxers or not.
> In fact, I haven't found anything about glbl atom at all.
> So, I think I look into Xiph OGG format then, which AFAIK should
> contain full speex header, get some ideas about which AVCodecContext
> fields should be used to signal speex vbr operation mode and decide
> later how to act in case of `non-speex-friendly' input format is used
> for stream copy.

I've looked into ogg format with speex and it actually looks ugly (on the
matter of vbr detection).
It looks like libspeex is no longer respects speex header structure: the most 
fresh release: 1.2rc1 (made 4 years ago) initialises vbr field with 0 and
leaves it like that regardless of operation mode and doc [1]. A large 
header on speex.org and the time of the last release suggests that it
won't be fixed.

It occurs to me, that these two formats supporting speex (QuickTime,
Ogg) are incapable of distinguishing vbr and cbr payloads. Actually, I
think that was made on a purpose, 'cause speex decoder can process data
without this info.

I don't know if there is a media format, which supports speex and has
info on it's payload type, but I've decided to update my patch a little.
Now optional vbr parameter will be outputted only in case codec properties
are known for a fact - when data is being encoded and encoder parameters
are set.

[1] http://www.speex.org/docs/api/speex-api-reference/group__SpeexHeader.html
-------------- next part --------------
>From b35a53594bb96f0f5badad97c96c08217a1f1ba0 Mon Sep 17 00:00:00 2001
From: Dmitry Samonenko <shreddingwork at gmail.com>
Date: Sat, 13 Oct 2012 19:03:33 +0400
Subject: [PATCH 1/1] sdp: output speex optional vbr parameter

Optional sdp speex payload parameter is outputed only when
data is encoded. It's not printed in case of stream copy.
 libavformat/sdp.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/libavformat/sdp.c b/libavformat/sdp.c
index ca8c3df..c4edd78 100644
--- a/libavformat/sdp.c
+++ b/libavformat/sdp.c
@@ -575,6 +575,20 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c,
         case AV_CODEC_ID_SPEEX:
             av_strlcatf(buff, size, "a=rtpmap:%d speex/%d\r\n",
                                      payload_type, c->sample_rate);
+            if (c->codec) {
+                const char *mode;
+                uint64_t vad_option;
+                if (c->flags & CODEC_FLAG_QSCALE)
+                      mode = "on";
+                else if (!av_opt_get_int(c, "vad", AV_OPT_FLAG_ENCODING_PARAM, &vad_option) && vad_option)
+                      mode = "vad";
+                else
+                      mode = "off";
+                av_strlcatf(buff, size, "a=fmtp:%d vbr=%s\r\n",
+                                        payload_type, mode);
+            }
         case AV_CODEC_ID_OPUS:
             av_strlcatf(buff, size, "a=rtpmap:%d opus/48000\r\n",

More information about the ffmpeg-devel mailing list