Search code examples
dockerffmpegdocker-swarm

How to pass custom parameters when creating docker swarm service?


I am new to docker and docker swarm and started dockerizing several services and am trying to get them running as docker swarm services. I ran into a road block with the linuxserver/ffmpeg image:

  1. it uses a --device parameter which is not implemented in create service
  2. it expects several custom parameters to pass them to the ffmpeg encoder

From my research up to now I assume that passing parameters is not implemented in docker create service, but maybe you can think of a workaround? (unfortunately the image does not process environment variables, or at least they are not documented)

This is how I start dockerized ffmpeg (working fine in standalone mode):

docker run -d /
--network="host" /
--device=/dev/video0:/dev/video0 / ### error: unknow flag
--name ffmpeg_streamer /
--restart always -it /
-v $(pwd)/video:/video /
linuxserver/ffmpeg / ### custom parameters below here
-stream_loop /
-1 -re -nostdin /
-i "/video/test.avi" /
-f pulse /
-vcodec libx264 /
-preset:v veryfast /
-b:v 400k /
-f flv rtmp://localhost:1935/live/streamkey

Many thanks for looking into this!


Solution

  • try this docker-compose file

    version: '3.3'
    
    services:
      ffmpeg_streamer:
        image: 'linuxserver/ffmpeg'
        restart: always
        devices:
          - "/dev/video0:/dev/video0" #make sure the folde /dev/video0 exist in your host
        command: ["-stream_loop", "-1", "-re", "-nostdin", "-i" ,"/video/test.avi", "-f", "pulse", "-vcodec", "libx264", "-preset:v", "veryfast", "-b:v", "400k", "-f", "flv", "rtmp://localhost:1935/live/streamkey"]
        network_mode: host
        volumes:
          - './video:/video'
    

    you can run it using this command: docker-compos up -d