Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video: Uprate RasPi hardware encoding #195

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions python/rtsp-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ def getPipeline(device, height, width, bitrate, format, rotation, framerate, tim
bitrate*1000, devrotation, ts)
elif "Ubuntu" not in platform.uname().version and not is_debian_bookworm():
# Pi or similar arm platforms running on RasPiOS. Note that bookworm (and Pi5) onwards don't support hardware encoding
s_h264 = "videoconvert ! {1} ! {2}v4l2h264enc extra-controls=\"controls,repeat_sequence_header=1,h264_profile=2,video_bitrate={0},h264_i_frame_period=5\" ! video/x-h264,profile=main,level=(string)4 ! h264parse".format(
bitrate*1000, devrotation, ts)
# Only use a higher h264 level if the bitrate requires it. I find that level 4.1 can be a little crashy sometimes.
if bitrate > 20000:
level = "4.1"
else:
level = "4"
s_h264 = "videoconvert ! {1} ! {2}v4l2h264enc extra-controls=\"controls,repeat_sequence_header=1,h264_profile=4,video_bitrate={0},h264_i_frame_period=5\" ! video/x-h264,profile=high,level=(string){3} ! h264parse".format(
bitrate*1000, devrotation, ts, level)
else:
# s/w encoder - Pi-on-ubuntu, or RasPiOS Bookworm, due to ...sigh ... incompatibility issues
s_h264 = "videoconvert ! video/x-raw,format=I420 ! queue ! {1} ! {2}x264enc tune=zerolatency bitrate={0} speed-preset=superfast".format(
s_h264 = "videoconvert ! video/x-raw,format=NV12 ! queue ! {1} ! {2}x264enc tune=zerolatency bitrate={0} speed-preset=superfast".format(
bitrate, devrotation, ts)
else:
# s/w encoder - x86, etc
Expand Down
2 changes: 1 addition & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ app.post('/api/startstopvideo', [check('active').isBoolean(),
check('useTimestamp').isBoolean(),
check('useUDPPort').isPort(),
check('useUDPIP').isIP(),
check('bitrate').isInt({ min: 50, max: 20000 }),
check('bitrate').isInt({ min: 50, max: 50000 }),
check('format').isIn(['video/x-raw', 'video/x-h264', 'image/jpeg']),
check('fps').isInt({ min: -1, max: 100 }),
check('rotation').isInt().isIn([0, 90, 180, 270])], (req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion src/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class VideoPage extends basePage {
<div className="form-group row" style={{ marginBottom: '5px' }}>
<label className="col-sm-4 col-form-label">Maximum Bitrate</label>
<div className="col-sm-8">
<input disabled={this.state.streamingStatus} type="number" name="bitrate" min="50" max="20000" step="10" onChange={this.handleBitrateChange} value={this.state.bitrate} />kbps
<input disabled={this.state.streamingStatus} type="number" name="bitrate" min="50" max="50000" step="10" onChange={this.handleBitrateChange} value={this.state.bitrate} />kbps
</div>
</div>
<div className="form-group row" style={{ marginBottom: '5px' }}>
Expand Down