### Install FFmpeg Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/INSTALL.md Install the built binaries and libraries using 'make install'. ```bash make install ``` -------------------------------- ### Install FFmpeg Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Compilation Installs the compiled FFmpeg binary to the specified prefix path after successful compilation and testing. ```shell # Install FFmpeg to the prefix path make install ``` -------------------------------- ### Run Kodi with GBM and ALSA Audio Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Rendering Start Kodi with GBM windowing and force ALSA audio backend for direct KMS interaction. This is the fastest rendering method. ```bash FFMPEG_RKMPP_DEC_OPT="afbc=on" kodi --windowing=gbm --audio-backend=alsa ``` -------------------------------- ### Including Generated Tables in Header Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/doc/tablegen.txt This example shows how to include a generated table header file when CONFIG_HARDCODED_TABLES is set. The path must be correctly specified to point to the build directory. ```c #include "libavcodec/example_tables.h" ``` -------------------------------- ### Build Minimal FFmpeg with Rockchip Support Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Compilation Compiles a minimal FFmpeg build with Rockchip hardware acceleration support. Customize the configure parameters and install prefix as needed. ```shell # Build the minimal FFmpeg (You can customize the configure and install prefix) mkdir -p ~/dev && cd ~/dev git clone --depth=1 https://github.com/nyanmisaka/ffmpeg-rockchip.git ffmpeg cd ffmpeg ./configure --prefix=/usr --enable-gpl --enable-version3 --enable-libdrm --enable-rkmpp --enable-rkrga make -j $(nproc) ``` -------------------------------- ### Build MPP Runtime and Headers Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Compilation Native compilation of the MPP (Media Process Platform) runtime on an ARM/ARM64 host. Ensure the latest MPP runtime and headers are built and installed to avoid undefined behavior. ```shell # Native compilation on ARM/ARM64 host # Build MPP mkdir -p ~/dev && cd ~/dev git clone -b jellyfin-mpp --depth=1 https://gitee.com/nyanmisaka/mpp.git rkmpp pushd rkmpp mkdir rkmpp_build pushd rkmpp_build cmake \ -DCMAKE_INSTALL_PREFIX=/usr \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SHARED_LIBS=ON \ -DBUILD_TEST=OFF \ .. make -j $(nproc) make install ``` -------------------------------- ### Query Specific Rockchip MPP Decoder Options Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Decoder Get detailed information and available options for a specific Rockchip MPP decoder, such as the H.264 decoder. This includes supported pixel formats and configuration flags like AFBC and buffer modes. ```shell ./ffmpeg -hide_banner -h decoder=h264_rkmpp ``` -------------------------------- ### Configure FFmpeg Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/INSTALL.md Run the configure script to set up the build environment. Use 'configure --help' to see available options. Building out of tree is supported by providing an absolute path to the configure script. ```bash ./configure ``` ```bash configure --help ``` ```bash /ffmpegdir/ffmpeg/configure ``` -------------------------------- ### Test Compiled FFmpeg Features Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Compilation Tests the compiled FFmpeg binary for the presence of rkmpp decoders, rkmpp encoders, and rkrga filters without installing FFmpeg system-wide. ```shell # Try the compiled FFmpeg without installation ./ffmpeg -decoders | grep rkmpp ./ffmpeg -encoders | grep rkmpp ./ffmpeg -filters | grep rkrga ``` -------------------------------- ### MPV GPU Backend and Audio Options Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Rendering Enables the new libplacebo-based GPU backend for potentially better performance. Disables audio synchronization to prevent frame drops when testing from the command line without a proper audio backend. ```bash --vo=gpu-next ``` ```bash --ao=null --ao-null-untimed ``` -------------------------------- ### FFmpeg Configure Parameters for Rockchip Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Compilation These parameters must be added to FFmpeg's configure script to enable all project functions, including hardware acceleration. --enable-gpl is optional. ```shell --enable-gpl --enable-version3 --enable-libdrm --enable-rkmpp --enable-rkrga ``` -------------------------------- ### Compiling and Testing the New Filter Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/doc/writing_filters.txt Configure, compile FFmpeg with the new filter, and then test it using a sample input and output file. ```bash ./configure ... make -j ffmpeg ./ffmpeg -i http://samples.ffmpeg.org/image-samples/lena.pnm -vf foobar foobar.png ``` -------------------------------- ### Filter Configuration Variables Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/doc/writing_filters.txt After running configure, check config.mak and config.h to verify that the build system and C preprocessor recognize the new filter. ```bash $ grep FOOBAR ffbuild/config.mak CONFIG_FOOBAR_FILTER=yes $ grep FOOBAR config.h #define CONFIG_FOOBAR_FILTER 1 ``` -------------------------------- ### FFmpeg overlay_rkrga Filter Help Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Filter Displays the help information for the overlay_rkrga filter, detailing its inputs, outputs, and available options. ```bash ./ffmpeg -hide_banner -h filter=overlay_rkrga ``` -------------------------------- ### Overlay Video with overlay_rkrga Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Filter Places a 540p overlay video onto a 1080p main video and centers it using the overlay_rkrga hardware filter. The overlay image must be in RGB format, while the main image can be YUV or RGB. ```shell ./ffmpeg -init_hw_device rkmpp=hw -filter_hw_device hw -f lavfi -i color=c=cyan:s=1920x1080,format=nv12 -f lavfi -i testsrc2=s=960x540,format=bgra \ -filter_complex "[0:v]hwupload[main];[1:v]hwupload[overlay];[main][overlay]overlay_rkrga=eof_action=pass:repeatlast=0:format=nv12:x=(W-w)/2:y=(H-h)/2" \ -c:v h264_rkmpp -b:v 4M -maxrate 4M -vframes 1000 -y /tmp/tmp.mp4 ``` -------------------------------- ### Build FFmpeg Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/INSTALL.md Compile FFmpeg using the make command. GNU Make version 3.81 or later is required. ```bash make ``` -------------------------------- ### Basic MPV Hardware Decoding Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Rendering Use this command for basic hardware decoding with MPV. It enables the rkmpp decoder for faster rendering up to 4k@60 fps. ```bash mpv --profile=fast --hwdec=rkmpp path-to-file ``` -------------------------------- ### Query H.264 MPP Encoder Options Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Encoder Inspect the detailed options and capabilities of the h264_rkmpp encoder. This includes rate control modes, QP settings, and profile/level restrictions. ```shell ./ffmpeg -hide_banner -h encoder=h264_rkmpp ``` -------------------------------- ### Generic Table Printing in C Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/doc/tablegen.txt This code demonstrates the generic form of printing a table as a header file. It includes writing the file header, defining a static constant array, and then writing the array's contents. ```c write_fileheader(); printf("static const uint8_t my_array[100] = {\n"); write_uint8_t_array(my_array, 100); printf("};\n"); ``` -------------------------------- ### Understanding frame data and linesize Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/doc/writing_filters.txt Illustrates the relationship between frame width, height, and linesize, including padding. Note that linesize may be larger than width and padding should not be modified. ```c /* <-------------- linesize ------------------------> +-------------------------------+----------------+ ^ | | | | | | | | | picture | padding | | height | | | | | | | | +-------------------------------+----------------+ v <----------- width -------------> */ ``` -------------------------------- ### Execute Filter Slice with Threading Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/doc/writing_filters.txt Shows how to invoke the threading distributor to process filter slices in parallel. ```c ThreadData td; // ... td.in = in; td.out = out; ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outlink->h, ff_filter_get_nb_threads(ctx))); // ... return ff_filter_frame(outlink, out); ``` -------------------------------- ### Creating a New Filter File Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/doc/writing_filters.txt Copy an existing filter's source file and rename it for your new filter. This sets up the basic file structure. ```bash sed 's/edgedetect/foobar/g;s/EdgeDetect/Foobar/g' libavfilter/vf_edgedetect.c > libavfilter/vf_foobar.c ``` -------------------------------- ### FFmpeg Filter activate() Callback Logic Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/doc/filter_design.txt This code demonstrates the core logic within an FFmpeg filter's activate() callback. It handles output link status, processes buffered frames, consumes new frames from input links, acknowledges status changes, and requests new frames if needed. Use this as a template for implementing custom filter logic. ```c ret = ff_outlink_get_status(outlink); if (ret) { ff_inlink_set_status(inlink, ret); return 0; } if (priv->next_frame) { /* use it */ return 0; } ret = ff_inlink_consume_frame(inlink, &frame); if (ret < 0) return ret; if (ret) { /* use it */ return 0; } ret = ff_inlink_acknowledge_status(inlink, &status, &pts); if (ret) { /* flush */ ff_outlink_set_status(outlink, status, pts); return 0; } if (ff_outlink_frame_wanted(outlink)) { ff_inlink_request_frame(inlink); return 0; } return FFERROR_NOT_READY; ``` -------------------------------- ### Query VPP RGA Filter Options Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Filter This command shows the available options for the 'vpp_rkrga' filter, which handles video post-processing tasks like scaling, cropping, and transposing using Rockchip RGA. ```shell ./ffmpeg -hide_banner -h filter=vpp_rkrga ``` -------------------------------- ### Crop and Upscale Video with vpp_rkrga Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Filter Selects the lower-right quarter of a 1080p video, crops it to 540p, and then upscales it to 720p using the vpp_rkrga hardware filter. Specify crop coordinates (cx, cy) and dimensions (cw, ch). ```shell ./ffmpeg -init_hw_device rkmpp=hw -filter_hw_device hw -f lavfi -i testsrc2=s=1920x1080,format=nv12 \ -vf hwupload,vpp_rkrga=cx=960:cy=540:cw=960:ch=540:w=1280:h=720:format=nv12 -c:v h264_rkmpp -b:v 4M -maxrate 4M -vframes 1000 -y /tmp/tmp.mp4 ``` -------------------------------- ### Required Device Files for Rockchip Hardware Acceleration Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/README.md Lists essential device files that must be accessible for the hardware acceleration components (DRM, DMA_HEAP, RGA, MPP) to function correctly. Ensure user permissions are granted. ```text # DRM allocator /dev/dri # DMA_HEAP allocator /dev/dma_heap # RGA filters /dev/rga # MPP codecs /dev/mpp_service # Optional, for compatibility with older kernels and socs /dev/iep /dev/mpp-service /dev/vpu_service /dev/vpu-service /dev/hevc_service /dev/hevc-service /dev/rkvdec /dev/rkvenc /dev/vepu /dev/h265e ``` -------------------------------- ### Registering the New Filter Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/doc/writing_filters.txt Update the Makefile and allfilters.c to include your new filter. This makes the filter available to FFmpeg. ```bash edit libavfilter/Makefile, and add an entry for "foobar" following the pattern of the other filters. edit libavfilter/allfilters.c, and add an entry for "foobar" following the pattern of the other filters. ``` -------------------------------- ### 1080p MJPEG Encoding with CQP (Low Latency) Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Encoder Encodes 1080p video using MJPEG with CQP rate control, optimized for low latency by disabling asynchronous encoding. Outputs JPEG files. ```shell ./ffmpeg -f lavfi -i testsrc2=s=1920x1080,format=bgra -c:v mjpeg_rkmpp -flags +low_delay -qp_init 80 -vframes 1000 -y /tmp/tmp%d.jpg ``` -------------------------------- ### MJPEG Encoder Options Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Encoder Lists the available AVOptions for the mjpeg_rkmpp encoder, including parameters for quantization, chroma format, and more. These options control the quality and characteristics of the MJPEG output. ```bash mjpeg_rkmpp_encoder AVOptions: -qp_init E..V....... Set the initial QP/Q_Factor value (from -1 to 99) (default -1) -qp_max E..V....... Set the max QP/Q_Factor value (from -1 to 99) (default -1) -qp_min E..V....... Set the min QP/Q_Factor value (from -1 to 99) (default -1) -chroma_fmt E..V....... Specify the output chroma format for down subsampling (from -1 to 7) (default 0) auto -1 E..V....... 400 1 E..V....... 420 4 E..V....... 422 5 E..V....... 444 7 E..V....... ``` -------------------------------- ### Iteration and Pointer Adjustments Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/doc/transforms.md This snippet illustrates how to adjust pointers for subsequent iterations in the split-radix synthesis. It highlights the need for specific pointer increments due to coefficient overlap and layout resets. ```c #if 0 z += 4; // !!! cos += 2*4; wim -= 2*4; } #endif ``` -------------------------------- ### Query HEVC MPP Encoder Options Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Encoder Examine the specific options available for the hevc_rkmpp encoder. This covers rate control, QP values, and supported profiles/levels for HEVC encoding. ```shell ./ffmpeg -hide_banner -h encoder=hevc_rkmpp ``` -------------------------------- ### 1080p MJPEG Encoding with CQP Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Encoder Encodes 1080p video using MJPEG with CQP rate control. Outputs JPEG files. ```shell ./ffmpeg -f lavfi -i testsrc2=s=1920x1080,format=bgra -c:v mjpeg_rkmpp -qp_init 80 -vframes 1000 -y /tmp/tmp%d.jpg ``` -------------------------------- ### Allocate New Buffer and Copy Frame Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/doc/writing_filters.txt Allocate a new video buffer for the output frame and copy properties from the input frame. This is used when in-place modification is not possible. ```c AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!out) { av_frame_free(&in); return AVERROR(ENOMEM); } av_frame_copy_props(out, in); // out->data[...] = foobar(in->data[...]) av_frame_free(&in); return ff_filter_frame(outlink, out); ``` -------------------------------- ### List Available Rockchip MPP Decoders Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Decoder Query FFmpeg to list all available decoders that use the Rockchip MPP. This helps identify which codecs are supported by the MPP hardware. ```shell ./ffmpeg -hide_banner -decoders | grep rkmpp ``` -------------------------------- ### Query Scale RGA Filter Options Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Filter This command displays the detailed options and parameters for the 'scale_rkrga' filter, which is used for video resizing and format conversion with Rockchip RGA. ```shell ./ffmpeg -hide_banner -h filter=scale_rkrga ``` -------------------------------- ### MPV Debugging Options Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Rendering Use these flags to enable detailed logging for FFmpeg decoding processes in MPV. '--msg-level=ffmpeg=debug' is generally sufficient, while '--msg-level=ffmpeg=trace' may provide excessive detail. ```bash --msg-level=ffmpeg=debug ``` ```bash --msg-level=ffmpeg=trace ``` -------------------------------- ### Typical request_frame Implementation for a Filter Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/doc/filter_design.txt This C code demonstrates a typical implementation of the request_frame method for a filter with multiple inputs. It prioritizes pushing queued frames before requesting new ones from inputs. ```c if (frames_queued) { push_one_frame(); return 0; } input = input_where_a_frame_is_most_needed(); ret = ff_request_frame(input); if (ret == AVERROR_EOF) { process_eof_on_input(); } else if (ret < 0) { return ret; } return 0; ``` -------------------------------- ### Build RGA (Rockchip Graphics Acceleration) Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Compilation Native compilation of the RGA (Rockchip Graphics Acceleration) library on an ARM/ARM64 host. This is necessary for graphics acceleration functionalities. ```shell # Build RGA mkdir -p ~/dev && cd ~/dev git clone -b jellyfin-rga --depth=1 https://gitee.com/nyanmisaka/rga.git rkrga meson setup rkrga rkrga_build \ --prefix=/usr \ --libdir=lib \ --buildtype=release \ --default-library=shared \ -Dcpp_args=-fpermissive \ -Dlibdrm=false \ -Dlibrga_demo=false meson configure rkrga_build ninja -C rkrga_build install ``` -------------------------------- ### 1080p HEVC Encoding with CQP Source: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Encoder Encodes 1080p video using HEVC with CQP rate control. Ensure the hevc_rkmpp encoder is available. ```shell ./ffmpeg -f lavfi -i testsrc2=s=1920x1080,format=nv12 -c:v hevc_rkmpp -qp_init 26 -profile:v main -level 4.1 -g:v 100 -vframes 5000 -y /tmp/tmp.mp4 ``` -------------------------------- ### Snow Qlogs Syntax Source: https://github.com/nyanmisaka/ffmpeg-rockchip/blob/master/doc/snow.txt Defines the structure for quantization logs (qlogs) within the Snow header, used for both keyframes and non-keyframes. ```plaintext qlogs: for(plane=0; plane