savonet / liquidsoap

Liquidsoap is a statically typed scripting general-purpose language with dedicated operators and backend for all thing media, streaming, file generation, automation, HTTP backend and more.
http://liquidsoap.info
GNU General Public License v2.0
1.41k stars 130 forks source link

ffmpeg.encode.audio error with mono #2602

Closed cdgraff closed 2 years ago

cdgraff commented 2 years ago

Hi, I’m moving from standard mp3 transcoding to ffmpeg way… to avoid duplicate the process for recording and live. My input is MONO, and I’m getting this error:

[clock.ffmpeg.encode.audio.producer_0.child:4] Source ffmpeg.encode.audio.consumer_0 failed while streaming: Avutil.Error(Swresample failed to convert 1 channels : 2 channels were expected)!

here my code:

fm = "LUARADIO_DEBUG=1 luaradio rtlsdr_wbfm_mono.lua #{dial}e6 #{device_id} #{rf_gain}"

    live = input.external.rawaudio(channels=1,restart_on_error=false,restart=false,fm)
    live = blank.detect(restartapp, live)

    # Encode it in mp3:
    source = ffmpeg.encode.audio(
      %ffmpeg(%audio(codec="libmp3lame",b="64k", samplerate=44100, channels=1)),
      live)

    # Icecast source, with its own clock:
    icecast_source = buffer(source) 
    clock.assign_new(id="icecast", [icecast_source])

    # Output the full stream MP3
    output.icecast(%ffmpeg(format="mp3", %audio.copy),
        fallible=true,
        host="#{icecast_host}",
        port=int_of_string(icecast_port),
        password="#{icecast_pwd}",
        mount="#{device_uuid}-#{service_name}",
        description="#{icecast_desc}",
        on_start={log("Mediainbox - Starting Remote Streaming Host: #{icecast_host} Stream: #{device_uuid}-#{service_name}")},
        on_stop={log("Mediainbox - Stoping Remote Streaming Host: #{icecast_host} Stream: #{device_uuid}-#{service_name}")},
        icecast_source)

    # Dump the stream
    output.file(%ffmpeg(format="mp3", %audio.copy),
        fallible=true,
        on_stop=restartapp,
        filename,reopen_when={0m or 5m or 10m or 15m or 20m or 25m or 30m or 35m or 40m or 45m or 50m or 55m},source)
end 
toots commented 2 years ago

Thanks for reporting! This is fixed in main in https://github.com/savonet/liquidsoap/commit/79aeb3a55a25a29e9d7cba5e90cb3360716b2352 and in rolling-release-v2.1.x in https://github.com/savonet/liquidsoap/commit/25d7a6d91793994f1c9b2501cb783561abd1326c