ossrs / srs

SRS is a simple, high-efficiency, real-time video server supporting RTMP, WebRTC, HLS, HTTP-FLV, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
24.86k stars 5.29k forks source link

FLV: SRS 4.0 recognizes mono audio streams (AAC) as stereo. #3556

Open HunterTang opened 1 year ago

HunterTang commented 1 year ago

Description

  1. Application scenario

There is an older system with a Chrome kernel (compatible with XP) that can only recognize mono audio streams. A mono audio stream was pushed to SRS, and when using flv.js to play the FLV stream, it could not be played. The backend showed that it was recognized as stereo. Currently, this issue is temporarily resolved by using libmp3lame for transcoding.

  1. Actual testing

2.1 Transcoding test with FFMPEG Push to SRS after transcoding with FFMPEG (version 4.4), the ffmpeg command is as follows: ffmpeg -i rtmp://127.0.0.1/live/livestream -vn -ac 1 -ar 22050 -c:a libfdk_aac -f flv rtmp://IP/live/livestream

FFmpeg prints the following information:

libavutil      56. 70.100 / 56. 70.100
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libswscale      5.  9.100 /  5.  9.100
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100
...

Duration: 00:00:00.00, start: 3046.899000, bitrate: N/A
Stream #0:0: Audio: aac (LC), 44100 Hz, mono, fltp, 65 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (aac (native) -> aac (libfdk_aac))
...
Stream #0:0: Audio: aac ([10][0][0][0] / 0x000A), 22050 Hz, mono, s16, 48 kb/s
Metadata:
encoder         : Lavc58.134.100 libfdk_aac

Using ffprob to view the stream information, it correctly recognizes mono:

Duration: 00:00:00.00, start: 10.867000, bitrate: N/A
Stream #0:0: Audio: aac (LC), 22050 Hz, mono, fltp, 47 kb/s

The following stream information is received through the SRS backend web page:

Recv: 0.00Kbps
Send: 0.00Kbps
Audio: AAC/22050/Stereo/LC

2.2 Pushing mono stream directly with OBS Pushing a mono audio stream directly to SRS with OBS, the stream information in ffporb is as follows:

Duration: N/A, start: 0.000000, bitrate: 2625 kb/s
Stream #0:0: Data: none
Stream #0:1: Audio: aac (LC), 44100 Hz, mono, fltp, 65 kb/s
Stream #0:2: Video: h264 (Constrained Baseline), yuv420p(progressive), 1920x1080, 2560 kb/s, 30 fps, 30 tbr, 1k tbn

The following stream information is received through the SRS backend web page:

Recv: 0.00Kbps
Send: 0.00Kbps
Video: H264/Baseline/4/1920x1080
Audio: AAC/44100/Stereo/LC
  1. SRS version:

    v-4.0.268
    v-4.0.251
  2. SRS configuration file:

listen              1935;
max_connections     22000;
pid                 /mnt/srs/srs.pid;
srs_log_tank        file;
srs_log_file        /mnt/srs/log/srs.log;
daemon              on;
http_api {
    enabled         on;
    listen          1985;
}
http_server {
    enabled         on;
    listen          8080;
    dir             /usr/local/srs/objs/nginx/html;
}
rtc_server {
    enabled on;
    listen 8000; # UDP port
    candidate $CANDIDATE;
}
vhost __defaultVhost__ {
    hls {
        enabled         off;
    }
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
    rtc {
        enabled     on;
        rtmp_to_rtc on;
        rtc_to_rtmp on;
    }
    forward {
        enabled    off;
    }
}

Replay

Push a mono audio stream to SRS with OBS, and then view the received stream information on the SRS backend page. You can also preview and view the playback log in the console, which will show that the received audio stream is mp4a 40.5 instead of mp4a 40.2.

Expect

Correctly recognize mono audio streams.

winlinvip commented 1 year ago

When pushing an AAC mono stream, FFmpeg recognizes it as a mono stream, but SRS mistakenly recognizes it as a stereo stream. This seems to be an error in SRS, possibly related to metadata parsing, which causes flv.js to be unable to play the stream due to incorrect audio channel information.