Encoder tweaks
This commit is contained in:
parent
67acfeb6f5
commit
0d0e33c607
@ -29,7 +29,7 @@ type VideoSettings struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StreamQuality struct {
|
type StreamQuality struct {
|
||||||
Bitrate string `yaml:"bitrate"`
|
Bitrate int `yaml:"bitrate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxNumberOnDisk must be at least as large as MaxNumberInPlaylist
|
// MaxNumberOnDisk must be at least as large as MaxNumberInPlaylist
|
||||||
|
@ -10,7 +10,7 @@ videoSettings:
|
|||||||
passthrough: true # Enabling this will ignore the below stream qualities and pass through the same quality that you're sending it
|
passthrough: true # Enabling this will ignore the below stream qualities and pass through the same quality that you're sending it
|
||||||
|
|
||||||
streamQualities:
|
streamQualities:
|
||||||
- bitrate: 6000k
|
- bitrate: 1000 # in k
|
||||||
|
|
||||||
files:
|
files:
|
||||||
maxNumberInPlaylist: 30
|
maxNumberInPlaylist: 30
|
||||||
|
15
ffmpeg.go
15
ffmpeg.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@ -37,14 +38,15 @@ func startFfmpeg(configuration Config) {
|
|||||||
var videoMapsString = ""
|
var videoMapsString = ""
|
||||||
var audioMapsString = ""
|
var audioMapsString = ""
|
||||||
var streamMappingString = ""
|
var streamMappingString = ""
|
||||||
|
|
||||||
if configuration.VideoSettings.EnablePassthrough || len(configuration.VideoSettings.StreamQualities) == 0 {
|
if configuration.VideoSettings.EnablePassthrough || len(configuration.VideoSettings.StreamQualities) == 0 {
|
||||||
fmt.Println("Enabling passthrough video")
|
fmt.Println("Enabling passthrough video")
|
||||||
// videoMaps = append(videoMaps, fmt.Sprintf("-map 0:v -c:v copy"))
|
// videoMaps = append(videoMaps, fmt.Sprintf("-map 0:v -c:v copy"))
|
||||||
streamMaps = append(streamMaps, fmt.Sprintf("v:%d,a:%d", 0, 0))
|
streamMaps = append(streamMaps, fmt.Sprintf("v:%d,a:%d", 0, 0))
|
||||||
} else {
|
} else {
|
||||||
for index, quality := range configuration.VideoSettings.StreamQualities {
|
for index, quality := range configuration.VideoSettings.StreamQualities {
|
||||||
videoMaps = append(videoMaps, fmt.Sprintf("-map v:0 -c:v:%d libx264 -b:v:%d %s", index, index, quality.Bitrate))
|
// minRate := math.Floor(float64(quality.Bitrate) / 2)
|
||||||
|
maxRate := math.Floor(float64(quality.Bitrate) * 0.8)
|
||||||
|
videoMaps = append(videoMaps, fmt.Sprintf("-map v:0 -c:v:%d libx264 -b:v:%d %dk -maxrate %dk -bufsize %dk", index, index, int(quality.Bitrate), int(maxRate), int(maxRate)))
|
||||||
streamMaps = append(streamMaps, fmt.Sprintf("v:%d,a:%d", index, index))
|
streamMaps = append(streamMaps, fmt.Sprintf("v:%d,a:%d", index, index))
|
||||||
videoMapsString = strings.Join(videoMaps, " ")
|
videoMapsString = strings.Join(videoMaps, " ")
|
||||||
audioMaps = append(audioMaps, "-map a:0")
|
audioMaps = append(audioMaps, "-map a:0")
|
||||||
@ -52,6 +54,8 @@ func startFfmpeg(configuration Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
framerate := 30
|
||||||
|
|
||||||
streamMappingString = "-var_stream_map \"" + strings.Join(streamMaps, " ") + "\""
|
streamMappingString = "-var_stream_map \"" + strings.Join(streamMaps, " ") + "\""
|
||||||
ffmpegFlags := []string{
|
ffmpegFlags := []string{
|
||||||
"-hide_banner",
|
"-hide_banner",
|
||||||
@ -62,15 +66,14 @@ func startFfmpeg(configuration Config) {
|
|||||||
videoMapsString, // All the different video variants
|
videoMapsString, // All the different video variants
|
||||||
audioMapsString,
|
audioMapsString,
|
||||||
"-master_pl_name stream.m3u8",
|
"-master_pl_name stream.m3u8",
|
||||||
"-g 60", "-keyint_min 60", // create key frame (I-frame) every 48 frames (~2 seconds) - will later affect correct slicing of segments and alignment of renditions
|
"-framerate " + strconv.Itoa(framerate),
|
||||||
// "-framerate 30",
|
"-g " + strconv.Itoa(framerate*2), " -keyint_min " + strconv.Itoa(framerate*2), // multiply your output frame rate * 2. For example, if your input is -framerate 30, then use -g 60
|
||||||
// "-r 25",
|
// "-r 25",
|
||||||
"-preset " + configuration.VideoSettings.EncoderPreset,
|
"-preset " + configuration.VideoSettings.EncoderPreset,
|
||||||
"-sc_threshold 0", // don't create key frames on scene change - only according to -g
|
"-sc_threshold 0", // don't create key frames on scene change - only according to -g
|
||||||
"-profile:v high", // Main – for standard definition (SD) to 640×480, High – for high definition (HD) to 1920×1080
|
"-profile:v high", // Main – for standard definition (SD) to 640×480, High – for high definition (HD) to 1920×1080
|
||||||
"-movflags +faststart",
|
"-movflags +faststart",
|
||||||
"-pix_fmt yuv420p",
|
"-pix_fmt yuv420p",
|
||||||
"-maxrate 2048k -bufsize 2048k",
|
|
||||||
"-f hls",
|
"-f hls",
|
||||||
"-hls_list_size " + strconv.Itoa(configuration.Files.MaxNumberInPlaylist),
|
"-hls_list_size " + strconv.Itoa(configuration.Files.MaxNumberInPlaylist),
|
||||||
"-hls_time " + strconv.Itoa(configuration.VideoSettings.ChunkLengthInSeconds),
|
"-hls_time " + strconv.Itoa(configuration.VideoSettings.ChunkLengthInSeconds),
|
||||||
@ -89,7 +92,7 @@ func startFfmpeg(configuration Config) {
|
|||||||
|
|
||||||
ffmpegCmd := "cat " + pipePath + " | " + configuration.FFMpegPath + " " + ffmpegFlagsString
|
ffmpegCmd := "cat " + pipePath + " | " + configuration.FFMpegPath + " " + ffmpegFlagsString
|
||||||
|
|
||||||
// fmt.Println(ffmpegCmd)
|
fmt.Println(ffmpegCmd)
|
||||||
|
|
||||||
_, err := exec.Command("sh", "-c", ffmpegCmd).Output()
|
_, err := exec.Command("sh", "-c", ffmpegCmd).Output()
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user