Skip to content

zsgd901/ffmpeg-mlu

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EN|CN

Cambricon® FFmpeg-MLU

Cambricon® FFmpeg-MLU supports hardware-accelerated video decoding and encoding using a plain C API on Cambricon MLU hardware platforms.

Requirements

  • Supported OS:
    • Ubuntu
    • Centos
    • Debian
  • Cambricon MLU Driver:
    • neuware-mlu270-driver-4.0.3 or later.
  • Cambricon MLU SDK:
    • neuware-mlu270-1.2.5-1 or later.

Patch and Build FFmpeg-MLU

  1. Get FFmpeg sources and patch with the following Git* command:

    git clone https://gitee.com/mirrors/ffmpeg.git -b release/4.2 --depth=1
    cd ffmpeg    
    git apply ../ffmpeg4.2_mlu.patch
  2. If you are using CentOS, you need to set LD_LIBRARY_PATH to the proper directory by running the following commands:

    export LD_LIBRARY_PATH=/usr/local/neuware/lib64
  3. Run the following commands to configure and build FFmpeg-MLU:

    ./configure --enable-gpl \
                --enable-version3 \
                --enable-mlumpp \
                --extra-cflags="-I/usr/local/neuware/include" \
                --extra-ldflags="-L/usr/local/neuware/lib64" \
                --extra-libs="-lcncodec -lcnrt -ldl"
    make -j
  4. If you need a MLU transcode demo with multi-threads, run the following commands:

    make -j examples
  5. (Optional) If you need support downscaling with MLU operators, build mluop_plugin and copy libeasyOP.so to the /usr/local/neuware/lib64 folder.

Decoding and Encoding with FFmpeg-MLU

Decoding

Supported video decoding formats are as follows:

  • H.264/AVC
    • Codec Name: h264_mludec
  • HEVC
    • Codec Name: hevc_mludec
  • VP8
    • Codec Name: vp8_mludec
  • VP9
    • Codec Name: vp9_mludec
  • JPEG
    • Codec Name: mjpeg_mludec

Example

export LD_LIBRARY_PATH=/usr/local/neuware/lib64
./ffmpeg -c:v h264_mludec -i input_file -f null -

Encoding

Supported video encoding formats are as follows:

  • H.264/AVC
    • Codec Name: h264_mluenc
  • HEVC
    • Codec Name: hevc_mluenc

Example

export LD_LIBRARY_PATH=/usr/local/neuware/lib64
./ffmpeg -i input_file -c:v h264_mluenc <output.h264>

Basic Testing

Encode Baseline Test

./ffmpeg -benchmark -re -i input.mkv -c:v h264_mluenc -f null -

Decode with Scaling

./ffmpeg -y -vsync 0 -c:v h264_mludec -i input_1920x1080.mkv -vf scale=320:240 output_320x240.mp4

1:1 Transcode Without Scaling

./ffmpeg -y -vsync 0 -c:v h264_mludec -i fhd_input.mkv -c:a copy -c:v h264_mluenc -b:v 5M output.mp4

1:N Transcode With Scaling

./ffmpeg -y -vsync 0 -c:v h264_mludec -i fhd_input.mkv -vf scale=1280:720 -c:a copy -c:v h264_mluenc -b:v 2M output1.mp4 -vf scale=640:360 -c:a copy -c:v h264_mluenc -b:v 512K output2.mp4

Quality Testing

This section introduces how to test video quality with PSNR and SSTM.

PSNR

./ffmpeg -i src.h264  -i dst.h264  -lavfi psnr="stats_file=psnr.log" -f null -

SSIM

./ffmpeg -i src.h264  -i dst.h264  -lavfi ssim="stats_file=ssim.log" -f null -

Performance Fine-Tune

This section introduces how to improve the performance.

MLU Decoder

Option name Type Description
device_id int Select the accelerator card.
Supported values range from 0 to INT_MAX. INT_MAX is the total number of accelerator cards minus 1.
The default value is 0.
instance_id int Select the VPU instance.
Supported values are:
- Value in the range 0 - 5: Represents VPU instance.
- 6: The VPU instance is auto-selected.
The default value is 6.
cnrt_init_flag int Initialize or destory cnrt context in FFmpeg.
Supported values are:
- 0: Represents disabled.
- 1: Represents enabled.
The default value is 1.
input_buf_num int Number of input buffers for decoder.
Supported values range from 1 to 32.
The default value is 5.
output_buf_num int Number of output buffers for decoder.
Supported values range from 1 to 32.
The default value is 6.
stride_align int Stride align of output buffers for decoder.
Supported values range from 1 to 128, can be 2^(0 - 7).
The default value is 1.
output_pixfmt int The output pixel format.
Supported values are:
- 0: Represents NV12.
- 1: Represents NV21.
- 2: Represents I420.
The default value is 0.
resize string Resize (width)x(height).
Only supports 1/2 and 1/4 for down scaling.
The default is null.
trace int MLU FFmpeg MLU trace switch.
Supported values are:
- 0: Represents disabled.
- 1: Represents enabled.
The default value is 0.

MLU Encoder

Common

Option name Type Description
device_id int Select the accelerator card.
Supported values range from 0 to INT_MAX. INT_MAX is the total number of accelerator cards minus 1.
The default value is 0.
instance_id int Select the VPU instance.
Supported values are:
- Value in the range 0 - 1: Represents VPU instance.
- 6: The VPU instance is auto-selected.
The default value is 6.
cnrt_init_flag int Initialize or destory cnrt context in FFmpeg.
Supported values are:
- 0: Represents disabled.
- 1: Represents enabled.
The default value is 1.
input_buf_num int Number of input buffers for encoder.
Supported values range from 1 to 32.
The default value is 3.
output_buf_num int Number of output buffers for encoder.
Supported values range from 1 to 32.
The default value is 5.
trace int MLU FFmpeg debug switch.
Supported values are:
- 0 Represents disabled.
- 1: Represents enabled.
The default value is 0.
init_qpP int Initial QP value for P frame, set P frame QP.
Supported values range from -1 to 51.
The default value is -1.
init_qpI int Initial QP value for I frame, set I frame QP.
Supported values range from -1 to 51.
The default value is -1.
init_qpB int Initial QP value for B frame, set B frame QP.
Supported values range from -1 to 51.
The default value is -1.
qp int Constant QP rate control method, same as FFmpeg cqp.
Supported values range from -1 to 51.
The default value is -1.
vbr_minqp int Variable bitrate mode with MinQP, same as FFmepg qmin.
Supported values range from -1 to 51.
The default value is -1.
vbr_maxqp int Variable bitrate mode with MaxQP, same as FFmpeg qmax.
Supported values range from -1 to 51.
The default value is -1.

H264

Option name Type Description
profile const Set the encoding profile.
Supported values are: baseline, main, high, and high444p.
The default value is high.
level const Set the encoding level restriction.
Supported values are: in the range 1 - 5.1, or auto.
The default value is 4.2.
coder const Set the encoding entropy mode.
Supported values are: cabac and cavlc.
The default value is cavlc.

HEVC

Option name Type Description
profile const Set the encoding profile.
Supported values are: main, main_still, main_intra, and main10.
The default value is main.
level const Set the encoding level restriction.
Supported values are: in the range 1 - 6.2, or auto.
The default value is 1.

About

ffmpeg-mlu is mainly designed to support hardware-accelerated video decoding and encoding for Cambricon MLU card.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C++ 64.2%
  • C 22.0%
  • Dockerfile 9.6%
  • CMake 4.2%