How to trancode other video formats to AVS using ffmpeg under Linux
This document will show you how to enable the AVS encoder inside ffmpeg and transcode from other video formats to AVS video under Linux.

1. How to Compile ffmpeg to support XAVS encoding
2. How to use ffmpeg to transcode videos to AVS
3. XAVS to FFmpeg options mapping
#########################################################################
##############How to Compile ffmpeg to support XAVS encoding###################
#########################################################################
1. Download the ffmpeg sourcecode
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
Download the xavs sourcecode
svn co https://xavs.svn.sourceforge.net/svnroot/xavs/trunk xavs

2. Compile the xavs code
install your xavs and Prefix the .h file and the .a file into the system directory like /usr/local.
./configure --enable-shared
make
make install (the libxavs.so.x will be installed at /usr/local/lib/

3. Configure ffmpeg
When you run the configure file, add the following two commands:
#./configure --enable-gpl --enable-libxavs
You should make sure that the ffmpeg project also prefix to the same location where you prefix your avs library file. That is /usr/local in our example.
 make
 make install

Check for XAVS support
#./ffmpeg -formats |less
DE cavsvideo raw Chinese AVS video
The avs video encoder is built successfully in the ffmpeg.

#########################################################################
###############How to use ffmpeg to transcode videos to AVS######################
#########################################################################
Command line to accomplish the trancoding should be like this:
./ffmpeg -vframes 300 -cqp 29 -refs 2 -bf 2 -g 16 -s widthxheight -i "INPUT_FILE_NAME" -vcodec libxavs "OUTPUT_FILE_NAME"
You should have some basic knowledge of the ffmpeg parameters to set the transcoding configure. We provide you some commonly used parameters as a reference:
-b/-vb set the bitrate/video bitrate
-s resoltion should be in the format of widthxheight
-r frame rate
-refs number of reference frames
-bf how many B frame enabled
-g gop size: frame distance between each I frames
-cqp value of this parameter should be integer larger or equal to 0. And this shows that you are going to use constant QP.
-me_method [zero, full, epzs,esa,tesa,dia, log, phod, x1, hex, umh, iter]
-qmin/-qmax min/max quantization step
-vframes how many frames are going to encode

example:
A. 264 -> avs (without B frames)
#./ffmpeg -i test0.avi -g 60 -b 600k -vcodec libxavs output1.cavs
Input #0, avi, from 'test.avi':
Metadata:
ISFT : Lavf52.68.0
Duration: 00:00:40.46, start: 0.000000, bitrate: 313 kb/s
Stream #0.0: Video: h264, yuv420p, 576x432, 30 fps, 30 tbr, 30 tbn, 60 tbc
Output #0, avs, to 'output.avs':
Metadata:
encoder : Lavf52.68.0
Stream #0.0: Video: libxavs, yuv420p, 576x432, q=2-31, 600 kb/s, 90k tbn, 30 tbc
#./ffmpeg -i output.avs
Input #0, cavsvideo, from 'output1.cavs':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: cavs, yuv420p, 576x432, 30 fps, 30 tbr, 1200k tbn, 30 tbc
[libxavs @ 0xaad0030]mb I I16..4: 0.0% 100.0% 0.0%
[libxavs @ 0xaad0030]mb P I16..4: 0.0% 3.1% 0.0% P16..4: 27.7% 9.3% 3.0% 0.0% 0.0% skip:56.9%
frame= 1214 fps= 3 q=-2.0 Lsize= 2925kB time=40.47 bitrate= 592.2kbits/s

Check Done from RM52k

B. 264 -> avs (with B frames)
#./ffmpeg -i test0.avi -b 600k -bf 2 -vcodec libxavs output2.cavs
[libxavs @ 0x9d83030]mb I I16..4: 0.0% 100.0% 0.0%
[libxavs @ 0x9d83030]mb P I16..4: 0.0% 5.7% 0.0% P16..4: 30.2% 10.2% 3.6% 0.0% 0.0% skip:50.3%
[libxavs @ 0x9d83030]mb B I16..4: 0.0% 0.4% 0.0% B16..8: 33.3% 0.8% 0.9% direct: 0.2% skip:64.4%
frame= 1214 fps= 3 q=-2.0 Lsize= 3304kB time=40.47 bitrate= 668.9kbits/s

C. PSNR of the trancoding or encoding , use -psnr option
./ffmpeg -s cif -i /mnt/d/sequences/ak.yuv -psnr -vcodec libxavs test.cavs

D. Set the bitrate of the AVS video
./ffmpeg -s cif -i /mnt/d/sequences/ak.yuv -b 300k -vcodec libxavs test.cavs

XAVS to FFmpeg options mapping
 
FFmpeg option xavs option
-g <frames> 每keyint
-b <bits per second> 每bitrate
-bufsize <bits> 每vbv-bufsize
-maxrate <bits> 每vbv-maxrate
-pass <1,2,3> 每pass
-crf <float> 每crf
-cqp <int> 每qp
-bf <int> 每bframes
-coder <0,1> 每no-cabac/nothing
-b_strategy <0,1> 每no-b-adapt/nothing
-bframebias <int> 每b-bias
-keyint_min <int> 每min-keyint
-sc_threshold <int> 每scenecut
-deblockalpha <int> 每deblock
-deblockbeta <int>
-qmin <int> 每qpmin
-qmax <int> 每qpmax
-qdiff <int> 每qpstep
-qcomp <float> 每qcomp
-qblur <float> 每qblur
-complexityblur <float> 每cplxblur
-refs <int> 每ref
-directpred <int> 每direct
-me <epzs,hex,umh,full> 每me
-me_range <int> 每merange
-subq <int> 每subme
-bidir_refine <0,1> 每bime
-trellis <0,1,2> 每trellis
-nr <int> 每nr
-level <int> 每level
-bt <bits> 每ratetol = -bt / -b
-rc_init_occupancy <bits> 每vbv-init = -rc_init_occupancy / -bufsize
-i_qfactor <float> 每ipratio = 1 / -i_qfactor
-b_qfactor <float> 每pbratio
-chromaoffset <int> 每chroma-qp-offset
-rc_eq <string> 每rc_eq
-threads <int> 每threads
-cmp <-chroma/+chroma> 每no-chroma-me/nothing
-partitions 每partitions
+parti8℅8 i8℅8
+parti4℅4 i4℅4
+partp8℅8 p8℅8
+partp4℅4 p4℅4
+partb8℅8 b8℅8
-flags
-loop/+loop 每no-deblock/每deblock
-psnr/+psnr 每no-psnr/nothing
-flags2
+bpyramid 每b-pyramid
+wpred 每weightb
+brdo 每b-rdo
+mixed_refs 每mixed-refs
+dct8℅8 每8℅8dct
-fastpskip/+fastpskip 每no-fast-pskip/nothing
+aud 每aud