MaartenBaert / ssr

SimpleScreenRecorder, a screen recorder for Linux
http://www.maartenbaert.be/simplescreenrecorder/
GNU General Public License v3.0
2.56k stars 289 forks source link

AAC: Unsupported channel layout "2 channels" #1040

Closed autogris closed 4 weeks ago

autogris commented 2 months ago

Hi, after upgrading ffmpeg to 7.0.2 from 6.x, SSR gives me the following error when trying to produce an mp4 with h264+aac:

[PageRecord::StartPage] Starting page ...
[PageRecord::StartPage] Started page.
[PageRecord::StartOutput] Starting output ...
[PageRecord::StartOutput] Output file: /tmp/video.mp4
[Muxer::Init] Using format mp4 (MP4 (MPEG-4 Part 14)).
[Muxer::AddStream] Using codec libx264 (libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10).
[VideoEncoder::PrepareStream] Using pixel format nv12.
[libx264 @ 0x27bed500] using SAR=1/1
[libx264 @ 0x27bed500] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x27bed500] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x27bed500] 264 - core 164 - H.264/MPEG-4 AVC codec - Copyleft 2003-2024 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x3 me=dia subme=1 psy=1 psy_rd=1,00:0,00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=8 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=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc=crf mbtree=0 crf=23,0 qcomp=0,60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1,40 pb_ratio=1,30 aq=1:1,00
[Muxer::AddStream] Using codec aac (AAC (Advanced Audio Coding)).
[BaseEncoder::EncoderThread] Encoder thread started.
[AudioEncoder::PrepareStream] Using sample format f32p.
[aac @ 0x27fcfa00] Unsupported channel layout "2 channels"
[aac @ 0x27fcfa00] Qavg: nan
[BaseEncoder::Init] Error: Can't open codec!
[BaseEncoder::~BaseEncoder] Stopping encoder thread ...
[BaseEncoder::EncoderThread] Encoder thread stopped.
[PageRecord::StartOutput] Error: Something went wrong during initialization.

I'm on the latest git commit (https://github.com/MaartenBaert/ssr/commit/4e3ba13dd212fc4213fe0911f371bc7d34033b8d)

ccady commented 2 months ago

I also get this error when I am using the AAC audio codec. I get what I presume is an identical error with the libmp3lame audio encoder.:

[Muxer::AddStream] Using codec libmp3lame (libmp3lame MP3 (MPEG audio layer 3)). [BaseEncoder::EncoderThread] Encoder thread started. [AudioEncoder::PrepareStream] Using sample format f32p. [libmp3lame @ 0x55ec6c612100] Specified channel layout '2 channels' is not supported by the libmp3lame encoder [libmp3lame @ 0x55ec6c612100] Supported channel layouts: [libmp3lame @ 0x55ec6c612100] mono [libmp3lame @ 0x55ec6c612100] stereo [BaseEncoder::Init] Error: Can't open codec! [BaseEncoder::~BaseEncoder] Stopping encoder thread ... [BaseEncoder::EncoderThread] Encoder thread stopped. [PageRecord::StartOutput] Error: Something went wrong during initialization.

I am using this version in Debian Linux, testing:

SimpleScreenRecorder 0.4.4 Compiled with GCC 14.2.0 Qt: header 5.15.13, lib 5.15.13 libavformat: header 61.1.100, lib 61.1.100 libavcodec: header 61.3.100, lib 61.3.100 libavutil: header 59.8.100, lib 59.8.100 libswscale: header 8.1.100, lib 8.1.100

flydiscohuebr commented 4 weeks ago

I replaced this part of the code in the else block with this other part present in the commit https://github.com/MaartenBaert/ssr/pull/1035 https://github.com/MaartenBaert/ssr/blob/4e3ba13dd212fc4213fe0911f371bc7d34033b8d/src/AV/Output/AudioEncoder.cpp#L117-L120 https://github.com/MaartenBaert/ssr/blob/f8988d9f8b48ddfb48079b1a7552c979cff6a912/src/AV/Output/AudioEncoder.cpp#L111-L115 In the end it looked something like this and it worked

#if LIBAVCODEC_VERSION_MAJOR < 61
    codec_context->channels = channels;
    codec_context->channel_layout = (channels == 1)? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
#else
    if(channels == 1) {
        av_channel_layout_from_mask(&codec_context->ch_layout, AV_CH_LAYOUT_MONO);
    } else {
        av_channel_layout_from_mask(&codec_context->ch_layout, AV_CH_LAYOUT_STEREO);
    }
#endif
autogris commented 4 weeks ago

Thanks, I've compiled with your patch and it works!