├── LICENSE ├── README.md ├── go.mod ├── go.sum ├── index.html ├── stats.min.js └── ws-relay.go /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 cs8425 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ffmpeg ws-relay 2 | This is a simple example show up how to streaming video from ffmpeg by broadcasting image frames via websocket. 3 | 4 | 5 | ## Build 6 | 7 | 1. install go: [golang](https://golang.org/dl/) 8 | 2. clone this repo : `git clone https://github.com/cs8425/ffmpeg-ws-relay.git` 9 | 3. build: `go build -o ws-relay ws-relay.go` 10 | 4. run with ffmpeg, see [Usage example](#usage-example) 11 | 5. open browser to: [http://127.0.0.1:8080/](http://127.0.0.1:8080/) 12 | 13 | 14 | ## Usage example: 15 | 16 | * transcode a file to websocket via png format: 17 | * `ffmpeg -re -i v01.mp4 -c:v png -f image2pipe - | ./ws-relay -l :8080 -s png` 18 | * transcode a file to websocket via jpg format: 19 | * `ffmpeg -re -i v01.mp4 -s 1280x720 -c:v mjpeg -qscale:v 2 -f image2pipe - | ./ws-relay -l :8080` 20 | * `-s 1280x720` : output size 21 | * `-qscale:v 2` : jpeg quality, range 2~31, 31 is the worst quality 22 | 23 | 24 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/cs8425/ffmpeg-ws-relay 2 | 3 | go 1.12 4 | 5 | require github.com/gorilla/websocket v1.4.0 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= 2 | github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= 3 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |