Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#8436 closed defect (invalid)

ffmpeg sets opus audio to stereo in SDP even though it is mono

Reported by: rudolfs.bundulis Owned by:
Priority: minor Component: undetermined
Version: unspecified Keywords: opus sdp
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

ffmpeg sets a=rtpmap:98 opus/48000/2 indicating a stereo track
in RTSP SDP when the source is actually mono.

How to reproduce:

The input file has been attached (Big buck bunny with a mono audio track that has silence).

% fmpeg -i mono_opus_sample.mp4 -c:v h264 -c:a opus -strict -2 -rtsp_transport tcp -f rtsp rtsp://localhost:554/app/live

ffmpeg version 4.2.1
built on macOS 10.15

Here is the output from ffmpeg with -loglevel panic, which shows the invalid SDP:

[rtsp @ 0x7fb9ea805800] SDP:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 58.29.100
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QADazZQUH7DhAAAAMAEAAAAwPA8UKZYA==,aOvjyyLA; profile-level-id=64000D
a=control:streamid=0
m=audio 0 RTP/AVP 97
b=AS:48
a=rtpmap:97 opus/48000/2 # This track should be mono
a=control:streamid=1

If not forcing opus (and defaulting to aac), the entry seems correct:

ffmpeg -i mono_opus_sample.mp4 -c:v h264  -rtsp_transport tcp -f rtsp rtsp://localhost:554/app/live

The SDP then is:

[rtsp @ 0x7fd58c013800] SDP:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 58.29.100
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QADazZQUH7DhAAAAMAEAAAAwPA8UKZYA==,aOvjyyLA; profile-level-id=64000D
a=control:streamid=0
m=audio 0 RTP/AVP 97
b=AS:69
a=rtpmap:97 MPEG4-GENERIC/48000/1 # Mono, as it should be
a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=118856E500
a=control:streamid=1

Attachments (1)

mono_opus_sample.mp4 (27.1 KB ) - added by rudolfs.bundulis 4 years ago.
Big buck bunny with a silent opus mono audio track

Download all attachments as: .zip

Change History (9)

by rudolfs.bundulis, 4 years ago

Attachment: mono_opus_sample.mp4 added

Big buck bunny with a silent opus mono audio track

comment:1 by rudolfs.bundulis, 4 years ago

Version: unspecified4.2

comment:2 by Carl Eugen Hoyos, 4 years ago

Version: 4.2unspecified

Is the issue reproducible with current FFmpeg git head?
Please provide the command line you tested together with the complete, uncut console output to make this a valid ticket.

comment:3 by rudolfs.bundulis, 4 years ago

Ok, I'll retest with git head and provide feedback as well as the full output (I pasted the rtsp output since it perfectly showed the issue, but I'll provide the full output from git head).

comment:4 by rudolfs.bundulis, 4 years ago

./ffmpeg -i /Users/rudolfs/Downloads/mono_opus_sample.mp4 -c:v h264 -c:a opus -strict -2 -rtsp_transport tcp -f rtsp rtsp://localhost:554/app/live -loglevel verbose
ffmpeg version N-96159-gb0d0d7e4d0 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.16)
  configuration: --prefix=/usr/local --enable-gpl --enable-libx264 --enable-libopus
  libavutil      56. 37.100 / 56. 37.100
  libavcodec     58. 65.100 / 58. 65.100
  libavformat    58. 35.101 / 58. 35.101
  libavdevice    58.  9.101 / 58.  9.101
  libavfilter     7. 69.101 /  7. 69.101
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Routing option strict to both codec and muxer layer
[h264 @ 0x7feb79002c00] Reinit context to 320x240, pix_fmt: yuv420p
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/rudolfs/Downloads/mono_opus_sample.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:02.07, start: 0.000000, bitrate: 107 kb/s
    Stream #0:0(und): Audio: opus (Opus / 0x7375704F), 48000 Hz, mono, fltp, delay 120, 48 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:1(und): Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p(left), 320x240 [SAR 4:3 DAR 16:9], 48 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : GPAC ISO Video Handler
Matched encoder 'libx264' for codec 'h264'.
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (opus (native) -> opus (native))
Press [q] to stop, [?] for help
[h264 @ 0x7feb78829a00] Reinit context to 320x240, pix_fmt: yuv420p
[graph_1_in_0_0 @ 0x7feb76d089c0] tb:1/48000 samplefmt:fltp samplerate:48000 chlayout:0x4
[graph 0 input from stream 0:1 @ 0x7feb76d0f7c0] w:320 h:240 pixfmt:yuv420p tb:1/15360 fr:30/1 sar:4/3 sws_param:flags=2
[libx264 @ 0x7feb78815e00] using SAR=4/3
[libx264 @ 0x7feb78815e00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7feb78815e00] profile High, level 1.3
[libx264 @ 0x7feb78815e00] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=7 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[tcp @ 0x7feb76d13780] Starting connection attempt to 127.0.0.1 port 554
[tcp @ 0x7feb76d13780] Successfully connected to 127.0.0.1 port 554
[rtsp @ 0x7feb78817a00] SDP:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 58.35.101
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QADazZQUH7DhAAAAMAEAAAAwPA8UKZYA==,aOvjyyLA; profile-level-id=64000D
a=control:streamid=0
m=audio 0 RTP/AVP 97
b=AS:48
a=rtpmap:97 opus/48000/2
a=control:streamid=1

Output #0, rtsp, to 'rtsp://localhost:554/app/live':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.35.101
    Stream #0:0(und): Video: h264 (libx264), 1 reference frame, yuv420p(left), 320x240 [SAR 4:3 DAR 16:9], q=-1--1, 30 fps, 90k tbn, 30 tbc (default)
    Metadata:
      handler_name    : GPAC ISO Video Handler
      encoder         : Lavc58.65.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
    Stream #0:1(und): Audio: opus, 48000 Hz, mono, fltp, delay 120, 48 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc58.65.100 opus
No more output streams to write to, finishing.
frame=   62 fps=0.0 q=-1.0 Lsize=N/A time=00:00:02.00 bitrate=N/A speed=22.9x    
video:12kB audio:12kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Input file #0 (/Users/rudolfs/Downloads/mono_opus_sample.mp4):
  Input stream #0:0 (audio): 101 packets read (12221 bytes); 101 frames decoded (96840 samples); 
  Input stream #0:1 (video): 62 packets read (12460 bytes); 62 frames decoded; 
  Total: 163 packets (24681 bytes) demuxed
Output file #0 (rtsp://localhost:554/app/live):
  Output stream #0:0 (video): 62 frames encoded; 62 packets muxed (11900 bytes); 
  Output stream #0:1 (audio): 807 frames encoded (96840 samples); 101 packets muxed (12221 bytes); 
  Total: 163 packets (24121 bytes) muxed
[libx264 @ 0x7feb78815e00] frame I:1     Avg QP: 3.56  size:    65
[libx264 @ 0x7feb78815e00] frame P:26    Avg QP:20.19  size:   371
[libx264 @ 0x7feb78815e00] frame B:35    Avg QP:17.63  size:    43
[libx264 @ 0x7feb78815e00] consecutive B-frames: 16.1% 22.6%  9.7% 51.6%
[libx264 @ 0x7feb78815e00] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 0x7feb78815e00] mb P  I16..4:  3.1%  0.1%  1.0%  P16..4:  2.3%  1.0%  1.1%  0.0%  0.0%    skip:91.4%
[libx264 @ 0x7feb78815e00] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.5%  0.3%  0.3%  direct: 0.2%  skip:98.7%  L0:47.0% L1:47.4% BI: 5.6%
[libx264 @ 0x7feb78815e00] 8x8 transform intra:0.6% inter:29.8%
[libx264 @ 0x7feb78815e00] coded y,uvDC,uvAC intra: 8.7% 14.2% 13.0% inter: 0.9% 1.7% 1.1%
[libx264 @ 0x7feb78815e00] i16 v,h,dc,p: 92%  1%  7%  0%
[libx264 @ 0x7feb78815e00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu:  0%  6% 38% 12%  0% 25%  6% 12%  0%
[libx264 @ 0x7feb78815e00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 50% 21% 12%  3%  3%  5%  2%  2%  2%
[libx264 @ 0x7feb78815e00] i8c dc,h,v,p: 88%  4%  8%  1%
[libx264 @ 0x7feb78815e00] Weighted P-Frames: Y:15.4% UV:11.5%
[libx264 @ 0x7feb78815e00] ref P L0: 83.1%  4.8%  6.9%  5.1%
[libx264 @ 0x7feb78815e00] ref B L0: 80.1%  7.2% 12.8%
[libx264 @ 0x7feb78815e00] kb/s:43.40
[opus @ 0x7feb78818000] Average Intensity Stereo band: 21.0
[opus @ 0x7feb78818000] Dual Stereo used: 0.00%
[AVIOContext @ 0x7feb76e00840] Statistics: 27752 bytes read, 0 seeks

This is the output from git head, as you can see the issue is still present - the stream is listed as mono:

Stream #0:0(und): Audio: opus (Opus / 0x7375704F), 48000 Hz, mono, fltp, delay 120, 48 kb/s (default)

but advertised as stereo in sdp:

a=rtpmap:97 opus/48000/2

comment:5 by Carl Eugen Hoyos, 4 years ago

Did you see a05f5052fef3b3743fab7846da12861d8a8098ec?
Is the comment wrong?

in reply to:  5 comment:6 by rudolfs.bundulis, 4 years ago

Replying to cehoyos:

Did you see a05f5052fef3b3743fab7846da12861d8a8098ec?
Is the comment wrong?

Thanks for the link, I looked at the commit and then at https://tools.ietf.org/html/rfc7587 and yeah under paragraph 7 it has:

The media subtype ("opus") goes in SDP "a=rtpmap" as the encoding
      name.  The RTP clock rate in "a=rtpmap" MUST be 48000, and the
      number of channels MUST be 2.

so the comment is correct, will close the issue.

comment:7 by rudolfs.bundulis, 4 years ago

Resolution: invalid
Status: newclosed

comment:8 by Carl Eugen Hoyos, 4 years ago

Keywords: rtsp removed
Note: See TracTickets for help on using tickets.