VPU
The VPU (Video Processing Unit) is a hardware video codec engine that improves codec efficiency and reduces CPU load. The K3 VPU is implemented on top of the V4L2 framework.
- Decoding support: H.264 / HEVC / VP8 / VP9 / VC-1 / MJPEG / MPEG-4 / MPEG-2
- Encoding support: H.264 / HEVC / VP8 / VP9 / MJPEG
- Features: Provides complete test programs for development and functional verification.
1 Specifications
1.1 Decoding Specifications (4 cores @ 1 GHz)
| Format | Profile | Maximum resolution | Maximum bitrate | Single-channel specification | Multi-channel specification |
|---|---|---|---|---|---|
| HEVC | Main/Main10 | 4096×4096 | 400Mbps | 4k@180fps | 24 channels 1080P@30fps |
| H.264 | BP/MP/HP/High10 | 4096×4096 | 400Mbps | 4k@180fps | 24 channels 1080P@30fps |
| VP8 | / | 2048×2048 | 400Mbps | 4k@120fps | 16 channels 1080P@30fps |
| VP9 | Profile0/Profile 2 10-bit | 4096×4096 | 400Mbps | 4k@180fps | 24 channels 1080P@30fps |
| VC-1 | SP/MP/AP | 2048×4096 | 160Mbps | 4k@120fps | 16 channels 1080P@30fps |
| JPEG | Baseline sequential | 8192×8192 | 240Mbps | 4k@120fps | 16 channels 1080P@30fps |
| MPEG4 | SP/ASP | 2048×2048 | 160Mbps | 4k@120fps | 16 channels 1080P@30fps |
| MPEG2 | MP | 4096×4096 | 160Mbps | 4k@120fps | 16 channels 1080P@30fps |
1.2 Encoding Specifications (4 cores @ 1 GHz)
| Format | Profile | Maximum resolution | Maximum bitrate | Single-channel specification | Multi-channel specification |
|---|---|---|---|---|---|
| HEVC | Main/Main10 | 4096×4096 | 400Mbps | 4k@90fps | 12 channels 1080P@30fps |
| H.264 | BP/MP/HP/High10 | 4096×4096 | 400Mbps | 4k@90fps | 12 channels 1080P@30fps |
| VP8 | / | 2048×2048 | 400Mbps | 4k@90fps | 12 channels 1080P@30fps |
| VP9 | Profile0/Profile 2 10-bit | 4096×4096 | 400Mbps | 4k@90fps | 12 channels 1080P@30fps |
| JPEG | Baseline sequential | 8192×8192 | 720Mbps | 4k@90fps | 12 channels 1080P@30fps |
2 VPU Test Program
k3x-vpu-test is a set of programs used to test the functionality and performance of the K3 VPU. It also serves as a reference for application development that interfaces with the VPU for hardware encoding and decoding.
2.1 Installation Instructions
2.1.1 Bianbu Desktop System
k3x-vpu-test is included in the software repository and can be installed with apt.
sudo apt update
sudo apt install k3x-vpu-test
2.1.2 Buildroot System
There are two ways to integrate k3x-vpu-test into the system:
- Enable the
k3x-vpu-testbuild and integration option when building the image. This option is enabled by default, so the image includes the relatedk3x-vpu-testprograms. - If this option is disabled,
k3x-vpu-testcan be compiled manually, and the generated binaries can be copied to/usr/bin/in the target system. The binaries are listed below.
2.2 Usage Instructions
The k3x-vpu-test suite includes the following programs:
mvx_decoder: Used for single-channel video bitstream decoding tests.mvx_decoder_multi: Used for multi-channel video bitstream decoding tests. Multi-channel video bitstreams must use the same source video.mvx_encoder: Used for single-channel video bitstream encoding tests.mvx_encoder_multi: Used for multi-channel YUV stream encoding tests. Multi-channel YUV streams must use the same source stream.mvx_logd: Used to capture firmware logs for issue analysis and debugging.
2.2.1 mvx_decoder
Basic usage examples:
///Decode H.264 video stream (with startcode) from input.264 to output.yuv
//-f raw : represents raw video stream
//Default input encoding format is H.264
//Default output YUV pixel format is YUV420P
mvx_decoder -f raw /mnt/streams/input.264 /mnt/test/output.yuv
//Decode H.264 video stream (with startcode) from input.264 to output.yuv, with output pixel format set to NV12
mvx_decoder -f raw -o yuv420_nv12 /mnt/streams/input.264 /mnt/test/output.yuv
///Decode HEVC video stream (with startcode) from input.265 to output.yuv
mvx_decoder -f raw -i hevc /mnt/streams/input.265 /mnt/test/output.yuv
Parameter description:
usage: ./mvx_decoder [optional] [positional]
positional arguments:
input
Input file.
output
Output file.
optional arguments:
--dev
Device.
Default: /dev/video0
-i, --inputformat
Pixel format.
Default: h264
-o, --outputformat
Output pixel format.
Default: yuv420
-f, --format
Input container format. [ivf, rcv, raw]
For ivf input format will be taken from IVF header.
Default: ivf
-s, --stride
Stride alignment.
Default: 1
-y, --intbuf
Limit of intermediate buffer size
Default: 1000000
-m, --md5
Output md5 file
-e, --md5ref
Input ref md5 file
-u, --nalu
Nalu format, START_CODES (0) and ONE_NALU_PER_BUFFER (1), ONE_BYTE_LENGTH_FIELD (2), TWO_BYTE_LENGTH_FIELD (3), FOUR_BYTE_LENGTH_FIELD (3).
Default: 0
-r, --rotate
Rotation, 0 | 90 | 180 | 270
Default: 0
-d, --downscale
Down Scale, 1 | 2 | 4
Default: 1
-v, --fps
Frame rate.
Default: 24
--dsl_ratio_hor
Horizontal downscale ratio, [1, 256]
Default: 0
--dsl_ratio_ver
Vertical downscale ratio, [1, 128]
Default: 0
--dsl_frame_width
Downscaled frame width in pixels
Default: 0
--dsl_frame_height
Downscaled frame height in pixels
Default: 0
--dsl_pos_mode
Flexible Downscaled original position mode [0, 2],
only availble in high precision mode.
Value: 0 [default:x_original=(x_resized + 0.5)/scale - 0.5]
Value: 1 [x_original=x_resized/scale]
Value: 2 [x_original=(x_resized+0.5)/scale]
Default: 0
--frames
nr of frames to process
Default: 0
--fro
Frame reordering 1 is on (default), 0 is off
Default: 1
--ish
Ignore Stream Headers 1 is on, 0 is off (default)
Default: 0
--trystop
Try if Decoding Stop Command exists
Default: 0
--one_frame_per_packet
Each input buffer contains one frame.
Default: 0
-n, --interlaced
Frames are interlaced
Default: 0
--tiled
Use tiles for AFBC formats.
Default: disabled
--preload
preload the input stream to memory.
the size for input file should be less than 15MBytes.
Default: 0
--fw_timeout
timeout value[secs] for watchdog timeout. range: 5~60.
Default: 5
--profiling
enable profiling for bandwidth statistics . 0:disable; 1:enable.
Default: 0
2.2.2 mvx_decoder_multi
Basic usage examples:
// Decode the H.264 video stream (with start code) from input.264 to output.yuv using 4 concurrent decoding sessions.
// The default input encoding format is H.264.
// The default output YUV pixel format is YUV420P.
mvx_decoder_multi -n 4 /mnt/streams/input.264 /mnt/test/output.yuv
// Decode the HEVC video stream (with start code) from input.265 to output.yuv using 4 concurrent decoding sessions. The pixel format of output.yuv is NV21.
mvx_decoder_multi -n 4 -i hevc -o yuv420_nv21 /mnt/streams/input.265 /mnt/test/output.yuv
Parameter description:
usage: ./mvx_decoder_multi [optional] [positional]
positional arguments:
input
Input file.
output
Output file.
optional arguments:
--dev
Device.
Default: /dev/video0
-i, --inputformat
Pixel format.
Default: h264
-o, --outputformat
Output pixel format.
Default: yuv420
-s, --stride
Stride alignment.
Default: 1
-n, --nsessions
Number of sessions.
Default: 1
2.2.3 mvx_encoder
Basic usage examples:
// Encode the YUV420P stream from input.yuv to an H.264 video stream (with start code) in output.264.
// The default input YUV pixel format is YUV420P.
// The default output video encoding format is H.264.
mvx_encoder -f raw -w 1280 -h 720 /mnt/streams/input.yuv /mnt/test/output.264
// Encode the NV21 stream from input.yuv to an HEVC video stream (with start code) in output.265.
mvx_encoder -f raw -w 1280 -h 720 -i yuv420_nv21 -o hevc /mnt/streams/input.yuv /mnt/test/output.265
Parameter description:
usage: ./mvx_encoder [optional] [positional]
positional arguments:
input
Input file.
output
Output file.
optional arguments:
--dev
Device.
Default: /dev/video0
-i, --inputformat
Pixel format.
Default: yuv420
-o, --outputformat
Output pixel format.
Default: h264
-f, --format
Output container format. [ivf, raw]
Default: ivf
-w, --width
Width.
Default: 1920
-h, --height
Height.
Default: 1080
-s, --stride
Stride alignment.
Default: 1
--mirror
mirror, 1 : horizontal; 2 : vertical.
Default: 0
--roi_cfg
ROI config file.
--frames
nr of frames to process
Default: 0
--epr_cfg
Encode Parameter Records config file name
--rate_control
Selects rate control type, constant/variable/off
Default: off
--target_bitrate
If rate control is enabled, this option sets target bitrate
Default: 0
--max_bitrate
If rate control is enabled, this option sets maximum bitrate
Default: 0
--gop
GOP: 0 is None, 1 is Bidi, 2 is Low delay, 3 is Pyramid
Default: 0
--pframes
Number of P frames
Default: 0
--bframes
Number of B frames
Default: 0
-n, --minqp
H264 min QP
Default: 0
-m, --maxqp
H264 max QP
Default: 51
-t, --tier
Profile.
Default: 2
-l, --level
Level.
Default: 1
-v, --fps
Frame rate.
Default: 24
--ecm
0 is CAVLC, 1 is CABAC
Default: 1
--bitdepth
Set other bitdepth
Default: 8
-q, --fixedqp
H264 fixed QP for I P B frames.
If it is combined with -x, the value will later be increased with 2.
Default: 20
--qpi
H264 fixed QP for I frames.
Default: 20
--qpb
H264 fixed QP for B frames.
Default: 20
--qpp
H264 fixed QP for P frames.
Default: 20
--crop_left
encoder SPS crop param, left offset
Default: 0
--crop_right
encoder SPS crop param, right offset
Default: 0
--crop_top
encoder SPS crop param, top offset
Default: 0
--crop_bottom
encoder SPS crop param, bottom offset
Default: 0
--colour_description_range
VUI param: Colour description; range
Value: 0=Unspecified, 1=Limited, 2=Full
Default: 0
--colour_primaries
VUI param: Colour description;
colour primaries (0-255, see hevc spec. E.3.1)
Value: 0=Unspecified,
1=BT709,
2=BT470M,
3=BT601_625,
4=T601_525,
5=GENERIC_FILM,
6=BT2020
Default: 0
--transfer_characteristics
VUI param: Colour description;
transfer characteristics (0-255, see hevc spec. E.3.1)
Value: 0=Unspecified,
1=LINEAR,
2=SRGB,
3=SMPTE170M,
4=GAMMA22,
5=GAMMA28,
6=ST2084,
7=HLG,
8=SMPTE240M,
9=XVYCC,
10=BT1361,
11=ST428
Default: 0
--matrix_coeff
VUI param: Colour description;
matrix coefficients (0-255, see hevc spec. E.3.1)
Value: 0=Unspecified,
1=BT709,
2=BT470M,
3=BT601,
4=SMPTE240M,
5=T2020,
6=BT2020Constant
Default: 0
--time_scale
VUI param: vui_time_scale
Default: 0
--num_units_in_tick
VUI param: vui_num_units_in_tick
Default: 0
--aspect_ratio_idc
VUI param: aspect_ratio_idc. [0,255]
Default: 0
--sar_width
VUI param: sar_width
Default: 0
--sar_height
VUI param: sar_height
Default: 0
--video_format
VUI param: video_format. (0-5, see hevc spec. E.3.1)
Value: 0=Component, 2=PAL, 2=NTSC, 3=SECAM, 4=MAC, 5=Unspecified
Default: 0
--sei_mastering_display
SEI param : mastering display 's parameters
Default: 0
--sei_content_light
SEI param : sei_content_light
Default: 0
--sei_user_data_unregistered
SEI param : user data unregistered
Default: 0
--hrd_buffer_size
Hypothetical Reference Decoder buffer size
relative to the bitrate (in seconds) for rate control Value: should bigger than target_bitrate/fps on normal case
Default: 0
--ltr_mode
encoder long term reference mode,range from 1 to 8 (inclusive)
1: LDP-method-1 |
2: LDP-method-2 |
3: LDB-method-1 |
4: LDB-method-2
5: BiDirection-method-1 |
6: BiDirection-method-2 |
7: Pyramid-method-1 |
8: Pyramid-method-2
Default: 0
--ltr_period
encoder long term reference period, range from 2 to 254 (inclusive)
Default: 0
--trystop
Try if Encoding Stop Command exists
Default: 0
--restart_interval
JPEG restart interval.
Default: -1
--quality
JPEG compression quality. [1-100, 0 - default]
Default: 0
--preload
preload the first 5 yuv frames to memory.
Default: 0
--fw_timeout
timeout value[secs] for watchdog timeout. range: 5~60.
Default: 5
--profiling
enable profiling for bandwidth statistics . 0:disable; 1:enable.
Default: 0
2.2.4 mvx_encoder_multi
Basic usage examples:
// Encode the YUV420P stream from input.yuv into an H.264 video stream (with start code) in output.264 using 4 concurrent encoding sessions.
mvx_encoder_multi -n 4 -w 1280 -h 720 /mnt/streams/input.yuv /mnt/test/output.264
// Encode the NV21 stream from input.yuv into an HEVC video stream (with start code) in output.265 using 4 concurrent encoding sessions.
mvx_encoder_multi -n 4 -w 1280 -h 720 -i yuv420_nv21 -o hevc /mnt/streams/input.yuv /mnt/test/output.265
Parameter description:
usage: ./mvx_encoder_multi [optional] [positional]
positional arguments:
input
Input file.
output
Output file.
optional arguments:
--dev
Device.
Default: /dev/video0
-i, --inputformat
Pixel format.
Default: yuv420
-o, --outputformat
Output pixel format.
Default: h264
-s, --stride
Stride alignment.
Default: 1
-w, --width
Stride alignment.
Default: 1280
-h, --height
Stride alignment.
Default: 720
-f, --frames
Specified frame count to be processed.
Default: 0
-n, --nsessions
Number of sessions.
Default: 1
2.2.5 mvx_logd
Basic usage examples:
// Mount debugfs to save firmware logs to a file
mount -t debugfs none /sys/kernel/debug
// Clear logs
mvx_logd -C
// Set the log save path and format
mvx_logd -d -f text xxx.log
// Start video playback
// Check xxx.log
Parameter description:
Usage: ./mvx_logd [OPTIONS] [DST]
Positional arguments:
DST
Output file (default stdout).
Optional arguments:
-h
--help This help message.
-C
Clear ring buffer.
-c
Clear ring buffer after first printing its contents.
-d
Daemonize process. DST file is expected in this case.
--follow
Keep on reading.
-f
Format.
text Text format (default).
bin Binary format.
json Java Script Object Notation.
-i
Input file (default /sys/kernel/debug/amvx/log/drain/ram0/msg).
-t
Adjust for timezone differences.
Example:
Print and clear log.
# mvx_logd -c
Run in daemon mode.
# mvx_logd -d -f bin fw.log
Unpack binary log and adjust for timezone differences.
# mvx_logd -t -1 fw.log
2.3 Code Structure
The k3x-vpu-test source code is located at:
package-src/k3x-vpu-test
Source code structure:
|-- CMakeLists.txt //cmake build script
|-- debian ///configurations and scripts for deb package building
|-- format.sh //code style formatting script, formated in Google style
|-- include //important header file
| |-- fw_v2
| | `-- mve_protocol_def.h
| |-- md5.h
| |-- mvx_argparse.h
| |-- mvx_list.h
| |-- mvx_log_ram.h
| `-- mvx-v4l2-controls.h //Additional APIs for VPU driver
|-- test
| |-- coverage
| |-- md5 //md5 API and implementation
| | |-- CMakeLists.txt
| | |-- md5.c
| | `-- md5.h
| |-- mvx_player //test program set implementation code
| | |-- CMakeLists.txt
| | |-- dmabufheap //dmabuf management API and implementation
| | | |-- BufferAllocator.cpp
| | | |-- BufferAllocator.h
| | | |-- BufferAllocatorWrapper.cpp
| | | |-- BufferAllocatorWrapper.h
| | | `-- dmabufheap-defs.h
| | |-- mvx_decoder.cpp //mvx_decoder implementation
| | |-- mvx_decoder_multi.cpp //mvx_decoder_multi implementation
| | |-- mvx_encoder.cpp //mvx_encoder implementation
| | |-- mvx_encoder_gen.cpp //mvx_encoder_gen implementation
| | |-- mvx_encoder_multi.cpp //mvx_encoder_multi implementation
| | |-- mvx_info.cpp //mvx_info implementation
| | |-- mvx_player.cpp //core logic encapsulation implementation
| | |-- mvx_player.hpp //core logic encapsulation API
| | `-- reader //bitsream reading API and implementation
| | |-- parser.h
| | `-- read_util.h
| |-- userptr
| | |-- CMakeLists.txt
| | `-- mvx_userptr.cpp
| `-- utils //utils
| |-- CMakeLists.txt
| |-- mvx_argparse.c
| |-- mvx_argparse.h
| `-- mvx_list.h
`-- tools
|-- logd //logd implementation, capture VPU firmware logs
| |-- CMakeLists.txt
| |-- mvx_logd.cpp
| |-- mvx_logd_fwif_v2.cpp
| `-- mvx_logd.hpp
`-- securevideo ///for security video testing (use not verified)
|-- 50-mvx.rules
|-- mvx_securehelper.cpp
|-- mvx_secureplayer.cpp
|-- mvx_securevideo.cpp
`-- mvx_securevideo.hpp
2.4 Compilation Instructions
Bianbu Desktop System
cd k3x-vpu-test
sudo apt-get build-dep k3x-vpu-test #install dependencies
dpkg-buildpackage -us -uc -nc -b -j32
Buildroot System
cd k3x-vpu-test
mkdir out
cd out
cmake ..
make
make install
2.5 Debugging
2.5.1 Adding Logs
Add logs with printf or fprintf, then recompile and reinstall the program.
2.5.2 Successful Decoding Logs
- Single-channel decoding
/mnt/tool # ./mvx_decoder -f raw /mnt/streams/h264dec/Zhling_1280x720.264 /mnt/test/output.yuv //input command
Opening '/dev/video0'.
Enumerate frame size. index=0, pixel_format=32314d59, min_width=2, max_width=8192, step_width=2, min_height=2, max_height=8192, step_height=2
Format: type=2, format=875967048, width=0, height=0, sizeimage=1048576, bytesperline=0, interlaced:1
Format: type=9, format=842091865, width=0, height=0, nplanes=3, bytesperline=[0, 0, 0], sizeimage=[0, 0, 0], interlaced:1
Request buffers. type=2, count=6, memory=4
Query: type=2, index=0, sequence=0, timestamp={0, 0}, flags=4000, bytesused=0, length=1048576
Query: type=2, index=1, sequence=0, timestamp={0, 0}, flags=4000, bytesused=0, length=1048576
Query: type=2, index=2, sequence=0, timestamp={0, 0}, flags=4000, bytesused=0, length=1048576
Query: type=2, index=3, sequence=0, timestamp={0, 0}, flags=4000, bytesused=0, length=1048576
Query: type=2, index=4, sequence=0, timestamp={0, 0}, flags=4000, bytesused=0, length=1048576
Query: type=2, index=5, sequence=0, timestamp={0, 0}, flags=4000, bytesused=0, length=1048576
Request buffers. type=9, count=1, memory=4
Query: type=9, index=0, sequence=0, timestamp={0, 0}, flags=4000, num_planes=3, bytesused=[0, 0, 0], length=[1, 1, 1], offset=[0, 0, 0]
//request input and output buffer
Stream on 2
Stream on 9
//input/output open streams
Event. type=5.
source changed. should reset output stream.
Stream off 9
Request buffers. type=9, count=0, memory=4
Format: type=9, format=842091865, width=1280, height=720, nplanes=3, bytesperline=[1280, 640, 640], sizeimage=[921600, 230400, 230400], interlaced:1
Request buffers. type=9, count=4, memory=4
Query: type=9, index=0, sequence=0, timestamp={0, 0}, flags=4000, num_planes=3, bytesused=[0, 0, 0], length=[921600, 230400, 230400], offset=[0, 0, 0]
Query: type=9, index=1, sequence=0, timestamp={0, 0}, flags=4000, num_planes=3, bytesused=[0, 0, 0], length=[921600, 230400, 230400], offset=[0, 0, 0]
Query: type=9, index=2, sequence=0, timestamp={0, 0}, flags=4000, num_planes=3, bytesused=[0, 0, 0], length=[921600, 230400, 230400], offset=[0, 0, 0]
Query: type=9, index=3, sequence=0, timestamp={0, 0}, flags=4000, num_planes=3, bytesused=[0, 0, 0], length=[921600, 230400, 230400], offset=[0, 0, 0]
Stream on 9
// After receiving the resolution change message, close the output stream, reallocate the output buffer, and reopen the output stream.
-----Decoder. set timestart_us: 15432355548 us---------
// Start decoding
Capture EOS.
-----[Test Result] MVX Decode Done. frames_processed: 18, cost time: 16604176 us.
Stream off 2
Stream off 9
-----[Test Result] MVX Decode PASS. Average Framerate: 1.08.
Total size 26265600
Closing fd 5.
// Decoding completed. Output information is printed, and the program exits.
- Multi-channel decoding
/mnt/tool # ./mvx_decoder_multi -n 4 /mnt/streams/h264dec/foreman_128x64.264 /mnt/test/output.yuv
// Command
-----Decoder. set timestart_us: 16076598695 us---------
-----Decoder. set timestart_us: 16076606348 us---------
-----Decoder. set timestart_us: 16076569259 us---------
-----Decoder. set timestart_us: 16076788196 us---------
// Start decoding
-----[Test Result] MVX Decode Done. frames_processed: 2, cost time: 148367 us.
-----[Test Result] MVX Decode Done. frames_processed: 2, cost time: 250563 us.
-----[Test Result] MVX Decode Done. frames_processed: 2, cost time: 217680 us.
-----[Test Result] MVX Decode Done. frames_processed: 2, cost time: 279399 us.
Total size 36864
Total size 36864
Total size 36864
Total size 36864
// Decoding completed. Output information is printed, and the program exits.
2.5.3 Successful Encoding Logs
- Single-channel encoding
/mnt/tool # ./mvx_encoder -f raw -w 1280 -h 720 /mnt/streams/yuv/zhling_1280x720.yuv /mnt/test/output.264
// Command
Opening '/dev/video0'.
setEncFramerate( 1966080 )
setRateControl( 0,0,0)
Enumerate frame size. index=0, pixel_format=34363248, min_width=2, max_width=8192, step_width=2, min_height=2, max_height=8192, step_height=2
Format: type=10, format=842091865, width=1280, height=720, nplanes=3, bytesperline=[1280, 640, 640], sizeimage=[921600, 230400, 230400], interlaced:1
Format: type=9, format=875967048, width=1280, height=720, nplanes=1, bytesperline=[0, 0, 0], sizeimage=[921600, 0, 0], interlaced:1
Request buffers. type=10, count=3, memory=4
Query: type=10, index=0, sequence=0, timestamp={0, 0}, flags=4000, num_planes=3, bytesused=[0, 0, 0], length=[921600, 230400, 230400], offset=[0, 0, 0]
Query: type=10, index=1, sequence=0, timestamp={0, 0}, flags=4000, num_planes=3, bytesused=[0, 0, 0], length=[921600, 230400, 230400], offset=[0, 0, 0]
Query: type=10, index=2, sequence=0, timestamp={0, 0}, flags=4000, num_planes=3, bytesused=[0, 0, 0], length=[921600, 230400, 230400], offset=[0, 0, 0]
Request buffers. type=9, count=9, memory=4
Query: type=9, index=0, sequence=0, timestamp={0, 0}, flags=4000, num_planes=1, bytesused=[0], length=[921600], offset=[0]
Query: type=9, index=1, sequence=0, timestamp={0, 0}, flags=4000, num_planes=1, bytesused=[0], length=[921600], offset=[0]
Query: type=9, index=2, sequence=0, timestamp={0, 0}, flags=4000, num_planes=1, bytesused=[0], length=[921600], offset=[0]
Query: type=9, index=3, sequence=0, timestamp={0, 0}, flags=4000, num_planes=1, bytesused=[0], length=[921600], offset=[0]
Query: type=9, index=4, sequence=0, timestamp={0, 0}, flags=4000, num_planes=1, bytesused=[0], length=[921600], offset=[0]
Query: type=9, index=5, sequence=0, timestamp={0, 0}, flags=4000, num_planes=1, bytesused=[0], length=[921600], offset=[0]
Query: type=9, index=6, sequence=0, timestamp={0, 0}, flags=4000, num_planes=1, bytesused=[0], length=[921600], offset=[0]
Query: type=9, index=7, sequence=0, timestamp={0, 0}, flags=4000, num_planes=1, bytesused=[0], length=[921600], offset=[0]
Query: type=9, index=8, sequence=0, timestamp={0, 0}, flags=4000, num_planes=1, bytesused=[0], length=[921600], offset=[0]
//Request input and output buffer
Stream on 10
Stream on 9
// Open input and output streams
-----Encoder. set timestart_us: 15823672258 us---------
// Start encoding
Capture EOS.
-----[Test Result] MVX Encode Done. frames_processed: 19, cost time: 28493385 us.
Stream off 10
Stream off 9
-----[Test Result] MVX Encode PASS. Average Framerate: 0.67.
Total size 140165
Closing fd 5.
// Encoding completed. Output information is printed, and the program exits.
- Multi-channel encoding
/mnt/tool # ./mvx_encoder_multi -n 4 -w 128 -h 64 /mnt/streams/yuv/foreman_128x64_3frames.yuv /mnt/test/output.264
// Command
-----Encoder. set timestart_us: 16243183563 us---------
-----Encoder. set timestart_us: 16243458316 us---------
-----Encoder. set timestart_us: 16243756086 us---------
-----Encoder. set timestart_us: 16244053547 us---------
// Start encoding
-----[Test Result] MVX Encode Done. frames_processed: 3, cost time: 634710 us.
-----[Test Result] MVX Encode Done. frames_processed: 3, cost time: 952320 us.
-----[Test Result] MVX Encode Done. frames_processed: 3, cost time: 389159 us.
-----[Test Result] MVX Encode Done. frames_processed: 3, cost time: 147590 us.
Total size 1618
Total size 1618
Total size 1618
Total size 1618
// Encoding completed. Output information is printed, and the program exits.
3 FAQ
3.1 mvx_encoder / mvx_decoder fails: /dev/video0 is not the codec device node
By default, test programs such as mvx_encoder and mvx_decoder use /dev/video0 as the codec device node. However, on some solutions /dev/video0 may not be the VPU codec node (for example, it may be occupied by another V4L2 device such as a USB camera). In that case the test program fails to open the device or reports an error.
Cause
The numbering of V4L2 device nodes (/dev/videoN) is determined by the driver probe order and is not fixed. When other V4L2 devices such as USB cameras or MIPI CSI sensors are present, the VPU codec node is not necessarily /dev/video0.
Solution
Use v4l2-ctl to locate the VPU codec node first, then specify it explicitly with the --dev option.
- List all V4L2 devices:
v4l2-ctl --list-devices
Example output:
Linlon Video device (platform:mvx):
/dev/video0
HD Pro Webcam C920 (usb-xhci-hcd.15.auto-1.4):
/dev/video1
/dev/video2
Linlon Video device (platform:mvx) is the VPU codec device. In this example it happens to be /dev/video0, but the actual node depends on your query result.
- You can also query the driver name of a specific node. The node whose driver name is
mvxis the VPU codec node:
v4l2-ctl -d /dev/videoN -D | grep "Driver name"
# Driver name : mvx
- Run with the correct node specified via
--dev:
# Assume the VPU codec node is /dev/video3
mvx_decoder --dev /dev/video3 -f raw /mnt/streams/input.264 /mnt/test/output.yuv
mvx_encoder --dev /dev/video3 -f raw -w 1280 -h 720 /mnt/streams/input.yuv /mnt/test/output.264
mvx_decoder_multi and mvx_encoder_multi also support the --dev option to specify the codec node.