minih264 icon indicating copy to clipboard operation
minih264 copied to clipboard

Multithreading support

Open creativefctr opened this issue 5 years ago • 5 comments

I couldn't find any info about the state of multithreading in this library. Can you please explain more?

creativefctr avatar Feb 23 '21 08:02 creativefctr

Hi) Multi-threading is supported, but slightly reduces quality. You need to compile test application with -DH264E_MAX_THREADS=n (where n=max number of threads) and use -threads command line switch:

$ ./h264enc_x64                                                                                                                     ↑
Usage:
    h264e_test [options] <input[frame_size].yuv> <output.264>
Frame size can be: WxH sqcif qvga svga 4vga sxga xga vga qcif 4cif
    4sif cif sif pal ntsc d1 16cif 16sif 720p 4SVGA 4XGA 16VGA 16VGA
Options:
    -gen            - generate input instead of passing <input.yuv>
    -qop<n>         - key frame period >= 0
    -qp<n>          - set QP [10..51]
    -kbps<n>        - set bitrate (fps=30 assumed)
    -maxframes<n>   - encode no more than given number of frames
    -threads<n>     - use <n> threads for encode
    -speed<n>       - speed [0..10], 0 means best quality
    -denoise        - use temporal noise supression
    -stats          - print frame statistics
    -psnr           - print psnr statistics

For example:

./scripts/build_x86.sh
./h264enc_x64 -threads4 vectors/foreman.cif

lieff avatar Feb 23 '21 09:02 lieff

Thanks! I am curious though as how multi-threading would reduce quality...

creativefctr avatar Feb 23 '21 09:02 creativefctr

Quality reduction happen because of image split on n (number of threads) independent parts.

lieff avatar Feb 23 '21 15:02 lieff

so are you slicing one frame between multiple parts? Or each frame on one thread?

creativefctr avatar Feb 23 '21 15:02 creativefctr

Yes, slices are used. Here where per thread start\end macro-block params calculated https://github.com/lieff/minih264/blob/master/minih264e.h#L11323 .

lieff avatar Feb 23 '21 16:02 lieff