Skip to content

Commit

Permalink
making code easy to understand
Browse files Browse the repository at this point in the history
  • Loading branch information
mohit810 committed Nov 28, 2020
1 parent 7316dcd commit 06aa829
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 174 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vid/.gitkeep
38 changes: 18 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Signalling Pion Webrtc server via `POST` request
# This server accepts video and audio via webrtc and converts them in Adaptive HLS
This project is in Progress(ui,cdn integration), `Webrtc -> HLS` part is Complete.

This project is in Progress.
### Run Application

#### Steps to follow for using this project
1) Install or upgrade Golang ver. 1.15 or above
2) Install or upgrade Ffmpeg ver. 4.3.1-5 or above (Currently available in `Debian Sid`)
3) Download the project using Git command `git clone https://github.com/mohit810/streamingcdn`
4) To start the server use the command `go run main.go` (Use terminal for running the server)

### Software Req.
1) Golang >= 1.15
2) Ffmpeg >= 4.3.1-5 (Currently available in `Debian Sid`)
* Congratulations!! Now the server is up and running.
* As a starting point for testing you can use the [Web UI](https://github.com/mohit810/streamingcdn-web-ui)

### Current State
1) Users can connect via `POST` request and start streaming(1.5Mbps speed is hardcoded for the stream).
Expand All @@ -14,27 +20,19 @@ This project is in Progress.
1) Integrating FFmpeg.(Completed for now, further optimization will be done later)
2) Allowing multiple users to connect and start broadcasting.(not in priority, at this stage.)
3) CDN Integration ( Post UI development)
4) Front-end UI Development in android, web, ios. ( Current priority is android & web)
4) Front-end UI Development in android, web, ios. (Current priority is android)

### Final Goal
To receive the broadcast, Convert it into hls in various quality then push those to cdn to serve to the User.

Before using this solution you should set-up pion/webrtc/v3 ([Go Modules](https://blog.golang.org/using-go-modules) are mandatory for using Pion WebRTC. So make sure you set export GO111MODULE=on, and explicitly specify /v3 when importing.).

### Open broadcast example page
[localhost:8080](http://localhost:8080/)

### Run Application
#### Linux/macOS/windows
Run `main.go`

### Start a publisher

* Paste your Twitch stream Key
* Click `Publish a Broadcast` and now you don't have to do anything.
* Communicating with server is done by the js itself.
* If you want to know the request that is sent to server via `POST` method, refer to the screenshot attached below. The `application` will respond with an offer as a response to the `POST`.
### POST API used by the broadcaster for connecting to the server

![](https://github.com/mohit810/streamingcdn/blob/main/Screenshot.png)
`{
"sdp":"",
"streamKey":""
}`

## Big Thanks to the following

Expand Down
Binary file removed Screenshot.png
Binary file not shown.
6 changes: 3 additions & 3 deletions ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"bufio"
"context"
"fmt"
"os"
"os/exec"
)

func StartFFmpeg(ctx context.Context) {
//ffmpegPath := "ffmpeg"
//srcPath := "/home/tester/go/src/practice/hlsconvertor/sample720.mp4"
targetPath := "/home/tester/go/src/streamingcdn/vid" //replace according to ur need
goDir, _ := os.Getwd()
targetPath := goDir + "vid" //replace according to ur need
resOptions := []string{"360p", "480p", "720p", "1080p"}

variants, _ := generateHLSVariant(resOptions, "")
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import (
"flag"
"fmt"
"net/http"
"os"
"strconv"

"github.com/julienschmidt/httprouter"
Expand All @@ -19,6 +21,9 @@ func main() {
flag.Parse()
r := httprouter.New()
signal.HTTPSDPServer(r)
fmt.Println("Server is Up and Running at Port:" + strconv.Itoa(*port))
wd, _ := os.Getwd()
fmt.Println(wd)
err := http.ListenAndServe(":"+strconv.Itoa(*port), r)
if err != nil {
panic(err)
Expand Down
124 changes: 0 additions & 124 deletions public/demo.js

This file was deleted.

27 changes: 0 additions & 27 deletions public/index.html

This file was deleted.

0 comments on commit 06aa829

Please sign in to comment.