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
Duration time.Duration
FrameRate int
CodecName string
}
func NewManager(c *Config, path string, id string, close chan string) (*Manager, error) {
@ -214,7 +215,7 @@ func (m *Manager) ffprobe() error {
// video
"-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
"-of", "json",
@ -240,6 +241,7 @@ func (m *Manager) ffprobe() error {
Height int `json:"height"`
Duration string `json:"duration"`
FrameRate string `json:"avg_frame_rate"`
CodecName string `json:"codec_name"`
} `json:"streams"`
Format struct {
Duration string `json:"duration"`
@ -286,6 +288,7 @@ func (m *Manager) ffprobe() error {
Height: out.Streams[0].Height,
Duration: duration,
FrameRate: int(frameRate),
CodecName: out.Streams[0].CodecName,
}
return nil

View File

@ -280,10 +280,13 @@ func (s *Stream) transcode(startId int) {
}...)
}
// QSV / encoder selection
VAAPI := os.Getenv("VAAPI") == "1"
// encoder selection
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"
extra := "-hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi"
args = append(args, strings.Split(extra, " ")...)
@ -298,7 +301,7 @@ func (s *Stream) transcode(startId int) {
// Scaling for output
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)
} else if s.width >= 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)
}
// not original (max)
// do not scale or set bitrate for full quality
if s.quality != "max" {
args = append(args, []string{
"-vf", scale,
"-b:v", fmt.Sprintf("%dk", s.bitrate/1000),
"-profile:v", "high",
}...)
}
// Output specs
args = append(args, []string{
"-c:v", CV,
"-profile:v", "high",
}...)
// Device specific output args
if VAAPI {
if CV == "h264_vaapi" {
args = append(args, []string{
"-low_power", "1",
}...)
} else {
} else if CV == "libx264" {
args = append(args, []string{
"-preset", "faster",
"-level:v", "4.0",