This project provides a gRPC-based service for executing FFmpeg commands. It consists of a server that processes FFmpeg commands and a client that sends commands to the server. The server is designed to be secure and configurable, with options for SSL and token-based authentication.
.
├── proto
│ └── ffmpeg.proto # Protobuf definition file
├── server
│ └── grpc-ffmpeg.py # Server script
├── client
│ └── grpc-ffmpeg.py # Client script
│ └── Dockerfile # Dockerfile for building and running the client
├── Dockerfile # Dockerfile for building and running the server
├── README.md # Project documentation
└── requirements.txt # Python dependencies
- Python 3.6+
- Docker
Shared tmp directories between the client and worker containers (for jellyfin this would be the cache directory)
git clone https://github.com/CrystalNET-org/grpc-ffmpeg.git
cd grpc-ffmpeg
pip install -r requirements.txt
python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. proto/ffmpeg.proto
python server/grpc-ffmpeg.py
Build the Docker image:
docker build -t grpc-ffmpeg-service .
Run the Docker container:
docker run -p 50051:50051 -p 8080:8080 grpc-ffmpeg-service
python client/grpc-ffmpeg.py <ffmpeg_command>
The following environment variables can be set to configure the server and client:
VALID_TOKEN
: The authentication token for the gRPC server (default:my_secret_token
).ALLOWED_BINARIES
: The binaries allowed to be executed (default:['ffmpeg', 'ffprobe', 'vainfo']
).BINARY_PATH_PREFIX
: The path prefix for the binaries (default:/usr/bin/
).SSL_KEY_PATH
: The path to the SSL key file (default:server.key
).SSL_CERT_PATH
: The path to the SSL certificate file (default:server.crt
).USE_SSL
: Whether to use SSL (default:false
).GRPC_HOST
: The hostname for the gRPC client to connect to (default:ffmpeg-workers
).GRPC_PORT
: The port for the gRPC client to connect to (default:50051
).CERTIFICATE_PATH
: The path to the SSL certificate for the client (default:server.crt
).AUTH_TOKEN
: The authentication token for the client (default:my_secret_token1
).
Start the server with SSL:
export USE_SSL=true
export SSL_KEY_PATH=/path/to/server.key
export SSL_CERT_PATH=/path/to/server.crt
export VALID_TOKEN=my_secret_token1
python server/grpc-ffmpeg.py
Send a command to the server with SSL:
export USE_SSL=true
export CERTIFICATE_PATH=/path/to/server.crt
export AUTH_TOKEN=my_secret_token1
python client/grpc-ffmpeg.py "ffmpeg -i input.mp4 output.mp4"
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.