dockerffmpegfluent-ffmpeg

ffmpeg exited with code 1: Input/output error


On my backend Node server, I am trying to read a stream from an online radio station, and save the audio as a file in my computer. As streams don't have start/end, I'm choosing to record an arbitrary value of 5 seconds.

For this problem, I'm using the fluent-ffmpeg npm package for ffmpeg wrapper. Also, the @ffmpeg-installer/ffmpeg npm package to point to the directory of my local ffmpeg binary. As stream input, I'm reading from 89 FM - A Rádio Rock, a radio from São Paulo, BR, with the stream available at http://26593.live.streamtheworld.com/RADIO_89FMAAC.aac

Here is the code I put together:

import ffmpeg from "fluent-ffmpeg"
import ffmpegInstaller from "@ffmpeg-installer/ffmpeg"
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
console.log(ffmpegInstaller.path)
console.log(ffmpegInstaller.url)
console.log(ffmpegInstaller.version)

const pathInput = "http://26593.live.streamtheworld.com/RADIO_89FMAAC.aac"
// const pathInput = "./tmp/demo.avi"
const pathOutput = "./tmp/output.m4a"

ffmpeg()
  .input(pathInput)
  .duration(5)
  .save(pathOutput)
  .on("start", function(command) {
    console.log("Spawned Ffmpeg with command: " + command)
  })
  .on("error", function (err) {
    console.log("An error occurred: " + err.message)
  })
  .on("end", async function () {
    console.log("Processing finished!")
  })

On my local machine (Mac, running darwin-x64), the program outputs OK:

/.../node_modules/@ffmpeg-installer/darwin-x64/ffmpeg
https://evermeet.cx/ffmpeg/
92718-g092cb17983
Spawned Ffmpeg with command: ffmpeg -i http://26593.live.streamtheworld.com/RADIO_89FMAAC.aac -y -t 5 ./tmp/record.m4a
Processing finished!

On my docker container (linux-x64), which I need to deploy the project, the ffmpeg returns an error:

/usr/app/node_modules/@ffmpeg-installer/linux-x64/ffmpeg
https://www.johnvansickle.com/ffmpeg/
20181210-g0e8eb07980
Spawned Ffmpeg with command: ffmpeg -i http://26593.live.streamtheworld.com/RADIO_89FMAAC.aac -y -t 5 ./tmp/output.m4a
main-1  | An error occurred: ffmpeg exited with code 1: http://26593.live.streamtheworld.com/RADIO_89FMAAC.aac: Input/output error

Dockerfile for the container:

FROM node:alpine

WORKDIR /usr/app

COPY package*.json ./

# Install ffmpeg in the container:
RUN apk update
RUN apk add ffmpeg

RUN npm install

COPY . .

CMD [ "npm", "run", "dev" ]

Obs: this error seems to happen only for stream -> file save. When using as input a path from a local .avi file (thus, converting from .avi to .m4a), both localhost and docker versions run OK.

Has anyone has any clue as to why this error happens on this version? Or how I can run a ffmpeg command, server-side, on a docker container, to record a radio stream?


Solution

  • I found when creating a container to run FFmpeg for creating thumbnails and samples from videos that the Alpine version of FFmpeg had "missing features" (different or less compilation options) that seem to be available for the Mac build and other Linux distros.

    I ended up using debian:bookworm-slim as the base image, however the FFmpeg version is a bit older, you can use Deb multimedia version for 6.0.1 with something like this:

    FROM debian:bookworm-slim
    RUN apt-get update
    RUN apt-get install -y ca-certificates curl gnupg lsb-release
    RUN lsbRelease=`lsb_release -c -s` && echo "deb https://www.deb-multimedia.org $lsbRelease main non-free" | tee /etc/apt/sources.list.d/deb-multimedia.list
    RUN curl https://www.deb-multimedia.org/pool/main/d/deb-multimedia-keyring/deb-multimedia-keyring_2016.8.1_all.deb --output deb-multimedia-keyring_2016.8.1_all.deb
    RUN dpkg -i deb-multimedia-keyring_2016.8.1_all.deb
    RUN rm deb-multimedia-keyring_2016.8.1_all.deb
    RUN apt-get update
    RUN apt-get install -y ffmpeg
    

    Or the latest Ubuntu image has the latest version of FFmpeg, but I haven't got round to testing this fully yet.

    Of course my use case is completely different, so no guarantees this will work, but it may be a similar problem.