Skip to content

Commit

Permalink
Merge pull request #18 from viam-modules/RSDK-8903
Browse files Browse the repository at this point in the history
[RSDK-8903] - Implement simple keyframe force interval
  • Loading branch information
seanavery authored Oct 4, 2024
2 parents 60da21f + 7a7138a commit 4c26696
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cam/cam.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
defaultVideoFormat = "mp4"
defaultUploadPath = ".viam/capture/video-upload"
defaultStoragePath = ".viam/video-storage"
defaultLogLevel = "info"
defaultLogLevel = "error"

maxGRPCSize = 1024 * 1024 * 32 // bytes
deleterInterval = 10 // minutes
Expand Down
7 changes: 7 additions & 0 deletions cam/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ func newEncoder(
enc.codecCtx.max_b_frames = 0
presetCStr := C.CString(preset)
tuneCStr := C.CString("zerolatency")
forceKeyFramesExpr := fmt.Sprintf("expr:gte(t,n_forced*%d)", framerate)
forceKeyFramesCStr := C.CString(forceKeyFramesExpr)
defer C.free(unsafe.Pointer(presetCStr))
defer C.free(unsafe.Pointer(tuneCStr))
defer C.free(unsafe.Pointer(forceKeyFramesCStr))

// The user can set the preset and tune for the encoder. This affects the
// encoding speed and quality. See https://trac.ffmpeg.org/wiki/Encode/H.264
Expand All @@ -76,6 +79,10 @@ func newEncoder(
if ret < 0 {
return nil, fmt.Errorf("av_dict_set failed: %s", ffmpegError(ret))
}
ret = C.av_dict_set(&opts, C.CString("force_key_frames"), forceKeyFramesCStr, 0)
if ret < 0 {
return nil, fmt.Errorf("av_dict_set failed: %s", ffmpegError(ret))
}

ret = C.avcodec_open2(enc.codecCtx, codec, &opts)
if ret < 0 {
Expand Down
2 changes: 1 addition & 1 deletion examples/save_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package main

import (
"context"
"math/rand"
"os"
"time"

Expand All @@ -17,7 +18,6 @@ import (
"go.viam.com/rdk/logging"
"go.viam.com/rdk/robot/client"
"go.viam.com/utils/rpc"
"golang.org/x/exp/rand"
)

func main() {
Expand Down

0 comments on commit 4c26696

Please sign in to comment.