Use copy if we can

monorepo
Varun Patil 2022-11-12 09:50:16 -08:00
parent a42fcd6978
commit af6c0eb190
2 changed files with 15 additions and 9 deletions

View File

@ -38,6 +38,7 @@ type ProbeVideoData struct {
Height int Height int
Duration time.Duration Duration time.Duration
FrameRate int FrameRate int
CodecName string
} }
func NewManager(c *Config, path string, id string, close chan string) (*Manager, error) { func NewManager(c *Config, path string, id string, close chan string) (*Manager, error) {
@ -214,7 +215,7 @@ func (m *Manager) ffprobe() error {
// video // video
"-show_entries", "format=duration", "-show_entries", "format=duration",
"-show_entries", "stream=duration,width,height,avg_frame_rate", "-show_entries", "stream=duration,width,height,avg_frame_rate,codec_name",
"-select_streams", "v", // Video stream only, we're not interested in audio "-select_streams", "v", // Video stream only, we're not interested in audio
"-of", "json", "-of", "json",
@ -240,6 +241,7 @@ func (m *Manager) ffprobe() error {
Height int `json:"height"` Height int `json:"height"`
Duration string `json:"duration"` Duration string `json:"duration"`
FrameRate string `json:"avg_frame_rate"` FrameRate string `json:"avg_frame_rate"`
CodecName string `json:"codec_name"`
} `json:"streams"` } `json:"streams"`
Format struct { Format struct {
Duration string `json:"duration"` Duration string `json:"duration"`
@ -286,6 +288,7 @@ func (m *Manager) ffprobe() error {
Height: out.Streams[0].Height, Height: out.Streams[0].Height,
Duration: duration, Duration: duration,
FrameRate: int(frameRate), FrameRate: int(frameRate),
CodecName: out.Streams[0].CodecName,
} }
return nil return nil

View File

@ -280,10 +280,13 @@ func (s *Stream) transcode(startId int) {
}...) }...)
} }
// QSV / encoder selection // encoder selection
VAAPI := os.Getenv("VAAPI") == "1"
CV := "libx264" CV := "libx264"
if VAAPI {
// no need to transcode h264 streams for max quality
if s.quality == "max" && s.m.probe.CodecName == "h264" {
CV = "copy"
} else if os.Getenv("VAAPI") == "1" {
CV = "h264_vaapi" CV = "h264_vaapi"
extra := "-hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi" extra := "-hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi"
args = append(args, strings.Split(extra, " ")...) args = append(args, strings.Split(extra, " ")...)
@ -298,7 +301,7 @@ func (s *Stream) transcode(startId int) {
// Scaling for output // Scaling for output
var scale string var scale string
if VAAPI { if CV == "h264_vaapi" {
scale = fmt.Sprintf("scale_vaapi=w=%d:h=%d:force_original_aspect_ratio=decrease", s.width, s.height) scale = fmt.Sprintf("scale_vaapi=w=%d:h=%d:force_original_aspect_ratio=decrease", s.width, s.height)
} else if s.width >= s.height { } else if s.width >= s.height {
scale = fmt.Sprintf("scale=-2:%d", s.height) scale = fmt.Sprintf("scale=-2:%d", s.height)
@ -306,26 +309,26 @@ func (s *Stream) transcode(startId int) {
scale = fmt.Sprintf("scale=%d:-2", s.width) scale = fmt.Sprintf("scale=%d:-2", s.width)
} }
// not original (max) // do not scale or set bitrate for full quality
if s.quality != "max" { if s.quality != "max" {
args = append(args, []string{ args = append(args, []string{
"-vf", scale, "-vf", scale,
"-b:v", fmt.Sprintf("%dk", s.bitrate/1000), "-b:v", fmt.Sprintf("%dk", s.bitrate/1000),
"-profile:v", "high",
}...) }...)
} }
// Output specs // Output specs
args = append(args, []string{ args = append(args, []string{
"-c:v", CV, "-c:v", CV,
"-profile:v", "high",
}...) }...)
// Device specific output args // Device specific output args
if VAAPI { if CV == "h264_vaapi" {
args = append(args, []string{ args = append(args, []string{
"-low_power", "1", "-low_power", "1",
}...) }...)
} else { } else if CV == "libx264" {
args = append(args, []string{ args = append(args, []string{
"-preset", "faster", "-preset", "faster",
"-level:v", "4.0", "-level:v", "4.0",