Merge 1754e3878cd8a679d1df87bd7adaef8ddd3da3f9 into f0323731dd3007c65a5cf940837ab41d96ddc940

This commit is contained in:
zital 2024-10-10 08:32:26 -07:00 committed by GitHub
commit d08b8566a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 76 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"os/exec" "os/exec"
"strings" "strings"
"regexp"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -29,6 +30,7 @@ var supportedCodecs = map[string]string{
(&VaapiCodec{}).Name(): "vaapi", (&VaapiCodec{}).Name(): "vaapi",
(&NvencCodec{}).Name(): "NVIDIA nvenc", (&NvencCodec{}).Name(): "NVIDIA nvenc",
(&VideoToolboxCodec{}).Name(): "videotoolbox", (&VideoToolboxCodec{}).Name(): "videotoolbox",
(&RockchipMPPCodec{}).Name(): "Rockchip MPP",
} }
// Libx264Codec represents an instance of the Libx264 Codec. // Libx264Codec represents an instance of the Libx264 Codec.
@ -302,6 +304,71 @@ func (c *NvencCodec) GetPresetForLevel(l int) string {
return preset return preset
} }
// RockchipMPPCodec represents an instance of the MPP codec.
type RockchipMPPCodec struct{}
// Name returns the codec name.
func (c *RockchipMPPCodec) Name() string {
return "h264_rkmpp"
}
// DisplayName returns the human readable name of the codec.
func (c *RockchipMPPCodec) DisplayName() string {
return "Rockchip MPP (mpp)"
}
// GlobalFlags are the global flags used with this codec in the transcoder.
func (c *RockchipMPPCodec) GlobalFlags() string {
return ""
}
// PixelFormat is the pixel format required for this codec.
func (c *RockchipMPPCodec) PixelFormat() string {
return "yuv420p"
}
// Scaler is the scaler used for resizing the video in the transcoder.
func (c *RockchipMPPCodec) Scaler() string {
return ""
}
// ExtraArguments are the extra arguments used with this codec in the transcoder.
func (c *RockchipMPPCodec) ExtraArguments() string {
return strings.Join([]string{
"-tune", "zerolatency", // Option used for good for fast encoding and low-latency streaming (always includes iframes in each segment)
}, " ")
}
// ExtraFilters are the extra filters required for this codec in the transcoder.
func (c *RockchipMPPCodec) ExtraFilters() string {
return ""
}
// VariantFlags returns a string representing a single variant processed by this codec.
func (c *RockchipMPPCodec) VariantFlags(v *HLSVariant) string {
return ""
}
// GetPresetForLevel returns the string preset for this codec given an integer level.
func (c *RockchipMPPCodec) GetPresetForLevel(l int) string {
presetMapping := map[int]string{
0: "ultrafast",
1: "superfast",
2: "veryfast",
3: "faster",
4: "fast",
}
preset, ok := presetMapping[l]
if !ok {
defaultPreset := presetMapping[1]
log.Errorf("Invalid level for mpp preset %d, defaulting to %s", l, defaultPreset)
return defaultPreset
}
return preset
}
// QuicksyncCodec represents an instance of the Intel Quicksync Codec. // QuicksyncCodec represents an instance of the Intel Quicksync Codec.
type QuicksyncCodec struct{} type QuicksyncCodec struct{}
@ -513,10 +580,11 @@ func GetCodecs(ffmpegPath string) []string {
return codecs return codecs
} }
re := regexp.MustCompile(`H\.?264`)
response := string(out) response := string(out)
lines := strings.Split(response, "\n") lines := strings.Split(response, "\n")
for _, line := range lines { for _, line := range lines {
if strings.Contains(line, "H.264") { if re.MatchString(line) {
fields := strings.Fields(line) fields := strings.Fields(line)
codec := fields[1] codec := fields[1]
if _, supported := supportedCodecs[codec]; supported { if _, supported := supportedCodecs[codec]; supported {
@ -542,6 +610,8 @@ func getCodec(name string) Codec {
return &Video4Linux{} return &Video4Linux{}
case (&VideoToolboxCodec{}).Name(): case (&VideoToolboxCodec{}).Name():
return &VideoToolboxCodec{} return &VideoToolboxCodec{}
case (&RockchipMPPCodec{}).Name():
return &RockchipMPPCodec{}
default: default:
return &Libx264Codec{} return &Libx264Codec{}
} }

View File

@ -93,6 +93,8 @@ export const CodecSelector: FC<CodecSelectorProps> = () => {
title = 'OpenMax (omx) for Raspberry Pi'; title = 'OpenMax (omx) for Raspberry Pi';
} else if (title === 'h264_videotoolbox') { } else if (title === 'h264_videotoolbox') {
title = 'Apple VideoToolbox (hardware)'; title = 'Apple VideoToolbox (hardware)';
} else if (title === 'h264_rkmpp') {
title = 'Rockchip MPP (hardware)';
} }
return ( return (
@ -123,6 +125,9 @@ export const CodecSelector: FC<CodecSelectorProps> = () => {
} else if (selectedCodec === 'h264_videotoolbox') { } else if (selectedCodec === 'h264_videotoolbox') {
description = description =
'Apple VideoToolbox is a low-level framework that provides direct access to hardware encoders and decoders.'; 'Apple VideoToolbox is a low-level framework that provides direct access to hardware encoders and decoders.';
} else if (selectedCodec === 'h264_rkmpp') {
description =
'Rockchip MPP is a hardware-accelerate encoder for rockchip ARM SoC chips, like orange pi etc.';
} }
return ( return (