mirror of
https://github.com/alfg/ffmpegd.git
synced 2025-12-24 13:17:53 +08:00
feat: check for ffmpeg + ffprobe version on startup
This commit is contained in:
27
README.md
27
README.md
@@ -1,19 +1,26 @@
|
||||
# `ffmpegd`
|
||||
An FFmpeg server with a websocket API for [FFmpeg Commander](https://github.com/alfg/ffmpeg-commander).
|
||||
|
||||
The goal is to provide a simple interface for sending FFmpeg jobs from the browser (and other supported clients in the future) while reporting realtime progress details.
|
||||
[FFmpeg](https://www.ffmpeg.org/) websocket server and API for [FFmpeg Commander](https://alfg.github.io/ffmpeg-commander).
|
||||
|
||||
**Currently a work-in-progress! Bugs and breaking changes are expected.*
|
||||
|
||||
## How It Works
|
||||
TODO
|
||||
`ffmpegd` connects [FFmpeg Commander](https://alfg.github.io/ffmpeg-commander) to [ffmpeg](https://www.ffmpeg.org/) by providing a websocket server to send encode tasks and receive realtime progress updates back to the browser. This allows using `ffmpeg-commander` as a GUI for `ffmpeg`.
|
||||
|
||||
The goal is to provide a simple interface for sending FFmpeg tasks from the browser (and other supported clients in the future) to your local machine.
|
||||
|
||||
See [Usage](#Usage) for more details.
|
||||
|
||||
```
|
||||
process websocket
|
||||
[ffmpeg] <-------> [ffmpegd] <-----------> [ffmpeg-commander]
|
||||
```
|
||||
|
||||
## Install
|
||||
```
|
||||
$ go get -u github.com/alfg/ffmpegd
|
||||
```
|
||||
|
||||
Release binaries coming soon.
|
||||
Docker, Homebrew, and release binaries coming soon.
|
||||
|
||||
## Usage
|
||||
* [ffmpeg](https://www.ffmpeg.org/download.html) must be installed and available on your `$PATH`.
|
||||
@@ -43,15 +50,19 @@ $ ffmpegd
|
||||
|
||||
[ffmpegd] - websocket server for ffmpeg-commander.
|
||||
|
||||
Server started on port :8080.
|
||||
Go to https://alfg.github.io/ffmpeg-commander to connect!
|
||||
Checking FFmpeg version....4.3.1
|
||||
Checking FFprobe version...4.3.1
|
||||
|
||||
Server started on port :8080.
|
||||
- Go to https://alfg.github.io/ffmpeg-commander to connect!
|
||||
- ffmpegd must be enabled in ffmpeg-commander options!
|
||||
|
||||
Encoding... 6111 / 17620 (34.68%) 3.37x @ 80.77
|
||||
```
|
||||

|
||||
|
||||
## API
|
||||
TODO
|
||||
TBD
|
||||
|
||||
## TODO
|
||||
* Support all `ffmpeg-comamnder` JSON options.
|
||||
|
||||
13
ffmpeg.go
13
ffmpeg.go
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -155,9 +156,15 @@ func (f *FFmpeg) Cancel() {
|
||||
}
|
||||
|
||||
// Version gets the ffmpeg version.
|
||||
func (f *FFmpeg) Version() string {
|
||||
out, _ := exec.Command(ffmpegCmd, "-version").Output()
|
||||
return string(out)
|
||||
func (f *FFmpeg) Version() (string, error) {
|
||||
out, err := exec.Command(ffmpegCmd, "-version").Output()
|
||||
if err != nil {
|
||||
return "", errors.New("ffmpeg not available on $PATH")
|
||||
}
|
||||
str := strings.Split(string(out), "\n")
|
||||
r, _ := regexp.Compile(`(\d+(\.\d+){2})`)
|
||||
version := r.FindString(str[0])
|
||||
return version, nil
|
||||
}
|
||||
|
||||
func (f *FFmpeg) updateProgress(stdout io.ReadCloser) {
|
||||
|
||||
13
ffprobe.go
13
ffprobe.go
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -38,6 +39,18 @@ func (f FFProbe) Run(input string) (*FFProbeResponse, error) {
|
||||
return dat, nil
|
||||
}
|
||||
|
||||
// Version gets the ffprobe version.
|
||||
func (f *FFProbe) Version() (string, error) {
|
||||
out, err := exec.Command(ffprobeCmd, "-version").Output()
|
||||
if err != nil {
|
||||
return "", errors.New("ffprobe not available on $PATH")
|
||||
}
|
||||
str := strings.Split(string(out), "\n")
|
||||
r, _ := regexp.Compile(`(\d+(\.\d+){2})`)
|
||||
version := r.FindString(str[0])
|
||||
return version, nil
|
||||
}
|
||||
|
||||
// FFProbeResponse defines the response from ffprobe.
|
||||
type FFProbeResponse struct {
|
||||
Streams []stream `json:"streams"`
|
||||
|
||||
28
main.go
28
main.go
@@ -38,6 +38,7 @@ var (
|
||||
return true
|
||||
},
|
||||
}
|
||||
progressCh chan struct{}
|
||||
)
|
||||
|
||||
// Message payload from client.
|
||||
@@ -56,12 +57,18 @@ type Status struct {
|
||||
Err string `json:"err"`
|
||||
}
|
||||
|
||||
var progressCh chan struct{}
|
||||
|
||||
func main() {
|
||||
// CLI Banner.
|
||||
printBanner()
|
||||
|
||||
// Check if FFmpeg/FFprobe are available.
|
||||
err := verifyFFmpeg()
|
||||
if err != nil {
|
||||
fmt.Println("\u001b[31m" + err.Error() + "\u001b[0m")
|
||||
fmt.Println("\u001b[31mPlease ensure FFmpeg and FFprobe are installed and available on $PATH.\u001b[0m")
|
||||
return
|
||||
}
|
||||
|
||||
// HTTP/WS Server.
|
||||
startServer()
|
||||
}
|
||||
@@ -123,6 +130,23 @@ func handleMessages() {
|
||||
}
|
||||
}
|
||||
|
||||
func verifyFFmpeg() error {
|
||||
ffmpeg := &FFmpeg{}
|
||||
version, err := ffmpeg.Version()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(" Checking FFmpeg version....\u001b[32m" + version + "\u001b[0m")
|
||||
|
||||
ffprobe := &FFProbe{}
|
||||
version, err = ffprobe.Version()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(" Checking FFprobe version...\u001b[32m" + version + "\u001b[0m\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
func runEncode(input, output, payload string) {
|
||||
probe := FFProbe{}
|
||||
probeData, err := probe.Run(input)
|
||||
|
||||
Reference in New Issue
Block a user