Skip to main content

Rockchip Video Codec Examples

Download video codec examples

Example files

The archive contains the media preparation script prepare-video.sh, not video. Install tools first, then extract and prepare media in section 3.

1. Introduction to video codecs​

This guide demonstrates GStreamer hardware transcoding, FFmpeg software codecs, and low-level MPP tools for local playback, recording conversion, and embedded video development.

H.264 / H.265 are codecs, MP4 is a container for video and timing information, and NV12 is a decoded pixel format. A typical workflow is: read MP4 → demux and parse → decode → display, or re-encode and save.

TechnologyRole and example
GStreamerConnect video processing stages; example 1 uses MPP to transcode H.264 MP4, and example 2 extends this to H.265
FFmpegPrepare and inspect media; example 2 uses the libx265 software encoder alongside the hardware path
Rockchip MPPAccess hardware codecs; example 3 directly handles NV12 frames and elementary streams without an MP4 container

2. Environment and tool installation​

2.1 Supported board and image configurations​

The ArmSoM SDK provides these ARM64 image configurations:

SoCBoardsSDK image families
RK3528Sige1Debian 12
RK3576AIM5, CM5 (CM5-IO and CM4 Nano B IO), Sige5Debian 12, Ubuntu 22.04
RK3588 / RK3588SAIM7, CM7S, LM7, Sige7, Sige7SDebian 12, Ubuntu 22.04

Both OS configurations include MPP and the GStreamer Rockchip plugin. On other boards, use the matching official image and verify codec and display support with the examples.

The complete workflow was tested on CM7S with Debian 12 XFCE/X11. HDMI playback requires an active X11 session with XVideo support. Server images can run codecs and skip playback.

Test versions: CM7S (RK3588S), kernel 6.1.118-rk3588, HDMI 1080p60; GStreamer tools 1.22.9-1, Rockchip plugin 1.14-4, and MPP 1.5.0-1.

2.2 Install tools​

Connect to the internet, log into the board's desktop, and install tools in its desktop terminal. Prepare media in section 3.

APT and permissions

On a fresh image, check the clock and repositories using Update the APT package source list. If logged in as root, omit sudo.

sudo apt update
sudo apt install gstreamer1.0-tools ffmpeg curl

These tools run pipelines, process video, and download media. This guide uses system FFmpeg; for FFmpeg's own Rockchip acceleration, see the FFmpeg installation guide. See section 7 for missing MPP elements.

3. Download examples and prepare media​

Create a working directory on the board:

mkdir -p ~/rockchip-video

Use the download button above and place rockchip-video-examples.tar.gz in the board's ~/rockchip-video/, transferring it by SFTP or USB if needed. Then run:

cd ~/rockchip-video
tar -xzf rockchip-video-examples.tar.gz
bash prepare-video.sh

The script downloads Sintel from Blender and extracts eight seconds starting at 12 seconds as a silent 1080p30 H.264 clip.

FileLocation on the boardPurpose
Original trailer~/rockchip-video/sintel-source.mp4A different segment for example 2
Eight-second test clip~/rockchip-video/sintel-1080p.mp4Shared input for examples 1, 2, and 3; 240 frames
Repeated runs and output files

If the clip exists, continue without rerunning the script. GStreamer / MPP may overwrite outputs, so save files you need first. FFmpeg's -n refuses to overwrite them.

Media © Blender Foundation | durian.blender.org · CC BY 3.0. These examples process video only and do not retain audio.

4. Example 1: GStreamer H.264 hardware transcoding​

Decode the clip with MPP, hardware-encode H.264 at a target bitrate of 6 Mbps, and mux it into MP4. The output is ~/rockchip-video/sintel-output-mpp.mp4.

cd ~/rockchip-video
time gst-launch-1.0 -e filesrc location=sintel-1080p.mp4 ! qtdemux ! h264parse \
! mppvideodec ! mpph264enc bps=6000000 ! h264parse ! mp4mux \
! filesink location=sintel-output-mpp.mp4

! connects processing stages, time reports elapsed time, and -e requests EOS when interrupted. For a normal run, wait for Got EOS and command completion so the MP4 container is finalized.

4.1 HDMI playback and file inspection​

Run this command in the board's desktop terminal to play the output over HDMI. fpsdisplaysink reports rendering frame rates in the terminal, and sync=true follows the video's timing.

gst-launch-1.0 -v filesrc location=sintel-output-mpp.mp4 ! qtdemux ! h264parse \
! mppvideodec ! fpsdisplaysink video-sink=xvimagesink text-overlay=false sync=true

Check the codec, dimensions, frame rate, and frame count. Expect h264, 1920×1080, 30/1, and 240 frames:

ffprobe -v error -select_streams v:0 \
-show_entries stream=codec_name,width,height,avg_frame_rate,nb_frames \
-of default=nw=1 sintel-output-mpp.mp4
Display environment

Playback uses the desktop terminal's existing display address. See section 7 for serial or SSH sessions. On a system without a desktop, run transcoding and file inspection and skip HDMI playback.

4.2 CM7S test results​

Sintel 1080p testResult
Output formatH.264, 1920×1080, 30 fps, 240 frames, eight seconds
Decode-only time0.322 seconds
Decode, encode, and mux time1.310 seconds
Output size5,355,119 bytes
HDMI playbackNormal EOS, exit code 0; last periodic sample: 236 rendered frames, zero dropped frames, 30.23 fps average

CM7S XFCE desktop playing the hardware-transcoded Sintel clip

Interpreting frame rates

Timings are single-run results. The last periodic playback sample precedes EOS and counts submitted frames, not the final frame total or the monitor's refresh rate.

Optional: measure decoding time alone

This command decodes without displaying frames. sync=false removes playback pacing to measure processing time.

cd ~/rockchip-video
time gst-launch-1.0 filesrc location=sintel-1080p.mp4 ! qtdemux \
! h264parse ! mppvideodec ! fakesink sync=false

5. Example 2: H.265 software and hardware codecs​

5.1 FFmpeg software encoding and decoding​

Use system FFmpeg's CPU encoder, libx265, to explore the software path alongside hardware encoding. Extract four seconds starting at 19 seconds in the original trailer. Output is ~/rockchip-video/advanced/sintel-ffmpeg-hevc.mp4.

mkdir -p ~/rockchip-video/advanced
cd ~/rockchip-video/advanced
ffmpeg -nostdin -n -ss 19 -i ../sintel-source.mp4 -t 4 -an -r 30 \
-c:v libx265 -preset ultrafast -x265-params pools=2 -pix_fmt yuv420p sintel-ffmpeg-hevc.mp4

First check the file with FFmpeg software decoding (no errors on success), then use MPP hardware decoding for HDMI playback:

ffmpeg -nostdin -v error -xerror -i sintel-ffmpeg-hevc.mp4 -f null -
gst-launch-1.0 filesrc location=sintel-ffmpeg-hevc.mp4 ! qtdemux \
! h265parse ! mppvideodec ! xvimagesink

On CM7S, encoding 120 frames took 23.25 seconds (5.16 fps); software decoding exited with code 0. The screenshot shows that output playing through MPP.

CM7S FFmpeg H.265 output playback

5.2 GStreamer hardware encoding and decoding​

Use the eight-second clip from section 3 with the mpph265enc hardware encoder. Output is ~/rockchip-video/advanced/output-hevc.mp4. This section can run independently of section 5.1.

mkdir -p ~/rockchip-video/advanced
cd ~/rockchip-video/advanced
gst-launch-1.0 -e filesrc location=../sintel-1080p.mp4 ! qtdemux ! h264parse \
! mppvideodec ! mpph265enc bps=6000000 ! h265parse ! mp4mux \
! filesink location=output-hevc.mp4

Then hardware-decode the output and inspect its video properties. The first command uses fakesink without opening a window; normal EOS means the pipeline reached the end.

gst-launch-1.0 filesrc location=output-hevc.mp4 ! qtdemux ! h265parse \
! mppvideodec ! fakesink sync=false
ffprobe -v error -select_streams v:0 \
-show_entries stream=codec_name,width,height,avg_frame_rate,nb_frames \
-of default=nw=1 output-hevc.mp4

Both pipelines exited normally on CM7S. The output was HEVC, 1920×1080, 30 fps, 240 frames. This section verifies file transcoding and decoding without a window; the screenshot above belongs to section 5.1. The two sections use different clip lengths and are not a controlled performance comparison.

6. Example 3: MPP raw frames and elementary streams​

Complete sections 3 and 5.2 and reserve 400 MiB of space. Use the decoder mpi_dec_test and encoder mpi_enc_test from the official image’s rockchip-mpp-demos (tested version 1.5.0-1).

6.1 Decode and re-encode​

Enter the output directory, extract H.264, decode to NV12, and hardware-encode 60 frames:

cd ~/rockchip-video/advanced
ffmpeg -nostdin -n -i ../sintel-1080p.mp4 -an -c:v copy -bsf:v h264_mp4toannexb input.h264
mpi_dec_test -i input.h264 -t 7 -n 60 -f 0 -o decoded.nv12
mpi_enc_test -i decoded.nv12 -w 1920 -h 1080 -hstride 1920 -vstride 1080 \
-f 0 -t 7 -n 60 -fps 30 -bps 6000000 -o encoded.h264

Repeat for H.265 using the output from section 5.2:

ffmpeg -nostdin -n -i output-hevc.mp4 -an -c:v copy -bsf:v hevc_mp4toannexb input.hevc
mpi_dec_test -i input.hevc -t 16777220 -n 60 -f 0 -o decoded-hevc.nv12
mpi_enc_test -i decoded-hevc.nv12 -w 1920 -h 1080 -hstride 1920 -vstride 1080 \
-f 0 -t 16777220 -n 60 -fps 30 -bps 6000000 -o encoded.hevc
ParameterMeaning
-c:v copy and *_mp4toannexbExtract an Annex B elementary stream from MP4 without re-encoding
MPP -t 7 / -t 16777220H.264 / H.265
MPP -f 0, -n 60NV12 pixel format; process 60 frames
-hstride, -vstrideRaw-frame row and vertical strides; 1920 and 1080 in this example
Raw-frame layout

Each exported NV12 file in this test was 186,624,000 bytes and tightly packed. For other resolutions or direct hardware-buffer access, obtain strides from the actual frame metadata instead of copying these values.

6.2 Inspect and play back​

Inspect both encoded streams. Each was verified as 1920×1080 with 60 frames. All outputs are in ~/rockchip-video/advanced/:

for file in encoded.h264 encoded.hevc; do
ffprobe -v error -count_frames -select_streams v:0 \
-show_entries stream=codec_name,width,height,nb_read_frames -of default=nw=1 "$file"
done
CodecDecoded outputHardware-encoded output
H.264decoded.nv12encoded.h264
H.265decoded-hevc.nv12encoded.hevc

Play the HEVC elementary stream directly. It has no MP4 container and does not need qtdemux:

gst-launch-1.0 filesrc location=encoded.hevc ! h265parse ! mppvideodec ! xvimagesink

CM7S MPP HEVC elementary stream playback

Screenshot media: Sintel © Blender Foundation | durian.blender.org · CC BY 3.0.

7. Troubleshooting​

SymptomAction
APT or downloads report clock, certificate, or repository errorsFollow Update the APT package source list to correct the clock and check repositories
Missing input file or advanced directoryComplete section 3 first; section 5 creates the directory with mkdir -p. Use a directory after cd, not an .mp4 file
no element or missing MPP toolsCheck the elements below and use the matching official board image and Rockchip packages
Output exists but no HDMI window opensLog into the board's X11 desktop and run playback in its terminal; serial/SSH also requires a display address and access permissions
MP4 cannot be readWait for normal EOS before checking the output; an interrupted run may leave an unfinished container
Check missing GStreamer elements and MPP tools

gst-inspect-1.0 only queries elements. If it reports Missing:, install the corresponding plugin. Generic GStreamer tools do not include Rockchip plugins.

for element in qtdemux h264parse h265parse mppvideodec mpph264enc mpph265enc mp4mux fpsdisplaysink xvimagesink; do
gst-inspect-1.0 "$element" >/dev/null || { echo "Missing: $element"; break; }
done
command -v mpi_dec_test mpi_enc_test
Open an HDMI window from serial or SSH

First check the display address in a terminal on the board's desktop:

echo $DISPLAY

If the result is :0, set this in the serial or SSH terminal:

export DISPLAY=:0

Use the actual display address and a user authorized to access the desktop; setting DISPLAY alone does not grant access.

This guide uses xvimagesink; tests with ximagesink had format negotiation or dropped-frame problems. Ensure the desktop supports XVideo.

Contact us