Skip to content

Add cgo accessible logging shim for the custom ffmpeg log callback#93

Merged
seanavery merged 5 commits into
viam-modules:mainfrom
seanavery:ffmpeg-logger-shim
May 26, 2026
Merged

Add cgo accessible logging shim for the custom ffmpeg log callback#93
seanavery merged 5 commits into
viam-modules:mainfrom
seanavery:ffmpeg-logger-shim

Conversation

@seanavery
Copy link
Copy Markdown
Collaborator

@seanavery seanavery commented May 22, 2026

Description

We currently have coarse FFmpeg log handling: the cgo callback formats each line and dumps it to stderr/stdout via fprintf, and we rely on the viam-server parent process to interpret stderr as errors and stdout as info.

This PR changes the callback to hand the formatted line and level up to a Go shim, which routes it through the module's logging.Logger under an ffmpeg sublogger (libav levels map onto rdk loglevels).

Testing

  • Unit tests verify mapping of FFmpeg loglevel to our rdk loglevels ✅
  • Sanity check ffmpegLogger atomic.Pointer use by running tests with -race flag ✅
  • test live on machine full stack with viamrtsp
    • confirm debug ✅
    • confirm info ✅
    • confirm error ✅
5/26/2026, 4:42:20 PM debug viamrtsp.ffmpeg     utils/utils_ffmpeg_log_cgo.go:94 [segment @ 0x7835c8000c00] -> pts:1445400 pts_time:16.06 dts:1445400 dts_time:16.06
5/26/2026, 4:42:20 PM debug viamrtsp.ffmpeg     utils/utils_ffmpeg_log_cgo.go:94 [segment @ 0x7835c8000c00] stream:0 start_pts_time:240.14 pts:23058000 pts_time:256.2 dts:23058000 dts_time:256.2
5/26/2026, 4:42:20 PM debug viamrtsp.ffmpeg     utils/utils_ffmpeg_log_cgo.go:94 [segment @ 0x7835c8000c00] -> pts:1449000 pts_time:16.1 dts:1449000 dts_time:16.1
5/26/2026, 4:42:20 PM debug viamrtsp.ffmpeg     utils/utils_ffmpeg_log_cgo.go:94 [segment @ 0x7835c8000c00] stream:0 start_pts_time:240.14 pts:23061600 pts_time:256.24 dts:23061600 dts_time:256.24
5/26/2026, 4:42:20 PM debug viamrtsp.ffmpeg     utils/utils_ffmpeg_log_cgo.go:94 [segment @ 0x7835c8000c00] -> pts:1454400 pts_time:16.16 dts:1454400 dts_time:16.16
``

@seanavery seanavery changed the title Add cgo accessible logging shim Add cgo accessible logging shim for the custom ffmpeg log callback May 22, 2026
Copy link
Copy Markdown

@cheukt cheukt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm once tested on a real robot

@katiepeters
Copy link
Copy Markdown
Contributor

Sweet! Thanks for doing this. Looks like it already has reviewer coverage, so I'm going to bow out

Comment thread cmd/module/cmd.go
vsutils.SetFFmpegLogCallback()
vsutils.SetFFmpegLogCallback(logger)

module, err := module.NewModuleFromArgs(ctx)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cheukt I had to move to NewModule to get the logger working. NewModuleFromArgs logger return seemed to be behaving differently, is that expected?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya NewModuleFromArgs creates a blank logger for you, so having to thread it through makes sense.

@katiepeters katiepeters removed their request for review May 26, 2026 20:55
@seanavery seanavery merged commit 7304924 into viam-modules:main May 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants