-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from shimberger/restructuring
Merging code refactoring...
- Loading branch information
Showing
33 changed files
with
518 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.DS_Store | ||
.sass-cache | ||
/build | ||
node_modules | ||
videos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
Golang HLS Streamer | ||
=================== | ||
# Golang HLS Streamer | ||
|
||
Simple server that exposes a directory for video streaming via HTTP Live Streaming (HLS). | ||
Uses ffmpeg for transcoding. | ||
Simple server that exposes a directory for video streaming via HTTP Live Streaming (HLS). Uses ffmpeg for transcoding. | ||
|
||
This project is cobbled together from all kinds of code I has lying around so it's pretty crappy all around. | ||
*This project is cobbled together from all kinds of code I has lying around so it's pretty crappy all around. It also has some serious shortcomings.* | ||
|
||
Running it | ||
---------- | ||
## Running it | ||
*Important*: You need the ffmpeg and ffrpobe binaries in your PATH. The server will not start without them. You can find builds most operating systems at https://ffmpeg.org/download.html. | ||
|
||
- Place ffmpeg and ffprobe binaries in "tools" dir | ||
- Run go run *.go <path to videos> in project root (e.g. go run *.go ~/Documents/) | ||
- Access http://localhost:8080/ui/ | ||
1. Download the binary for your operating system from the releases page (https://github.com/shimberger/golang-hls/releases) | ||
2. Execute the command `gohls serve <path to videos>` e.g. `gohls serve ~/Documents/Videos` to serve the videos located in `~/Documents/Videos`. | ||
3. Visit the URL http://localhost:8080 to access the web interface | ||
|
||
## Developing it | ||
Just do a `go get /github.com/shimberger/golang-hls/...` in your GOPATH. Then change into the project directory and run the development server by executing `./scripts/run_dev` (sorry Windows users). You need gulp & npm to build the frontend. | ||
|
||
## License | ||
|
||
License | ||
------- | ||
See LICENSE.txt |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"github.com/google/subcommands" | ||
"github.com/shimberger/gohls/hls" | ||
"log" | ||
"net/http" | ||
"os/exec" | ||
"os/user" | ||
"path" | ||
) | ||
|
||
type serveCmd struct { | ||
homeDir string | ||
} | ||
|
||
func (*serveCmd) Name() string { return "serve" } | ||
func (*serveCmd) Synopsis() string { return "Serves the directory for streaming" } | ||
func (*serveCmd) Usage() string { | ||
return `serve <path to videos>: | ||
Serve videos in path as HTTP | ||
` | ||
} | ||
|
||
func (p *serveCmd) SetFlags(f *flag.FlagSet) { | ||
f.StringVar(&p.homeDir, "home", ".", "The home directory") | ||
} | ||
|
||
func (p *serveCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { | ||
// Determine user info | ||
usr, uerr := user.Current() | ||
if uerr != nil { | ||
log.Fatal(uerr) | ||
} | ||
|
||
// Find ffmpeg | ||
ffmpeg, f1err := exec.LookPath("ffmpeg") | ||
if f1err != nil { | ||
log.Fatal("ffmpeg could not be found in your path", f1err) | ||
} | ||
|
||
// Find ffprobe | ||
ffprobe, f2err := exec.LookPath("ffprobe") | ||
if f2err != nil { | ||
log.Fatal("ffprobe could not be found in your path", f2err) | ||
} | ||
|
||
// Generate variables and paths | ||
var port = 8080 | ||
var homeDir = path.Join(usr.HomeDir, ".gohls") | ||
var videoDir = path.Join(usr.HomeDir, "Videos") | ||
if f.NArg() > 0 { | ||
videoDir = f.Arg(0) | ||
} | ||
|
||
// Configure HLS module | ||
hls.FFMPEGPath = "ffmpeg" | ||
hls.FFProbePath = "ffprobe" | ||
hls.HomeDir = homeDir | ||
|
||
// Setup HTTP server | ||
http.Handle("/", http.RedirectHandler("/ui/", 302)) | ||
http.Handle("/ui/assets/", http.StripPrefix("/ui/assets/", &assetHandler{})) | ||
http.Handle("/ui/", hls.NewDebugHandlerWrapper(http.StripPrefix("/ui/", NewSingleAssetHandler("index.html")))) | ||
http.Handle("/list/", hls.NewDebugHandlerWrapper(http.StripPrefix("/list/", hls.NewListHandler(videoDir)))) | ||
http.Handle("/frame/", hls.NewDebugHandlerWrapper(http.StripPrefix("/frame/", hls.NewFrameHandler(videoDir)))) | ||
http.Handle("/playlist/", hls.NewDebugHandlerWrapper(http.StripPrefix("/playlist/", hls.NewPlaylistHandler(videoDir)))) | ||
http.Handle("/segments/", hls.NewDebugHandlerWrapper(http.StripPrefix("/segments/", hls.NewStreamHandler(videoDir)))) | ||
|
||
// Dump information to user | ||
fmt.Printf("Path to ffmpeg executable: %v\n", ffmpeg) | ||
fmt.Printf("Path to ffprobe executable: %v\n", ffprobe) | ||
fmt.Printf("Home directory: %v/\n", homeDir) | ||
fmt.Printf("Serving videos in %v\n", videoDir) | ||
fmt.Printf("Visit http://localhost:%v/\n", port) | ||
http.ListenAndServe(fmt.Sprintf(":%v", port), nil) | ||
|
||
return subcommands.ExitSuccess | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package hls | ||
|
||
import ( | ||
"flag" | ||
|
Oops, something went wrong.