Example programs
================
This is a collection of example programs demonstrating how to use Netint hardware
transcoding solutions through libxcoder.

Compile
================
In Linux, use "make".

### Building example programs

To build libxcoder, from the directory FFMPEGXCODER/libxcoder/ :
    ./build.sh

To build libxcoder api example programs, from this directory run:
	make clean; make

### ni_jpeg_test
This example program uses Netint Quadra via libxcoder to decode jpeg pictures, then apply scaling and padding.

    It accepts as input, a text list of paths to jpeg files.
    Generate a text list like thus:
    ```
    rm test_3840x2160_1920x1080_file.txt
    for f in {1..10}; do echo "/home/fpga/inputs/jpeg/Bee_3840x2160.jpeg" >> test_3840x2160_1920x1080_file.txt; done;
    for f in {1..10}; do echo "/home/fpga/inputs/jpeg/Fallen_Leaves_1920x1080.jpeg" >> test_3840x2160_1920x1080_file.txt; done;
    ```

Usage examples:
    1) output yuv420p
    ./ni_jpeg_test -c 0  -i ./test_3840x2160_1920x1080_file.txt -o ./output.yuv -d out=hw -f scale_width=640:scale_height=360:pad_width=640:pad_height=384:format=0:p2p=0
    2) output rgba
    ./ni_jpeg_test -c 0  -i ./test_3840x2160_1920x1080_file.txt -o ./output.rgb -d out=hw -f scale_width=640:scale_height=360:pad_width=640:pad_height=384:format=1:p2p=0

Parameters:
    -h | --help             Show help.
    -v | --version          Print version info.
    -l | --loglevel         Set loglevel of libxcoder API.
                            [none, fatal, error, info, debug, trace].
                            (Default: info).
    -c | --card             Set card index to use.
                            See `ni_rsrc_mon` for cards on system.
                            (Default: 0).
    -i | --input            Text file with list of paths of jpeg files.
                            ex: test_3840x2160_1920x1080_file.txt
    -d | --decoder-params   Decoding params.
    -o | --output           Output file path. eg:-o out.yuv. The output format is the same as -f.
    -f | --vf               Scaling params. ex:
                            scale_width=640:scale_height=360:pad_width=640:pad_height=384:format=0:p2p=0.
                            {format [ 0:yuv420p  1:rgba  2:rgbp ]  p2p [ 0:no p2p  1:use p2p ]}.

### ni_watermark_test
This example program is based on libxcoder. It performs a multi point overlay of a png onto the background.

Usage example:
    ./ni_watermark_test -c 0 -i ~/inputs/h264/Dinner_1920x1080p30_300.h264 -s 1920x1080 -i ~/work/test.rgb -s 1920x1080 -o aki-xcoder.265 -d out=hw

Parameters:
    -h | --help        Show help.
    -v | --version     Print version info.
    -c | --card        Set card index to use.
    -i | --input       Input file for decode and upload.
    -s | --size        Resolution of input file for decode and upload.
    -o | --output      Output file path.
    -d | --decoder-params Decode parameters.

### ni_xstack_application
This example program uses libxcoder to perform xstack.

Usage example:
    1) upload yuv420p and do stack, encode the stack result
       ./ni_xstack_application --input-format yuv420p -i input/360P_i420_01.yuv --input-resolution 640x360 -i input/360P_i420_02.yuv --input-resolution 640x360 -i input/360P_i420_03.yuv --input-resolution 640x360 -i input/360P_i420_04.yuv --input-resolution 640x360 -f "inputs=4:layout=0_0|640_0|0_360|640_360:size=640_360|640_360|640_360|640_360" -s 1280x720 -e h264_ni_quadra_enc -o test-u2e.h264 -m u2e -v info
    2) upload yuv420p and do stack, download the stack result
       ./ni_xstack_application --input-format yuv420p -i input/360P_i420_01.yuv --input-resolution 640x360 -i input/360P_i420_02.yuv --input-resolution 640x360 -i input/360P_i420_03.yuv --input-resolution 640x360 -i input/360P_i420_04.yuv  --input-resolution 640x360 -f "inputs=4:layout=0_0|640_0|0_360|640_360:size=640_360|640_360|640_360|640_360" -s 1280x720 -o test-u2d.yuv -m u2d -v info
    3) reconfig xstack layout, send sigusr1 to process and apply reconf.xstack, example reconfig file below will move the first input to the end:
       - input/360P_i420_01.yuv
       + input/360P_i420_01.yuv yuv420p 640x360
       f
       inputs=4:layout=0_0|640_0|0_360|640_360:size=640_360|640_360|640_360|640_360
       E.g. use `kill -s USR1 pid` to send sigusr1 and apply reconf.xstack.
   4) decode streams then stack and encode, set xstack sync to shortest
      ./ni_xstack_application --sync-mode 1 --input-format yuv420p -i input/clip1.h264 -d h264_ni_quadra_dec -i input/clip2.h264 -d h264_ni_quadra_dec -i input/clip3.h264 -d h264_ni_quadra_dec -i input/clip4.h264 -d h264_ni_quadra_dec -p "out=hw:scale0=640x360" -f "inputs=4:layout=0_0|640_0|0_360|640_360:size=640_360|640_360|640_360|640_360" -s 1280x720 -e h264_ni_quadra_enc -o test.h264 -v info -m d2e
   5) decode streams then stack and encode, and get multiple streams
      ./ni_xstack_application --sync-mode 1 --input-format yuv420p -i input/clip1.h264 -d h264_ni_quadra_dec -i input/clip2.h264 -d h264_ni_quadra_dec -i input/clip3.h264 -d h264_ni_quadra_dec -i input/clip4.h264 -d h264_ni_quadra_dec -p "out=hw:scale0=640x360" -f "inputs=4:layout=0_0|640_0|0_360|640_360:size=640_360|640_360|640_360|640_360" -s 1280x720 -e h264_ni_quadra_enc -o test-01.h264 -f "inputs=4:layout=0_0|640_0|0_360|640_360:size=640_360|640_360|640_360|640_360" -s 1920x1080 -e h265_ni_quadra_enc -o test-02.h265 -e h265_ni_quadra_enc -o test-03.h265 -v info -m d2e

Parameters:
-i | --input                    input video file name.
-d | --decoder                  decoder name, supported ones: [h264_ni_quadra_dec, h265_ni_quadra_dec, vp9_ni_quadra_dec]
-p | --decoder-params           decoder parameters (applicable to all decoders).
-f | --filter                   ni_quadra_xstack filter description, should only includes nb_inputs, layout and size.
-s | --resolution               output file resolution, in the format of width x height, should be associated with the preceeding filter description.
-e | --encoder                  encoder name, supported ones: [h264_ni_quadra_enc, h265_ni_quadra_enc]
-x | --encoder-params           encoder parameters.
-l | --loop                     number of times to repeat rereading input(s)
-o | --output                   output file name, should be associated with mode and preceeding filter description or encoder name
-n | --devid                    device id.
-v | --loglevel                 available debug level: warning, info, debug, trace.
-m | --mode                     available mode: d2e, d2l, u2e, u2l. Type notation: d: Decode, e: Encode, u: Upload, l: Download.
-h | --help                     print this help information.
-t | --input-format             input format, default yuv420p.
-r | --input-resolution         format: {width}x{height}, essential for u2d and u2e mode, e.g. 1280x720
-c | --sync-mode                available sync mode: 1(shortest, default), 0(not supported yet).

### ni_overlay_test
This example program is based on libxcoder. It performs rgb picture overlay postion change, overlay input change, add and remove onto the background.

Usage example:
    ./ni_overlay_test -c 0 -i ~/inputs/h264/Dinner_1920x1080p30_300.h264 -s 1920x1080 -i ../input/testa.rgb -s 1920x1080 -i ../input/testb.rgb -s 1920x1080 -o aki-xcoder.265 -d out=hw

Parameters:
    -h | --help        Show help.
    -v | --version     Print version info.
    -c | --card        Set card index to use.
    -i | --input       Input file for decode and upload.
    -s | --size        Resolution of input file for decode and upload.
    -o | --output      Output file path.
    -d | --decoder-params Decode parameters.
