Content
AVS2 is Chinese video encoding standard (the successor of AVS), for more info go to here
How to get and Build AVS2 open-source encoder xavs2?
git clone https://github.com/pkuvcl/xavs2.git
as recommended in the github of xavs2 you need perform the following (before launching Visual Studio solution):
- Add a path to Git to PATH variable, because the builder uses ‘sh.exe‘ of Git. Usually Git is located at
C:\Program Files\Git\bin
.
- Take nasm.exe from https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/win64/nasm-2.14.02-win64.zip and put it to
build/vs2013
directory
In the folder xavs2\build\vs2013 you launch the Visual Studio solution xavs2.sln in Release/x64.
I opened the solution with Visual Studio version 2019, therefore retarget is necessary
i was faced with the problem that two functions: coeff_scan4_xy_sse128 and coeff_scan4_yx_sse128 were not compiled, therefore i disabled the optimization of these functions by the pragma ‘optimize’:
#pragma optimize( "", off )
void coeff_scan4_xy_sse128(coeff_t *dst, uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4)
{
__m128i dst1, dst2;
__m128i order1, order2;
int int1, int2;
.....
void coeff_scan4_yx_sse128(coeff_t *dst, uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4)
{
__m128i dst1, dst2;
__m128i order1, order2;
int int1, int2;
....
}
#pragma optimize( "", on )
The built files are located in the folder C:\Tool\xavs2\build\bin\x64_Release
Notice xavs2.exe is not stand-alone, it uses dll and libs to run. So, to run xavs2.exe you need put corresponding dll and lib files to PATH.
If you are reluctant to build Windows version of xavs2.exe you are welcome to take it from my build
Running
Type xavs2.exe to get full help
Example [encode 500 frames of 1080p@60fps, open GOP size = 60 frames, bitrate 5Mbps, preset = fast]
xavs2 -p InputFile=Fifa17.yuv --FramesToBeEncoded=500 --fps=60 --SourceWidth=1920 --SourceHeight=1080 --InputSampleBitDepth=8 --SampleBitDepth=8 --thread_frames=1 --thread_rows=1 --preset=2 --recon=NUL --IntraPeriodMax=60 --IntraPeriodMin=60 --RateControl=3 --TargetBitRate=5000000 --OutputFile=test.avs
xavs2[d]: POC Type QP + Bits PsnrY PsnrU PsnrV Time [ RefList ]
xavs2[d]: 0 (I) 32 955944 39.4948 42.0059 43.1521 212
xavs2[d]: 8 (F) 33 934536 36.8715 39.7015 41.1243 233 [ 0]
xavs2[d]: 4 (B) 41 73896 35.8781 40.6941 41.6690 131 [ 8 0]
xavs2[d]: 2 (B) 42 17064 36.7152 41.3009 42.1491 72 [ 4 0]
xavs2[d]: 1 (B) 44 5584 37.5862 41.5348 42.3953 35 [ 2 0]
xavs2[d]: 3 (B) 44 8768 36.2024 41.1178 41.8132 46 [ 4 2]
xavs2[d]: 6 (B) 42 25336 35.4638 40.0378 41.1575 99 [ 8 4]
xavs2[d]: 5 (B) 44 4648 35.4198 40.3876 41.2155 38 [ 6 4]
xavs2[d]: 7 (B) 44 4592 35.5290 39.5114 40.7236 47 [ 8 6]
xavs2[d]: 16 (F) 36 405112 34.8557 38.2877 39.7894 206 [ 8 6]
xavs2[d]: 12 (B) 43 42496 33.5760 38.0473 39.5206 110 [ 16 8]
xavs2[d]: 10 (B) 44 21672 33.5401 37.8552 39.6315 101 [ 12 8]
xavs2[d]: 9 (B) 47 1960 34.7395 38.5473 40.0237 35 [ 10 8]
xavs2[d]: 11 (B) 47 4688 33.4861 37.9277 39.5667 54 [ 12 10]
xavs2[d]: 14 (B) 44 11120 33.7932 37.9853 39.6477 91 [ 16 12]
xavs2[d]: 13 (B) 47 2672 33.5904 38.0129 39.6087 41 [ 14 12]
xavs2[d]: 15 (B) 47 4024 33.8566 38.0343 39.5710 45 [ 16 14]
xavs2[d]: 24 (F) 35 298224 34.9336 38.2871 39.8936 157 [ 16 14]
...
xavs2[d]: 495 (B) 38 21712 36.7703 43.3976 43.5434 57 [496 494]
xavs2[d]: 499 (F) 29 483800 38.9070 43.7337 43.9173 116 [496 494]
xavs2[d]: 497 (B) 34 93056 37.5306 43.4905 43.5330 88 [499 496]
xavs2[d]: 498 (B) 36 55744 37.0850 43.3474 43.3461 89 [499 497]
xavs2[i]: ---------------------------------------------------------------------
xavs2[i]: AVERAGE SEQ PSNR: 36.3076 41.6501 42.5684
xavs2[i]: BITRATE: 5101.13 kb/s @ 60.0 Hz, 500 frames, xavs2 p2
xavs2[i]: TOTAL BITS: 42509392 (I: 8012208, B: 8874288, P/F: 25622896)
xavs2[d]: TOTAL TIME: 36.663 sec, total 500 frames, speed: 13.64 fps
xavs2[d]: Frame Time: I: 4.47%; B: 73.83%; P/F: 21.70%
xavs2[i]: Frame Num : I: 1.60%; B: 87.20%; P/F: 11.20%
xavs2[i]: ---------------------------------------------------------------------
xavs2[d]: Encoded 500 frames, 36.719 secs
Notes:
--recon=NUL
to not write reconstructed yuv
How to Play AVS2?
ffplay knows to play elementary AVS2:
ffplay -i test.avs2
Check that ffmpeg supports xavs2 coding (if not then i recommend to download the recent full ffmpeg version)
ffmpeg -codecs | findstr libxavs2
...
DEV.L. avs2 AVS2-P2/IEEE1857.4 (decoders: libdavs2 ) (encoders: libxavs2 )
Example: Encode AVS2 stream, GOP size – 60 frames, no B frames, the bitrate – 600Kbps, container – avi-container
ffmpeg -video_size 384x320 -pixel_format yuv420p -i battlefield_384x320.yuv -b:v 600k -refs 1 -bf 0 -g 60 -me_method hex -r 60 -vcodec libxavs2 -y battlefield_384x320_avs2
.avi
Pot player does not play AVS2 stream even encapsulated into AVI container. But ffplay does plays AVS2 streams:
ffplay battlefield_384x320_avs2.avi
23+ years’ programming and theoretical experience in the computer science fields such as video compression, media streaming and artificial intelligence (co-author of several papers and patents).
the author is looking for new job, my resume