0

Make things not break if video passthrough is enabled + update admin to display video settings a bit clearer. A start to #306

This commit is contained in:
Gabe Kangas 2020-11-19 22:07:28 -08:00
parent e860f9ab2f
commit 92dc98a0ea
5 changed files with 36 additions and 12 deletions

View File

@ -232,6 +232,10 @@ func (c *config) GetVideoStreamQualities() []StreamQuality {
// GetFramerate returns the framerate or default.
func (q *StreamQuality) GetFramerate() int {
if q.IsVideoPassthrough {
return 0
}
if q.Framerate > 0 {
return q.Framerate
}
@ -241,6 +245,10 @@ func (q *StreamQuality) GetFramerate() int {
// GetEncoderPreset returns the preset or default.
func (q *StreamQuality) GetEncoderPreset() string {
if q.IsVideoPassthrough {
return ""
}
if q.EncoderPreset != "" {
return q.EncoderPreset
}
@ -248,6 +256,18 @@ func (q *StreamQuality) GetEncoderPreset() string {
return _default.VideoSettings.StreamQualities[0].EncoderPreset
}
func (q *StreamQuality) GetIsAudioPassthrough() bool {
if q.IsAudioPassthrough {
return true
}
if q.AudioBitrate == 0 {
return true
}
return false
}
// Load tries to load the configuration file.
func Load(filePath string, versionInfo string, versionNumber string) error {
Config = new(config)

View File

@ -13,7 +13,7 @@ func GetServerConfig(w http.ResponseWriter, r *http.Request) {
var videoQualityVariants = make([]config.StreamQuality, 0)
for _, variant := range config.Config.GetVideoStreamQualities() {
videoQualityVariants = append(videoQualityVariants, config.StreamQuality{
IsAudioPassthrough: variant.IsAudioPassthrough,
IsAudioPassthrough: variant.GetIsAudioPassthrough(),
IsVideoPassthrough: variant.IsVideoPassthrough,
Framerate: variant.GetFramerate(),
EncoderPreset: variant.GetEncoderPreset(),

View File

@ -143,7 +143,6 @@ func (t *Transcoder) getString() string {
// Video settings
"-tune", "zerolatency", // Option used for good for fast encoding and low-latency streaming (always includes iframes in each segment)
"-pix_fmt", "yuv420p", // Force yuv420p color format
"-profile:v", "high", // Main for standard definition (SD) to 640×480, High for high definition (HD) to 1920×1080
"-sc_threshold", "0", // Disable scene change detection for creating segments
// Filenames
@ -239,8 +238,6 @@ func (v *HLSVariant) getVariantString(t *Transcoder) string {
variantEncoderCommands = append(variantEncoderCommands, v.getScalingString())
}
variantEncoderCommands = append(variantEncoderCommands, fmt.Sprintf("-r %d", v.framerate))
if v.encoderPreset != "" {
variantEncoderCommands = append(variantEncoderCommands, fmt.Sprintf("-preset %s", v.encoderPreset))
}
@ -310,11 +307,13 @@ func (v *HLSVariant) getVideoQualityString(t *Transcoder) string {
cmd := []string{
"-map v:0",
fmt.Sprintf("-c:v:%d %s", v.index, encoderCodec), // Video codec used for this variant
fmt.Sprintf("-b:v:%d %dk", v.index, v.videoBitrate), // The average bitrate for this variant
fmt.Sprintf("-maxrate:v:%d %dk", v.index, maxBitrate), // The max bitrate allowed for this variant
fmt.Sprintf("-bufsize:v:%d %dk", v.index, bufferSize), // How often the encoder checks the bitrate in order to meet average/max values
fmt.Sprintf("-g:v:%d %d", v.index, gop), // How often i-frames are encoded into the segments
fmt.Sprintf("-c:v:%d %s", v.index, encoderCodec), // Video codec used for this variant
fmt.Sprintf("-b:v:%d %dk", v.index, v.videoBitrate), // The average bitrate for this variant
fmt.Sprintf("-maxrate:v:%d %dk", v.index, maxBitrate), // The max bitrate allowed for this variant
fmt.Sprintf("-bufsize:v:%d %dk", v.index, bufferSize), // How often the encoder checks the bitrate in order to meet average/max values
fmt.Sprintf("-g:v:%d %d", v.index, gop), // How often i-frames are encoded into the segments
fmt.Sprintf("-profile:v:%d %s", v.index, "high"), // Encoding profile
fmt.Sprintf("-r:v:%d %d", v.index, v.framerate),
fmt.Sprintf("-x264-params:v:%d \"scenecut=0:open_gop=0:min-keyint=%d:keyint=%d\"", v.index, gop, gop), // How often i-frames are encoded into the segments
}

View File

@ -28,11 +28,16 @@ func TestFFmpegCommand(t *testing.T) {
variant2.SetVideoFramerate(24)
transcoder.AddVariant(variant2)
variant3 := HLSVariant{}
variant3.isAudioPassthrough = true
variant3.isVideoPassthrough = true
transcoder.AddVariant(variant3)
cmd := transcoder.getString()
expected := `/fake/path/ffmpeg -hide_banner -loglevel warning -i fakecontent.flv -map v:0 -c:v:0 libx264 -b:v:0 1200k -maxrate:v:0 1272k -bufsize:v:0 1440k -g:v:0 119 -x264-params:v:0 "scenecut=0:open_gop=0:min-keyint=119:keyint=119" -map a:0 -c:a:0 copy -r 30 -preset veryfast -map v:0 -c:v:1 libx264 -b:v:1 3500k -maxrate:v:1 3710k -bufsize:v:1 4200k -g:v:1 95 -x264-params:v:1 "scenecut=0:open_gop=0:min-keyint=95:keyint=95" -map a:0 -c:a:1 copy -r 24 -preset faster -var_stream_map "v:0,a:0 v:1,a:1 " -f hls -hls_time 4 -hls_list_size 10 -hls_delete_threshold 10 -tune zerolatency -pix_fmt yuv420p -profile:v high -sc_threshold 0 -master_pl_name stream.m3u8 -strftime 1 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdofFGg%s.ts -max_muxing_queue_size 400 -method PUT -http_persistent 0 -fflags +genpts http://127.0.0.1:8123/%v/stream.m3u8 2> transcoder.log`
expected := `/fake/path/ffmpeg -hide_banner -loglevel warning -i fakecontent.flv -map v:0 -c:v:0 libx264 -b:v:0 1200k -maxrate:v:0 1272k -bufsize:v:0 1440k -g:v:0 119 -profile:v:0 high -r:v:0 30 -x264-params:v:0 "scenecut=0:open_gop=0:min-keyint=119:keyint=119" -map a:0 -c:a:0 copy -preset veryfast -map v:0 -c:v:1 libx264 -b:v:1 3500k -maxrate:v:1 3710k -bufsize:v:1 4200k -g:v:1 95 -profile:v:1 high -r:v:1 24 -x264-params:v:1 "scenecut=0:open_gop=0:min-keyint=95:keyint=95" -map a:0 -c:a:1 copy -preset faster -map v:0 -c:v:2 copy -map a:0 -c:a:2 copy -var_stream_map "v:0,a:0 v:1,a:1 v:2,a:2 " -f hls -hls_time 4 -hls_list_size 10 -hls_delete_threshold 10 -tune zerolatency -pix_fmt yuv420p -sc_threshold 0 -master_pl_name stream.m3u8 -strftime 1 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdofFGg%s.ts -max_muxing_queue_size 400 -method PUT -http_persistent 0 -fflags +genpts http://127.0.0.1:8123/%v/stream.m3u8 2> transcoder.log`
if cmd != expected {
t.Errorf("ffmpeg command does not match expected. Got %s, want: %s", cmd, expected)
t.Errorf("ffmpeg command does not match expected.\nGot %s\n, want: %s", cmd, expected)
}
}

File diff suppressed because one or more lines are too long