[Python] Stream Recorder Using FFmpeg Fails on AWS Lambda

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to stream audio from URLs and save them to a file in S3 using AWS Lambda with FFmpeg. Here is an example FFmpeg command I'm using:

    ffmpeg -hide_banner -loglevel error -t 10 -i http://playerservices.streamtheworld.com/api/livestream-redirect/KTOOFMAAC_SC -ar 16000 -b:a 64k -ac 2 output.mp3

    • The FFmpeg command is getting called in a python script using subprocess.Popen()
    • The command works as expected on local, but does not work in an AWS Lambda python environment using a custom FFMPEG layer configured with these instructions.
    • When run on Lambda, I get the following error: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/output.mp3'

    Note: I've also tried a version where I use python requests to stream chunks and pipe them into ffmpeg. This works for some stream URLs, but for others, such as the streamtheworld URL above, it only saves ~5 seconds of audio from the stream or results in a Broken Pipe error.

    Continue reading...

Compartilhe esta Página