[FFmpeg-user] Error raised in oggenc.c when trying to create opus file from RTP stream

Jonathan Baudanza jon at jonb.org
Thu Oct 29 08:09:40 EET 2020

I am trying to write the contents of an RTC-OPUS stream to an OGG-OPUS file, ideally without doing any transcoding. The purpose is to send a WebRTC session to Google's Speech-to-text API, which accepts OGG-OPUS as input. 

The problem I'm having is that the opus muxer raises an error: "No extradata present". If I change the container format to webm instead of ogg, everything works fine. Google's API won't accept webm though.

I dug into oggenc.c in libavformat a bit, and it seems like it is expecting extradata to contain an opus header. I should have everything I need to construct a valid opus header. Is there some commandline or configuration that would help me do this? Any help would be appreciated.

I'm including my configuration and outputs below:


    o=- 0 0 IN IP4
    c=IN IP4
    t=0 0
    m=audio 5004 RTP/AVPF 100
    a=rtpmap:100 opus/48000/2

Command line:

    # Fails with "No extradata present" error
    ffmpeg \
         -nostdin \
         -protocol_whitelist file,rtp,udp \
         -i ./input.sdp \
         -codec copy \
         -y output.opus

    # Successfully writes output.webm from RTP stream
    ffmpeg \
         -nostdin \
         -protocol_whitelist file,rtp,udp \
         -i ./input.sdp \
         -codec copy \
         -y output.webm

Output from ffmpeg:

ffmpeg version 4.3.1-tessus  https://evermeet.cx/ffmpeg/  Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.17)
  configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, sdp, from './input.sdp':
    title           : Mediasoup
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp
[opus @ 0x7fe590008e00] No extradata present
Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
    Last message repeated 1 times

More information about the ffmpeg-user mailing list