Skip to content

Commit

Permalink
Merge pull request #7 from shimberger/restructuring
Browse files Browse the repository at this point in the history
Merging code refactoring...
  • Loading branch information
shimberger authored Nov 23, 2016
2 parents 535d8fe + 02b14be commit 33cd27a
Show file tree
Hide file tree
Showing 33 changed files with 518 additions and 71 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.sass-cache
/build
node_modules
videos
25 changes: 13 additions & 12 deletions README.md
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
261 changes: 261 additions & 0 deletions bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions cache/.gitignore

This file was deleted.

82 changes: 82 additions & 0 deletions cmd_serve.go
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
}
2 changes: 1 addition & 1 deletion debug.go → hls/debug.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package hls

import (
"flag"
Expand Down
Loading

0 comments on commit 33cd27a

Please sign in to comment.