Skip to content

Hardware Video (MFC) & JPEG Codecs

Google Tensor GS101 includes Samsung’s Exynos MFC v14 hardware video codec engine (/dev/video6 decode, /dev/video7 encode) and Exynos SMFC hardware JPEG engine (/dev/video12). Because stock FFmpeg v4l2m2m fails on Exynos MFC’s strict DMA-BUF, plane-ordering, and EOS ioctl requirements, headless-phone ships purpose-built zero-copy V4L2 M2M CLIs.

Engine Device Node Codecs / Formats Measured Live Speed
MFC Encode /dev/video7 + /dev/dma_heap/system H.264, HEVC, VP8, VP9 251 FPS 1080p H.264; 84.8 FPS 4K HEVC at 0.67 W SoC
MFC Decode /dev/video6 + /dev/dma_heap/system H.264, HEVC, VP8, VP9, AV1 464.7 FPS 1080p H.264; 156.6 FPS 4K HEVC
SMFC JPEG /dev/video12 (USERPTR) Baseline JFIF (nv12, rgb24, bgr24, yuyv) 3.7 ms 720p enc / 4.6 ms dec; 28.5 ms 4K enc

Allocates zero-copy V4L2_MEMORY_DMABUF buffers from /dev/dma_heap/system (requires sudo because /dev/dma_heap/system is root-only by default), automatically enables frame rate control, GOP sizing, SPS/PPS prepending on H.264/HEVC IDR frames, and IVF framing for VP8/VP9.

Requires ffmpeg (sudo apt install ffmpeg) to decode/demux the input and mux .mp4/.mkv/.webm output (adds -movflags +faststart on .mp4, forces TCP on rtsp://, and copies audio from local files unless --no-audio is set):

Terminal window
# Transcode a file to hardware HEVC MP4
sudo mfc-encode -i input.mp4 --codec hevc --bitrate 8M -o out_hevc.mp4
# Synthetic 4K HEVC test pattern (5s @ 30 fps)
sudo mfc-encode \
--test-pattern --width 3840 --height 2160 --fps 30 --duration 5 \
--codec hevc --bitrate 15M -o out_4k.mp4
Flag Default Description
-i, --input <STR> (none) Input file, stream URL, or - for stdin (omit when using --test-pattern).
-o, --output <STR> (required) Output container (.mp4/.mkv/.ts/.m2ts/.mov/.webm), raw bitstream (.h264/.hevc/.ivf/.vp8/.vp9), or - for stdout.
--raw-nv12 Off Read packed NV12 frames directly without ffmpeg (requires --input, --width, --height).
--test-pattern Off Generate synthetic ffmpeg testsrc2 input (defaults: 1920×1080, 30.0 fps, 5.0 s).
--codec h264 h264, hevc, vp8, or vp9.
--width, --height Auto / 1920×1080 Even integers >= 32 (must be given together).
--fps <FLOAT> Probed / 30.0 Frame rate.
--duration <FLOAT> Full / 5.0 Optional duration cap in seconds (ffmpeg / --test-pattern mode).
--bitrate <STR> 4000000 Target bitrate in bps, or with k/M suffix (e.g. 2.5M, 500k).
--gop <INT> 60 Keyframe interval (>= 1).
--no-audio Off Omit audio copy when muxing local container files.
--device / --dma-heap /dev/video7 / /dev/dma_heap/system V4L2 encoder node and DMA-BUF heap path.
--out-buffers / --cap-buffers 4 / 4 V4L2 output and capture queue depths (>= 1).
-v, --verbose Off Log V4L2 negotiation and redacted ffmpeg commands to stderr.

Decodes raw Annex-B/IVF bitstreams or container files (.mp4/.mkv/.ts/.m2ts/.mov/.webm/.avi, demuxed with ffmpeg -c:v copy — zero CPU video decoding) into cropped visible NV12 frames via /dev/video6 and /dev/dma_heap/system.

Terminal window
# Benchmark hardware decode throughput without writing pixels
sudo mfc-decode clip.mp4 --null --json
# Decode first 100 frames of a 4K HEVC bitstream to raw NV12
sudo mfc-decode clip.hevc --codec hevc --max-frames 100 -o decoded.nv12
# Stream decoded NV12 to stdout while logging JSON stats to stderr
sudo mfc-decode clip.mp4 -o - --json > frames.nv12
Flag / Argument Default Description
input (positional) (required) Input bitstream (.h264/.hevc/.vp8/.vp9/.av1/.ivf) or container (.mp4/.mkv/.webm/...).
-o, --output <STR> "" Output raw NV12 path, - for stdout, or omit / --null for benchmark-only decode.
--null Off Hardware decode without writing pixel output.
--codec auto auto, h264, hevc, vp8, vp9, or av1.
--max-frames <INT> 0 (all) Stop after decoding N frames.
--device / --dma-heap /dev/video6 / /dev/dma_heap/system V4L2 decoder node and DMA-BUF heap path.
--json Off Emit decode statistics as JSON (sent to stderr when -o -).

Drives Samsung Exynos SMFC (/dev/video12) via V4L2_MEMORY_USERPTR. Because /dev/video12 is accessible to the video group, hw-jpeg works without sudo for the default user.

Terminal window
# Encode a P6 PPM image to hardware JPEG (auto-detects dimensions & rgb24)
hw-jpeg encode frame.ppm -o frame.jpg --quality 90
# Encode raw NV12 pixels from camera-ctl snapshot
hw-jpeg encode frame.nv12 -o frame.jpg --pix-fmt nv12 --width 1280 --height 720 -q 85
# Decode a baseline JFIF JPEG back to P6 PPM or raw NV12
hw-jpeg decode frame.jpg -o decoded.ppm
hw-jpeg decode frame.jpg -o decoded.nv12 --pix-fmt nv12
# Run an in-memory hardware encode + decode round-trip benchmark
hw-jpeg benchmark --width 3840 --height 2160 --pix-fmt nv12 --iters 20 --json

Top-level option: --device <PATH> (default /dev/video12). Supported --pix-fmt: nv12, rgb24, bgr24, yuyv. Dimensions: 16..16384. Baseline SOF0 JFIF only (progressive SOF2 JPEGs are explicitly rejected).

Subcommand Arguments & Defaults
encode <input> (positional), -o/--output <PATH> (required), --pix-fmt rgb24, --width 0 (auto for .ppm), --height 0, -q/--quality 90 (1..100)
decode <input> (positional), -o/--output <PATH> (required), --pix-fmt rgb24 (auto rgb24 if output ends in .ppm)
benchmark --width 1280, --height 720, --pix-fmt nv12, -q/--quality 90, --iters 10, --json