rpi: add H264 software encoder (#2581) (#3670)

This allows to use the RPI camera on the Raspberry Pi 5 too.
This commit is contained in:
Alessandro Ros
2024-08-21 00:05:40 +02:00
committed by GitHub
parent f4051eb63d
commit 41a3fd503d
7 changed files with 71 additions and 57 deletions
+10 -8
View File
@@ -402,14 +402,6 @@ components:
type: string
rpiCameraFPS:
type: number
rpiCameraIDRPeriod:
type: integer
rpiCameraBitrate:
type: integer
rpiCameraProfile:
type: string
rpiCameraLevel:
type: string
rpiCameraAfMode:
type: string
rpiCameraAfRange:
@@ -426,6 +418,16 @@ components:
type: boolean
rpiCameraTextOverlay:
type: string
rpiCameraCodec:
type: string
rpiCameraIDRPeriod:
type: integer
rpiCameraBitrate:
type: integer
rpiCameraProfile:
type: string
rpiCameraLevel:
type: string
# Hooks
runOnInit:
+5 -4
View File
@@ -69,14 +69,15 @@ func TestConfFromFile(t *testing.T) {
RPICameraDenoise: "off",
RPICameraMetering: "centre",
RPICameraFPS: 30,
RPICameraIDRPeriod: 60,
RPICameraBitrate: 1000000,
RPICameraProfile: "main",
RPICameraLevel: "4.1",
RPICameraAfMode: "continuous",
RPICameraAfRange: "normal",
RPICameraAfSpeed: "normal",
RPICameraTextOverlay: "%Y-%m-%d %H:%M:%S - MediaMTX",
RPICameraCodec: "auto",
RPICameraIDRPeriod: 60,
RPICameraBitrate: 1000000,
RPICameraProfile: "main",
RPICameraLevel: "4.1",
RunOnDemandStartTimeout: 5 * StringDuration(time.Second),
RunOnDemandCloseAfter: 10 * StringDuration(time.Second),
}, pa)
+15 -8
View File
@@ -152,10 +152,6 @@ type Path struct {
RPICameraTuningFile string `json:"rpiCameraTuningFile"`
RPICameraMode string `json:"rpiCameraMode"`
RPICameraFPS float64 `json:"rpiCameraFPS"`
RPICameraIDRPeriod int `json:"rpiCameraIDRPeriod"`
RPICameraBitrate int `json:"rpiCameraBitrate"`
RPICameraProfile string `json:"rpiCameraProfile"`
RPICameraLevel string `json:"rpiCameraLevel"`
RPICameraAfMode string `json:"rpiCameraAfMode"`
RPICameraAfRange string `json:"rpiCameraAfRange"`
RPICameraAfSpeed string `json:"rpiCameraAfSpeed"`
@@ -164,6 +160,11 @@ type Path struct {
RPICameraFlickerPeriod int `json:"rpiCameraFlickerPeriod"`
RPICameraTextOverlayEnable bool `json:"rpiCameraTextOverlayEnable"`
RPICameraTextOverlay string `json:"rpiCameraTextOverlay"`
RPICameraCodec string `json:"rpiCameraCodec"`
RPICameraIDRPeriod int `json:"rpiCameraIDRPeriod"`
RPICameraBitrate int `json:"rpiCameraBitrate"`
RPICameraProfile string `json:"rpiCameraProfile"`
RPICameraLevel string `json:"rpiCameraLevel"`
// Hooks
RunOnInit string `json:"runOnInit"`
@@ -211,14 +212,15 @@ func (pconf *Path) setDefaults() {
pconf.RPICameraDenoise = "off"
pconf.RPICameraMetering = "centre"
pconf.RPICameraFPS = 30
pconf.RPICameraIDRPeriod = 60
pconf.RPICameraBitrate = 1000000
pconf.RPICameraProfile = "main"
pconf.RPICameraLevel = "4.1"
pconf.RPICameraAfMode = "continuous"
pconf.RPICameraAfRange = "normal"
pconf.RPICameraAfSpeed = "normal"
pconf.RPICameraTextOverlay = "%Y-%m-%d %H:%M:%S - MediaMTX"
pconf.RPICameraCodec = "auto"
pconf.RPICameraIDRPeriod = 60
pconf.RPICameraBitrate = 1000000
pconf.RPICameraProfile = "main"
pconf.RPICameraLevel = "4.1"
// Hooks
pconf.RunOnDemandStartTimeout = 10 * StringDuration(time.Second)
@@ -550,6 +552,11 @@ func (pconf *Path) validate(
default:
return fmt.Errorf("invalid 'rpiCameraAfSpeed' value")
}
switch pconf.RPICameraCodec {
case "auto", "hardwareH264", "softwareH264":
default:
return fmt.Errorf("invalid 'rpiCameraCodec' value")
}
// Hooks
@@ -1 +1 @@
v2.1.0
v2.2.0
+5 -4
View File
@@ -25,10 +25,6 @@ type params struct {
TuningFile string
Mode string
FPS float64
IDRPeriod int
Bitrate int
Profile string
Level string
AfMode string
AfRange string
AfSpeed string
@@ -37,4 +33,9 @@ type params struct {
FlickerPeriod int
TextOverlayEnable bool
TextOverlay string
Codec string
IDRPeriod int
Bitrate int
Profile string
Level string
}
+5 -4
View File
@@ -50,10 +50,6 @@ func paramsFromConf(logLevel conf.LogLevel, cnf *conf.Path) params {
TuningFile: cnf.RPICameraTuningFile,
Mode: cnf.RPICameraMode,
FPS: cnf.RPICameraFPS,
IDRPeriod: cnf.RPICameraIDRPeriod,
Bitrate: cnf.RPICameraBitrate,
Profile: cnf.RPICameraProfile,
Level: cnf.RPICameraLevel,
AfMode: cnf.RPICameraAfMode,
AfRange: cnf.RPICameraAfRange,
AfSpeed: cnf.RPICameraAfSpeed,
@@ -62,6 +58,11 @@ func paramsFromConf(logLevel conf.LogLevel, cnf *conf.Path) params {
FlickerPeriod: cnf.RPICameraFlickerPeriod,
TextOverlayEnable: cnf.RPICameraTextOverlayEnable,
TextOverlay: cnf.RPICameraTextOverlay,
Codec: cnf.RPICameraCodec,
IDRPeriod: cnf.RPICameraIDRPeriod,
Bitrate: cnf.RPICameraBitrate,
Profile: cnf.RPICameraProfile,
Level: cnf.RPICameraLevel,
}
}
+30 -28
View File
@@ -508,62 +508,54 @@ pathDefaults:
# ID of the camera
rpiCameraCamID: 0
# width of frames
# Width of frames
rpiCameraWidth: 1920
# height of frames
# Height of frames
rpiCameraHeight: 1080
# flip horizontally
# Flip horizontally
rpiCameraHFlip: false
# flip vertically
# Flip vertically
rpiCameraVFlip: false
# brightness [-1, 1]
# Brightness [-1, 1]
rpiCameraBrightness: 0
# contrast [0, 16]
# Contrast [0, 16]
rpiCameraContrast: 1
# saturation [0, 16]
# Saturation [0, 16]
rpiCameraSaturation: 1
# sharpness [0, 16]
# Sharpness [0, 16]
rpiCameraSharpness: 1
# exposure mode.
# Exposure mode.
# values: normal, short, long, custom
rpiCameraExposure: normal
# auto-white-balance mode.
# Auto-white-balance mode.
# values: auto, incandescent, tungsten, fluorescent, indoor, daylight, cloudy, custom
rpiCameraAWB: auto
# auto-white-balance fixed gains. This can be used in place of rpiCameraAWB.
# Auto-white-balance fixed gains. This can be used in place of rpiCameraAWB.
# format: [red,blue]
rpiCameraAWBGains: [0, 0]
# denoise operating mode.
# Denoise operating mode.
# values: off, cdn_off, cdn_fast, cdn_hq
rpiCameraDenoise: "off"
# fixed shutter speed, in microseconds.
# Fixed shutter speed, in microseconds.
rpiCameraShutter: 0
# metering mode of the AEC/AGC algorithm.
# Metering mode of the AEC/AGC algorithm.
# values: centre, spot, matrix, custom
rpiCameraMetering: centre
# fixed gain
# Fixed gain
rpiCameraGain: 0
# EV compensation of the image [-10, 10]
rpiCameraEV: 0
# Region of interest, in format x,y,width,height
rpiCameraROI:
# whether to enable HDR on Raspberry Camera 3.
# Whether to enable HDR on Raspberry Camera 3.
rpiCameraHDR: false
# tuning file
# Tuning file
rpiCameraTuningFile:
# sensor mode, in format [width]:[height]:[bit-depth]:[packing]
# Sensor mode, in format [width]:[height]:[bit-depth]:[packing]
# bit-depth and packing are optional.
rpiCameraMode:
# frames per second
rpiCameraFPS: 30
# period between IDR frames
rpiCameraIDRPeriod: 60
# bitrate
rpiCameraBitrate: 1000000
# H264 profile
rpiCameraProfile: main
# H264 level
rpiCameraLevel: '4.1'
# Autofocus mode
# values: auto, manual, continuous
rpiCameraAfMode: continuous
@@ -584,11 +576,21 @@ pathDefaults:
rpiCameraAfWindow:
# Manual flicker correction period, in microseconds.
rpiCameraFlickerPeriod: 0
# enables printing text on each frame.
# Enables printing text on each frame.
rpiCameraTextOverlayEnable: false
# text that is printed on each frame.
# Text that is printed on each frame.
# format is the one of the strftime() function.
rpiCameraTextOverlay: '%Y-%m-%d %H:%M:%S - MediaMTX'
# Codec. Available values: auto, hardwareH264, softwareH264
rpiCameraCodec: auto
# Period between IDR frames
rpiCameraIDRPeriod: 60
# Bitrate
rpiCameraBitrate: 1000000
# H264 profile
rpiCameraProfile: main
# H264 level
rpiCameraLevel: '4.1'
###############################################
# Default path settings -> Hooks