一锻梳、MPP 簡(jiǎn)介
Media Process Platform(簡(jiǎn)稱(chēng) MPP) 是適用于瑞芯微芯片系列的通用媒體處理軟件平臺(tái)。
該平臺(tái)對(duì)應(yīng)用軟件屏蔽了芯片相關(guān)的復(fù)雜底層處理, 其目的是為了屏蔽不同芯片的差異, 為使用者提供統(tǒng)一的視頻媒體處理接口(Media Process Interface, 縮寫(xiě) MPI)允华。
1.MPP的功能
- 視頻解碼:H.265 / H.264 / H.263 / VP9 / VP8 / MPEG-4 / MPEG-2 / MPEG-1 / VC1 / MJPEG 壓縮格式的流媒體【碼流數(shù)據(jù)】
- 視頻編碼:H.264 / VP8 / MJPEG 壓縮格式的視頻文件【圖像數(shù)據(jù)】
- 視頻處理:視頻拷貝,縮放寥掐,色彩空間轉(zhuǎn)換靴寂,場(chǎng)視頻解交織(Deinterlace)。
2.MPP系統(tǒng)架構(gòu)
-
硬件層
- 硬件層是瑞芯微系列芯片平臺(tái)的視頻編解碼硬件加速模塊, 包括 VPU, rkvdec, rkvenc 等不同類(lèi)型,
不同功能的硬件加速器召耘。
- 硬件層是瑞芯微系列芯片平臺(tái)的視頻編解碼硬件加速模塊, 包括 VPU, rkvdec, rkvenc 等不同類(lèi)型,
-
內(nèi)核驅(qū)動(dòng)層
- Linux 內(nèi)核的編碼器驅(qū)動(dòng)(vcodec_service)百炬、VPU驅(qū)動(dòng)(vpu_service),以及相關(guān)的 mmu, 內(nèi)存, 時(shí)鐘, 電源管理模塊等污它。
-
MPP層
- MPP層屏蔽了不同操作系統(tǒng)和不同芯片平臺(tái)的差異剖踊,為使用者提供統(tǒng)一的MPI接口,包括:
- HAL模塊
- OSAL模塊
- MPI模塊
- 視頻編解碼模塊(video decoder衫贬、video encoder)
- 視頻處理模塊(video process)
- MPP層屏蔽了不同操作系統(tǒng)和不同芯片平臺(tái)的差異剖踊,為使用者提供統(tǒng)一的MPI接口,包括:
-
操作系統(tǒng)層
- MPP 用戶(hù)態(tài)的運(yùn)行平臺(tái),如 Android 以及 Debian 等 Linux 發(fā)行版
-
應(yīng)用層
- MPP 層通過(guò) MPI 對(duì)接各種中間件軟件, 如 OpenMax, ffmpeg 和 gstreamer, 或者直接對(duì)接客戶(hù)的上
層應(yīng)用德澈。
- MPP 層通過(guò) MPI 對(duì)接各種中間件軟件, 如 OpenMax, ffmpeg 和 gstreamer, 或者直接對(duì)接客戶(hù)的上
3.平臺(tái)支持
-
硬件平臺(tái)支持
- 支持瑞芯微主流的各種系列芯片平臺(tái):
- RK3188 系列, RK3288 系列, RK3368 系列, RK3399 系列
- RK30xx 系列, RK312x 系列芯片,RK322x 系列芯片, RK332x 系列
- RV1108 / RV1107 系列
- 支持瑞芯微主流的各種系列芯片平臺(tái):
-
軟件平臺(tái)支持
- MPP 支持在各種版本的 Android 平臺(tái)和純 Linux 平臺(tái)上運(yùn)行。
- 支持瑞芯微 Linux 內(nèi)核 3.10 和 4.4 版本, 需要有 vcodec_service 設(shè)備驅(qū)動(dòng)支持以及相應(yīng)的 DTS 配置
支持祥山。
二圃验、MPI 接口
MPI(Media Process Interface)是 MPP 提供給用戶(hù)的接口,用于提供硬件編解碼功能,以及一些必要的相關(guān)功能。
1.MPI接口數(shù)據(jù)結(jié)構(gòu)
MPI 接口使用的主要數(shù)據(jù)結(jié)構(gòu)
- MppMem:C 庫(kù) malloc 內(nèi)存的封裝缝呕。
- MppBuffe:硬件用的 dmabuf 內(nèi)存的封裝澳窑。
- MppPacket :一維緩存封裝, 可以從 MppMem 和 MppBuffer 生成, 主要用于表示碼流數(shù)據(jù)斧散。
- 碼流:視頻圖像經(jīng)過(guò)編碼壓縮后在單位時(shí)間內(nèi)的數(shù)據(jù)流量,應(yīng)用于流媒體服務(wù)器摊聋。
- MppFrame :二維幀數(shù)據(jù)封裝,可 以從 MppMem 和 MppBuffer 生成, 主要用于表示圖像數(shù)據(jù)鸡捐。
- MppMeta 和 MppTask :輸入輸出用任務(wù)的高級(jí)組合接口,可以支持指定輸入輸出方式等復(fù)雜使用方
式, 較少使用。
2.MPI 接口使用
MPI 是通過(guò) C 結(jié)構(gòu)里的函數(shù)指針?lè)绞教峁┙o用戶(hù), 用戶(hù)可以通過(guò) MPP 上下文結(jié)構(gòu)MppCtx 與 MPI 接口結(jié)構(gòu) MppApi 組合使用來(lái)實(shí)現(xiàn)解碼器與編碼器的功能麻裁。
- 操作 MppCtx 接口
- mpp_create箍镜,mpp_init,mpp_destroy
- 真正的編碼與解碼過(guò)程是通過(guò)調(diào)用 MppApi 結(jié)構(gòu)體里內(nèi)的函數(shù)指針來(lái)實(shí)現(xiàn)煎源。
- 解碼
- 輸 入 碼 流 :decode_put_packet
- 按幀輸入或者按長(zhǎng)度輸入色迂,默認(rèn)可以接收 4 個(gè)輸入碼流包在處理隊(duì)列中。
- 輸 出 圖 像:decode_get_frame
- 輸 入 碼 流 :decode_put_packet
- 編碼
- 輸 入 圖像 :encode_put_frame
- 輸 出 碼流:encode_get_packet
- 解碼
三手销、MPP 庫(kù)編譯與使用
1.下載編譯MPP 庫(kù)
目前以RV1126為例使用MPP SDK
$ git clone -b release https://github.com/rockchip-linux/mpp.git
# linux 平臺(tái)編譯歇僧,假設(shè)處理器結(jié)構(gòu)為arm
$ cd mpp/build/linux/arm
$ sudo apt-get -y install cmake
$ bash make-Makefiles.bash
$ make -j4
$ sudo make install
$ tree -L 2
.
├── arm.linux.cross.cmake
├── CMakeCache.txt
├── CMakeFiles
│ ├── 3.10.2
│ ├── cmake.check_cache
│ ├── CMakeDirectoryInformation.cmake
│ ├── CMakeError.log
│ ├── CMakeOutput.log
│ ├── CMakeTmp
│ ├── feature_tests.bin
│ ├── feature_tests.c
│ ├── feature_tests.cxx
│ ├── Makefile2
│ ├── Makefile.cmake
│ ├── progress.marks
│ └── TargetDirectories.txt
├── cmake_install.cmake
├── Makefile
├── make-Makefiles.bash
├── mpp
│ ├── base
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── codec
│ ├── hal
│ ├── legacy
│ ├── librockchip_mpp.so -> librockchip_mpp.so.1
│ ├── librockchip_mpp.so.0
│ ├── librockchip_mpp.so.1 -> librockchip_mpp.so.0
│ ├── Makefile
│ └── vproc
├── osal
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── libosal.a
│ ├── Makefile
│ └── test
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── Makefile
│ ├── mpp_env_test
│ ├── mpp_eventfd_test
│ ├── mpp_log_test
│ ├── mpp_mem_test # 測(cè)試C庫(kù)的內(nèi)存分配器是否正常
│ ├── mpp_platform_test # 讀取和測(cè)試芯片平臺(tái)信息是否正常
│ ├── mpp_runtime_test # 測(cè)試一些軟硬件運(yùn)行時(shí)環(huán)境是否正常
│ ├── mpp_thread_test
│ └── mpp_time_test
├── rockchip_mpp.pc
├── rockchip_vpu.pc
├── test
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── Makefile
│ ├── mpi_dec_mt_test # 多線程解碼測(cè)試
│ ├── mpi_dec_multi_test # 多實(shí)例解碼測(cè)試【n線程同時(shí)解碼n份數(shù)據(jù)幀】
│ ├── mpi_dec_test # 單線程解碼測(cè)試
│ ├── mpi_enc_multi_test # 多實(shí)例編碼測(cè)試
│ ├── mpi_enc_test # 單線程編碼測(cè)試
│ ├── mpi_rc2_test
│ ├── mpi_rc_test
│ ├── mpi_test
│ ├── mpp_info_test # 讀取和打印MPP庫(kù)的版本信息
│ └── vpu_api_test
└── utils
├── CMakeFiles
├── cmake_install.cmake
├── libutils.a
└── Makefile
mpp測(cè)試程序說(shuō)明
mpi_enc_test:使用同步界面(輪詢(xún),出隊(duì)和入隊(duì))锋拖,對(duì)raw data進(jìn)行編碼以壓縮視頻诈悍。
mpi_dec_test:使用同步接口和異步接口(decode_put_packet和decode_get_frame),將視頻壓縮解碼為yuv格式的raw data兽埃。
mpi_rc_test:編碼使用詳細(xì)的比特率控制配置侥钳。
mpi_rc2_test:使用詳細(xì)的比特率控制配置進(jìn)行編碼,而cfg參數(shù)則來(lái)自mpi_rc.cfg柄错。
mpi_test:mpi調(diào)用方法的簡(jiǎn)單描述舷夺,僅供參考
mpp_event_trigger:事件觸發(fā)測(cè)試。
mpp_parse_cfg:mpp解析器cfg測(cè)試鄙陡。
vpu_api_test:編碼或解碼使用舊版接口冕房,以便與以前的vpu接口兼容。
2.獲取芯片平臺(tái)相關(guān)信息
$ cd mpp/build/linux/arm/osal/test
$ ./mpp_platform_test
mpp[2493]: mpp_plat_test: chip name: rockchip,rv1126-ds-v10 rockchip,rv1126
mpp[2493]: mpp_plat_test:
mpp[2493]: mpp_plat_test: chip vcodec type 00050202
mpp[2493]: mpp_plat_test: found vpu2 codec
mpp[2493]: mpp_plat_test: found rkvdec decoder # rk video decoder
mpp[2493]: mpp_plat_test: found rkvenc encoder # rk video encoder
mpp[2493]: mpp_plat_test: found vpu2 encoder
mpp[2493]: mpp_plat_test:
mpp[2493]: mpp_plat_test: start probing decoder device name:
mpp[2493]: mpp_plat_test: H.264 decoder: /dev/mpp_service # h264解碼
mpp[2493]: mpp_plat_test: H.265 decoder: /dev/mpp_service # h265解碼
mpp[2493]: mpp_plat_test: MJPEG decoder: /dev/mpp_service # MJPEG解碼
mpp[2493]: mpp_plat_test: VP9 decoder: (null)
mpp[2493]: mpp_plat_test: avs decoder: (null)
mpp[2493]: mpp_plat_test:
mpp[2493]: mpp_plat_test: start probing encoder device name:
mpp[2493]: mpp_plat_test: H.264 encoder: /dev/mpp_service # h264編碼
mpp[2493]: mpp_plat_test: H.265 encoder: /dev/mpp_service # h265編碼
mpp[2493]: mpp_plat_test: MJPEG encoder: /dev/mpp_service # MJPEG編碼
mpp[2493]: mpp_plat_test: mpp platform test done
$ ./mpp_runtime_test
mpp[2596]: mpp_rt: NOT found ion allocator
mpp[2596]: mpp_rt: found drm allocator
mpp[2596]: mpp_rt_test: mpp found ion buffer is invalid
mpp[2596]: mpp_rt_test: mpp found drm buffer is valid
$ ./mpp_mem_test
mpp[2034]: mpp_mem_test: calloc success ptr 0x0x59080
mpp[2034]: mpp_mem_test: realloc success ptr 0x0x5b548
mpp[2034]: mpp_mem_test: mpp_mem_test done
3.MPP視頻解碼測(cè)試
$ cd mpp/build/linux/arm/test
$ ./mpi_dec_test
mpp[671]: mpi_dec_test: usage: mpi_dec_test [options]
mpp[671]: utils: -i input_file input bitstream file
mpp[671]: utils: -o output_file output bitstream file,
mpp[671]: utils: -c ops_file input operation config file
mpp[671]: utils: -w width the width of input bitstream
mpp[671]: utils: -h height the height of input bitstream
mpp[671]: utils: -t type input stream coding type
mpp[671]: utils: -f format output frame format type # 無(wú)效趁矾,只輸出YUV420SP, NV12顏色格式
mpp[671]: utils: -d debug debug flag
mpp[671]: utils: -x timeout output timeout interval
mpp[671]: utils: -n frame_number max output frame number
mpp[671]: mpi: mpp coding type support list:
mpp[671]: mpi: type: dec id 0 coding: mpeg2 id 2
mpp[671]: mpi: type: dec id 0 coding: mpeg4 id 4
mpp[671]: mpi: type: dec id 0 coding: h.263 id 3
mpp[671]: mpi: type: dec id 0 coding: h.264/AVC id 7
mpp[671]: mpi: type: dec id 0 coding: h.265/HEVC id 16777220
mpp[671]: mpi: type: dec id 0 coding: vp8 id 9
mpp[671]: mpi: type: dec id 0 coding: VP9 id 10
mpp[671]: mpi: type: dec id 0 coding: avs+ id 16777221
mpp[671]: mpi: type: dec id 0 coding: jpeg id 8
mpp[671]: mpi: type: enc id 1 coding: h.264/AVC id 7
mpp[671]: mpi: type: enc id 1 coding: jpeg id 8
mpp[671]: mpi: type: enc id 1 coding: h265 id 16777220
mpp[671]: mpi: type: enc id 1 coding: vp8 id 9
# 將h.264/AVC視頻文件解碼成yuv格式raw data視頻文件
# 輸出圖像顏色默認(rèn)為YUV420SP, NV12格式耙册,-f選擇其他參數(shù)無(wú)效
$ sudo ./mpi_dec_test -i test.h264 -o test.yuv -w 160 -h 128 -t 7
mpp[311]: mpi_dec_test: cmd parse result:
mpp[311]: mpi_dec_test: input file name: test.h264
mpp[311]: mpi_dec_test: output file name: test.yuv
mpp[311]: mpi_dec_test: config file name:
mpp[311]: mpi_dec_test: width : 160
mpp[311]: mpi_dec_test: height : 128
mpp[311]: mpi_dec_test: type : 7
mpp[311]: mpi_dec_test: debug flag : 0
mpp[311]: mpi_dec_test: max frames : 0
mpp[311]: mpi_dec_test: mpi_dec_test start
mpp[311]: mpi_dec_test: input file size 3032275
mpp[311]: mpp_info: mpp version: a75c5ed author: Herman Chen 2020-11-06 [legacy]: Remove vpu dependence on mpp_service cmd
mpp[311]: mpi_dec_test: 0x329a0 mpi_dec_test decoder test start w 160 h 128 type 7
mpp[311]: mpp_rt: NOT found ion allocator
mpp[311]: mpp_rt: found drm allocator
mpp[311]: mpi_dec_test: 0x329a0 decode_get_frame get info changed found
mpp[311]: mpi_dec_test: 0x329a0 decoder require buffer w:h [160:128] stride [160:128] buf_size 40960
mpp[311]: mpi_dec_test: 0x329a0 decode get frame 0
mpp[311]: mpi_dec_test: 0x329a0 decode get frame 1
mpp[311]: mpi_dec_test: 0x329a0 decode get frame 2
mpp[311]: mpi_dec_test: 0x329a0 decode get frame 3
......
mpp[311]: mpi_dec_test: 0x329a0 decode get frame 7192
mpp[311]: mpi_dec_test: 0x329a0 decode get frame 7193
mpp[311]: mpi_dec_test: 0x329a0 decode get frame 7194
mpp[311]: mpi_dec_test: 0x329a0 found last packet
mpp[311]: mpi_dec_test: test success max memory 0.27 MB
# 測(cè)試RV1126編碼極限,將多路h.264/AVC視頻文件解碼成yuv格式raw data視頻【7路 1080P視頻解碼】
# 注意:編碼極限測(cè)試時(shí)不能用-o毫捣,否則會(huì)影響測(cè)試效果
$ sudo ./mpi_dec_multi_test -i video-1920x1080.h264 -w 1920 -h 1080 -t 7 -n 7
mpp[3975]: mpi_dec_multi_test: cmd parse result:
mpp[3975]: mpi_dec_multi_test: input file name: video-1920x1080.h264
mpp[3975]: mpi_dec_multi_test: output file name:
mpp[3975]: mpi_dec_multi_test: width : 1920
mpp[3975]: mpi_dec_multi_test: height : 1080
mpp[3975]: mpi_dec_multi_test: type : 7
mpp[3975]: mpi_dec_multi_test: mpi_dec_test decoder test start w 1920 h 1080 type 7
mpp[3975]: mpi_dec_multi_test: mpi_dec_test decoder test start w 1920 h 1080 type 7
mpp[3975]: mpp_info: mpp version: a75c5ed author: Herman Chen 2020-11-06 [legacy]: Remove vpu dependence on mpp_service cmd
mpp[3975]: mpp_info: mpp version: a75c5ed author: Herman Chen 2020-11-06 [legacy]: Remove vpu dependence on mpp_service cmd
mpp[3975]: mpi_dec_multi_test: mpi_dec_test decoder test start w 1920 h 1080 type 7
mpp[3975]: mpi_dec_multi_test: mpi_dec_test decoder test start w 1920 h 1080 type 7
mpp[3975]: mpp_rt: NOT found ion allocator
mpp[3975]: mpp_info: mpp version: a75c5ed author: Herman Chen 2020-11-06 [legacy]: Remove vpu dependence on mpp_service cmd
mpp[3975]: mpp_rt: found drm allocator
mpp[3975]: mpi_dec_multi_test: mpi_dec_test decoder test start w 1920 h 1080 type 7
mpp[3975]: mpi_dec_multi_test: mpi_dec_test decoder test start w 1920 h 1080 type 7
mpp[3975]: mpp_info: mpp version: a75c5ed author: Herman Chen 2020-11-06 [legacy]: Remove vpu dependence on mpp_service cmd
mpp[3975]: mpp_info: mpp version: a75c5ed author: Herman Chen 2020-11-06 [legacy]: Remove vpu dependence on mpp_service cmd
mpp[3975]: mpp_info: mpp version: a75c5ed author: Herman Chen 2020-11-06 [legacy]: Remove vpu dependence on mpp_service cmd
mpp[3975]: mpi_dec_multi_test: mpi_dec_test decoder test start w 1920 h 1080 type 7
mpp[3975]: mpp_info: mpp version: a75c5ed author: Herman Chen 2020-11-06 [legacy]: Remove vpu dependence on mpp_service cmd
mpp[3975]: mpi_dec_multi_test: decode_get_frame get info changed found
mpp[3975]: mpi_dec_multi_test: decoder require buffer w:h [1920:1080] stride [1920:1088] buf_size 4177920
mpp[3975]: mpi_dec_multi_test: decode_get_frame get info changed found
mpp[3975]: mpi_dec_multi_test: decoder require buffer w:h [1920:1080] stride [1920:1088] buf_size 4177920
mpp[3975]: mpi_dec_multi_test: decode_get_frame get info changed found
mpp[3975]: mpi_dec_multi_test: decode_get_frame get info changed found
mpp[3975]: mpi_dec_multi_test: decoder require buffer w:h [1920:1080] stride [1920:1088] buf_size 4177920
mpp[3975]: mpi_dec_multi_test: decoder require buffer w:h [1920:1080] stride [1920:1088] buf_size 4177920
mpp[3975]: mpi_dec_multi_test: decode_get_frame get info changed found
mpp[3975]: mpi_dec_multi_test: decoder require buffer w:h [1920:1080] stride [1920:1088] buf_size 4177920
mpp[3975]: mpi_dec_multi_test: decode_get_frame get info changed found
mpp[3975]: mpi_dec_multi_test: decoder require buffer w:h [1920:1080] stride [1920:1088] buf_size 4177920
mpp[3975]: mpi_dec_multi_test: decode_get_frame get info changed found
mpp[3975]: mpi_dec_multi_test: decoder require buffer w:h [1920:1080] stride [1920:1088] buf_size 4177920
mpp[3975]: mpi_dec_multi_test: decode 1500 frame use time 45613 ms frm rate 32.88
mpp[3975]: mpi_dec_multi_test: decode 1500 frame use time 45673 ms frm rate 32.84
mpp[3975]: mpi_dec_multi_test: decode 1500 frame use time 45738 ms frm rate 32.80
mpp[3975]: mpi_dec_multi_test: decode 1500 frame use time 45753 ms frm rate 32.78
mpp[3975]: mpi_dec_multi_test: decode 1500 frame use time 45770 ms frm rate 32.77
mpp[3975]: mpi_dec_multi_test: decode 1500 frame use time 45782 ms frm rate 32.76
mpp[3975]: mpi_dec_multi_test: decode 1500 frame use time 45782 ms frm rate 32.76
mpp[3975]: mpi_dec_multi_test: payload 0 frame rate: 32.84 first delay 180 ms
mpp[3975]: mpi_dec_multi_test: payload 1 frame rate: 32.88 first delay 145 ms
mpp[3975]: mpi_dec_multi_test: payload 2 frame rate: 32.78 first delay 150 ms
mpp[3975]: mpi_dec_multi_test: payload 3 frame rate: 32.77 first delay 181 ms
mpp[3975]: mpi_dec_multi_test: payload 4 frame rate: 32.76 first delay 166 ms
mpp[3975]: mpi_dec_multi_test: payload 5 frame rate: 32.76 first delay 227 ms
mpp[3975]: mpi_dec_multi_test: payload 6 frame rate: 32.80 first delay 165 ms
mpp[3975]: mpi_dec_multi_test: average frame rate 32
# RV1126 MPP解碼測(cè)試結(jié)果:7路 1080P 32fps H.264
- 視頻raw data格式分為YUV和RGB格式
- 常見(jiàn)的YUV 格式有YUV420详拙、YUV422、YUV444等
- 根據(jù)內(nèi)存存儲(chǔ)方式的不同蔓同,YUV420又分為YUV420P和YUV420SP饶辙,分別是3平面存儲(chǔ)和2平面存儲(chǔ);
- 常見(jiàn)的NV12斑粱、NV21弃揽、I420、YV12等都屬于YUV420;
- 常見(jiàn)的RGB格式有RGB和RGBA等矿微,
- 常見(jiàn)的YUV 格式有YUV420详拙、YUV422、YUV444等
4.MPP視頻編碼測(cè)試
$ ./mpi_enc_test
mpp[2628]: mpi_enc_utils: usage: mpi_enc_test [options]
mpp[2628]: utils: -i input_file input bitstream file
mpp[2628]: utils: -o output_file output bitstream file,
mpp[2628]: utils: -w width the width of input picture
mpp[2628]: utils: -h height the height of input picture
mpp[2628]: utils: -f format the format of input picture
mpp[2628]: utils: -t type output stream coding type
mpp[2628]: utils: -n max frame number max encoding frame number # 最大編碼幀數(shù)量痕慢,默認(rèn)是全部幀
mpp[2628]: utils: -g gop_mode gop reference mode
mpp[2628]: utils: -d debug debug flag
mpp[2628]: utils: -b bps target:min:max set tareget bps
mpp[2628]: utils: -r in/output fps set input and output frame rate
mpp[2628]: utils: -l loop count loop encoding times for each frame
mpp[2628]: mpi: mpp coding type support list:
mpp[2628]: mpi: type: dec id 0 coding: mpeg2 id 2
mpp[2628]: mpi: type: dec id 0 coding: mpeg4 id 4
mpp[2628]: mpi: type: dec id 0 coding: h.263 id 3
mpp[2628]: mpi: type: dec id 0 coding: h.264/AVC id 7
mpp[2628]: mpi: type: dec id 0 coding: h.265/HEVC id 16777220
mpp[2628]: mpi: type: dec id 0 coding: vp8 id 9
mpp[2628]: mpi: type: dec id 0 coding: VP9 id 10
mpp[2628]: mpi: type: dec id 0 coding: avs+ id 16777221
mpp[2628]: mpi: type: dec id 0 coding: jpeg id 8
mpp[2628]: mpi: type: enc id 1 coding: h.264/AVC id 7
mpp[2628]: mpi: type: enc id 1 coding: jpeg id 8
mpp[2628]: mpi: type: enc id 1 coding: h265 id 16777220
mpp[2628]: mpi: type: enc id 1 coding: vp8 id 9
mpp[2628]: mpi: mpp color support list: # the format of input picture
mpp[2628]: mpi: color: id 0 0x00000 YUV420SP, NV12
mpp[2628]: mpi: color: id 1 0x00001 YUV420SP-10bit
mpp[2628]: mpi: color: id 2 0x00002 YUV422SP, NV24
mpp[2628]: mpi: color: id 3 0x00003 YUV422SP-10bit
mpp[2628]: mpi: color: id 4 0x00004 YUV420P, I420
mpp[2628]: mpi: color: id 5 0x00005 YUV420SP, NV21
mpp[2628]: mpi: color: id 6 0x00006 YUV422P, 422P
mpp[2628]: mpi: color: id 7 0x00007 YUV422SP, NV42
mpp[2628]: mpi: color: id 8 0x00008 YUV422-YUYV, YUY2
mpp[2628]: mpi: color: id 10 0x0000a YUV422-UYVY, UYVY
mpp[2628]: mpi: color: id 12 0x0000c YUV400-Y8, Y800
mpp[2628]: mpi: color: id 65536 0x10000 RGB565
mpp[2628]: mpi: color: id 65537 0x10001 BGR565
mpp[2628]: mpi: color: id 65538 0x10002 RGB555
mpp[2628]: mpi: color: id 65539 0x10003 BGR555
mpp[2628]: mpi: color: id 65542 0x10006 RGB888
mpp[2628]: mpi: color: id 65543 0x10007 BGR888
mpp[2628]: mpi: color: id 65546 0x1000a ARGB8888
mpp[2628]: mpi: color: id 65547 0x1000b ABGR8888
# 將yuv raw data編碼成h264視頻文件,輸入圖像顏色選擇YUV420SP, NV12 格式
$ sudo ./mpi_enc_test -i test.yuv -o output.h264 -w 160 -h 128 -f 0 -t 7
mpp[3181]: mpi_enc_utils: cmd parse result:
mpp[3181]: mpi_enc_utils: input file name: test.yuv
mpp[3181]: mpi_enc_utils: output file name: (null)
mpp[3181]: mpi_enc_utils: width : 160
mpp[3181]: mpi_enc_utils: height : 128
mpp[3181]: mpi_enc_utils: format : 0
mpp[3181]: mpi_enc_utils: type : 7
mpp[3181]: mpi_enc_test: mpi_enc_test start
mpp[3181]: mpp_rt: NOT found ion allocator
mpp[3181]: mpp_rt: found drm allocator
mpp[3181]: mpp_info: mpp version: a75c5ed author: Herman Chen 2020-11-06 [legacy]: Remove vpu dependence on mpp_service cmd
mpp[3181]: mpi_enc_test: 0x359c0 mpi_enc_test encoder test start w 160 h 128 type 7
mpp[3181]: h264e_api_v2: MPP_ENC_SET_PREP_CFG w:h [160:128] stride [160:128]
mpp[3181]: h264e_api_v2: MPP_ENC_SET_RC_CFG bps 76800 [4800 : 81600] fps [30:30] gop 60
mpp[3181]: mpp_enc_v2: send header for set cfg change input/format
mpp[3181]: mpp_enc_v2: mode vbr bps [4800:76800:81600] fps fix [30/1] -> fix [30/1] gop i [60] v [0]
mpp[3181]: mpi_enc_test: 0x359c0 encoded frame 0 size 5478
mpp[3181]: mpi_enc_test: 0x359c0 encoded frame 1 size 1705
mpp[3181]: mpi_enc_test: 0x359c0 encoded frame 2 size 2182
......
mpp[1966]: mpi_enc_test: 0x35b60 encoded frame 25292 size 14
mpp[1966]: mpi_enc_test: 0x35b60 encoded frame 25293 size 14
mpp[1966]: mpi_enc_test: 0x35b60 found last frame. feof 1
mpp[1966]: mpi_enc_test: 0x35b60 encoded frame 25294 size 0
mpp[1966]: mpi_enc_test: 0x35b60 found last packet
mpp[1966]: mpi_enc_test: 0x35b60 mpi_enc_test success total frame 25295 bps 147396
# 將YUV420P的raw data視頻文件編碼成jpeg圖片涌矢,輸入圖像顏色選擇YUV420SP, NV12 格式
# 默認(rèn)編碼一幀掖举,如果編碼多幀則會(huì)疊加到同一張圖片,size增大
$ ./mpi_enc_test -i test.yuv -o output.jpeg -w 160 -h 128 -f 0 -t 8 -n 1
mpp[2417]: mpi_enc_utils: cmd parse result:
mpp[2417]: mpi_enc_utils: input file name: test.yuv
mpp[2417]: mpi_enc_utils: output file name: output.jpeg
mpp[2417]: mpi_enc_utils: width : 160
mpp[2417]: mpi_enc_utils: height : 128
mpp[2417]: mpi_enc_utils: format : 4
mpp[2417]: mpi_enc_utils: type : 8
mpp[2417]: mpi_enc_test: mpi_enc_test start
mpp[2417]: mpi_enc_test: jpege default encode only one frame. Use -n [num] for rc case
mpp[2417]: mpp_rt: NOT found ion allocator
mpp[2417]: mpp_rt: found drm allocator
mpp[2417]: mpp_info: mpp version: a75c5ed author: Herman Chen 2020-11-06 [legacy]: Remove vpu dependence on mpp_service cmd
mpp[2417]: mpi_enc_test: 0x35b60 mpi_enc_test encoder test start w 160 h 128 type 8
mpp[2417]: mpi_enc_test: 0x35b60 encoded frame 0 size 4149
mpp[2417]: mpi_enc_test: 0x35b60 encode max 1 frames
mpp[2417]: mpi_enc_test: 0x35b60 mpi_enc_test success total frame 1 bps 995760
5.視頻文件比較
$ sudo apt-get install mediainfo
# 原始測(cè)試h264視頻文件
$ mediainfo test.h264
General
Complete name : test.h264
Format : AVC
Format/Info : Advanced Video Codec
File size : 2.89 MiB
Video
Format : AVC
Format/Info : Advanced Video Codec
Format profile : Main@L5.1
Format settings : CABAC / 1 Ref Frames
Format settings, CABAC : Yes
Format settings, ReFrames : 1 frame
Width : 160 pixels
Height : 128 pixels
Display aspect ratio : 5:4
Frame rate : 29.970 (29970/1000) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
$ du -h test.h264
2.9M test.h264
# h264視頻文件解碼得到的yuv raw data文件
$ mediainfo test.yuv
General
Complete name : test.yuv
File size : 211 MiB # raw data數(shù)據(jù)比h264編碼的數(shù)據(jù)大72倍娜庇,所以網(wǎng)絡(luò)傳輸時(shí)塔次,編碼是很有必要的
# yuv raw data文件再次編碼得到的h264視頻文件
$ mediainfo output.h264
General
Complete name : output.h264
Format : AVC
Format/Info : Advanced Video Codec
File size : 2.14 MiB
Video
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4
Format settings : CABAC / 1 Ref Frames
Format settings, CABAC : Yes
Format settings, ReFrames : 1 frame
Format settings, GOP : M=1, N=60
Width : 160 pixels
Height : 128 pixels
Display aspect ratio : 5:4
Frame rate : 30.000 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressiv
# yuv raw data文件再次編碼得到的jpeg圖片
$ mediainfo output.jpeg
General
Complete name : output.jpeg
Format : JPEG
File size : 4.05 KiB
Image # 是一張圖片
Format : JPEG
Width : 160 pixels
Height : 128 pixels
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Compression mode : Lossy
Stream size : 4.05 KiB (100%)
# 播放H264視頻
$ ffplay -i test.h264
# 播放yuv raw data video
$ ffplay -f rawvideo -pixel_format yuv420p -video_size 160x128 test.yuv
# 播放編碼得到的H264視頻
$ ffplay -i output.h264
# 打開(kāi)jpeg圖片
$ ffplay -i output.jpg
- h264視頻文件解碼得到y(tǒng)uv raw data文件,再次編碼得到的h264視頻文件名秀,兩者視頻內(nèi)容一致励负。
- ffplay播放raw data video看到的是黑白視頻,可以使用yuvplayer.exe泰偿,選擇YUV420SP, NV12顏色格式熄守,就可以看到彩色視頻蜈垮。