Accelerated lossless image encoding?


Is there any way to accelerate image encoding on DPX2 GPU, preferably in a lossless manner?
I have a scenario when I need to save four, full-frame, 30FPS each raw camera feed to a USB SSD. The disk is quite fast (constant ~400MB/s write benchmarked) but it’s barely enough to dump raw frames. Any attempt of CPU encoding (e.g. lz4, compressed numpy, png, h5) slows it down significantly (even run on parallel threads).
Is there any way to use GPU for that on DPX2? I know only about h264 accelerated encoding, but I really prefer to store separate frames instead compiled video.
Besides, I’m quite confused about available encoders, as that’s all encoders I can see on my device, and there’s only one from NvMedia - nvmediah264videnc:

$ gst-inspect-1.0 | grep -i encod
vpx:  vp8enc: On2 VP8 Encoder
vpx:  vp9enc: On2 VP9 Encoder
mulaw:  mulawenc: Mu Law audio encoder
png:  pngenc: PNG image encoder
wavpack:  wavpackenc: Wavpack audio encoder
speex:  speexenc: Speex audio encoder
flac:  flacenc: FLAC audio encoder
alaw:  alawenc: A Law audio encoder
y4menc:  y4menc: YUV4MPEG video encoder
jpeg:  jpegenc: JPEG image encoder
libav:  avdec_mts2: libav MS Expression Encoder Screen decoder
libav:  avenc_zmbv: libav Zip Motion Blocks Video encoder
libav:  avenc_xwd: libav XWD (X Window Dump) image encoder
libav:  avenc_xface: libav X-face image encoder
libav:  avenc_xbm: libav XBM (X BitMap) image encoder
libav:  avenc_wmv2: libav Windows Media Video 8 encoder
libav:  avenc_wmv1: libav Windows Media Video 7 encoder
libav:  avenc_utvideo: libav Ut Video encoder
libav:  avenc_tiff: libav TIFF image encoder
libav:  avenc_targa: libav Truevision Targa image encoder
libav:  avenc_svq1: libav Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1 encoder
libav:  avenc_sunrast: libav Sun Rasterfile image encoder
libav:  avenc_snow: libav Snow encoder
libav:  avenc_sgi: libav SGI image encoder
libav:  avenc_rv20: libav RealVideo 2.0 encoder
libav:  avenc_rv10: libav RealVideo 1.0 encoder
libav:  avenc_roqvideo: libav id RoQ video encoder
libav:  avenc_r10k: libav AJA Kona 10-bit RGB Codec encoder
libav:  avenc_qtrle: libav QuickTime Animation (RLE) video encoder
libav:  avenc_prores_ks: libav Apple ProRes (iCodec Pro) encoder
libav:  avenc_prores_aw: libav Apple ProRes encoder
libav:  avenc_prores: libav Apple ProRes encoder
libav:  avenc_ppm: libav PPM (Portable PixelMap) image encoder
libav:  avenc_png: libav PNG (Portable Network Graphics) image encoder
libav:  avenc_pgmyuv: libav PGMYUV (Portable GrayMap YUV) image encoder
libav:  avenc_pgm: libav PGM (Portable GrayMap) image encoder
libav:  avenc_pcx: libav PC Paintbrush PCX image encoder
libav:  avenc_pbm: libav PBM (Portable BitMap) image encoder
libav:  avenc_pam: libav PAM (Portable AnyMap) image encoder
libav:  avenc_msvideo1: libav Microsoft Video-1 encoder
libav:  avenc_msmpeg4: libav MPEG-4 part 2 Microsoft variant version 3 encoder
libav:  avenc_msmpeg4v2: libav MPEG-4 part 2 Microsoft variant version 2 encoder
libav:  avenc_mpeg4: libav MPEG-4 part 2 encoder
libav:  avenc_mpeg2video: libav MPEG-2 video encoder
libav:  avenc_mpeg1video: libav MPEG-1 video encoder
libav:  avenc_mjpeg: libav MJPEG (Motion JPEG) encoder
libav:  avenc_ljpeg: libav Lossless JPEG encoder
libav:  avenc_jpegls: libav JPEG-LS encoder
libav:  avenc_jpeg2000: libav JPEG 2000 encoder
libav:  avenc_huffyuv: libav Huffyuv / HuffYUV encoder
libav:  avenc_hap: libav Vidvox Hap encoder encoder
libav:  avenc_h263p: libav H.263+ / H.263-1998 / H.263 version 2 encoder
libav:  avenc_h263: libav H.263 / H.263-1996 encoder
libav:  avenc_h261: libav H.261 encoder
libav:  avenc_flv: libav FLV / Sorenson Spark / Sorenson H.263 (Flash Video) encoder
libav:  avenc_flashsv2: libav Flash Screen Video Version 2 encoder
libav:  avenc_flashsv: libav Flash Screen Video encoder
libav:  avenc_ffvhuff: libav Huffyuv FFmpeg variant encoder
libav:  avenc_ffv1: libav FFmpeg video codec #1 encoder
libav:  avenc_dvvideo: libav DV (Digital Video) encoder
libav:  avenc_dpx: libav DPX (Digital Picture Exchange) image encoder
libav:  avenc_dnxhd: libav VC3/DNxHD encoder
libav:  avenc_cljr: libav Cirrus Logic AccuPak encoder
libav:  avenc_cinepak: libav Cinepak / CVID encoder
libav:  avenc_bmp: libav BMP (Windows and OS/2 bitmap) encoder
libav:  avenc_avui: libav Avid Meridien Uncompressed encoder
libav:  avenc_avrp: libav Avid 1:1 10-bit RGB Packer encoder
libav:  avenc_asv2: libav ASUS V2 encoder
libav:  avenc_asv1: libav ASUS V1 encoder
libav:  avenc_apng: libav APNG (Animated Portable Network Graphics) image encoder
libav:  avenc_amv: libav AMV Video encoder
libav:  avenc_alias_pix: libav Alias/Wavefront PIX image encoder
libav:  avenc_a64multi5: libav Multicolor charset for Commodore 64, extended with 5th color (colram) encoder
libav:  avenc_a64multi: libav Multicolor charset for Commodore 64 encoder
libav:  avenc_adpcm_yamaha: libav ADPCM Yamaha encoder
libav:  avenc_adpcm_swf: libav ADPCM Shockwave Flash encoder
libav:  avenc_adpcm_ms: libav ADPCM Microsoft encoder
libav:  avenc_adpcm_ima_wav: libav ADPCM IMA WAV encoder
libav:  avenc_adpcm_ima_qt: libav ADPCM IMA QuickTime encoder
libav:  avenc_g726: libav G.726 ADPCM encoder
libav:  avenc_g722: libav G.722 ADPCM encoder
libav:  avenc_adpcm_adx: libav SEGA CRI ADX ADPCM encoder
libav:  avenc_roq_dpcm: libav id RoQ DPCM encoder
libav:  avenc_wmav2: libav Windows Media Audio 2 encoder
libav:  avenc_wmav1: libav Windows Media Audio 1 encoder
libav:  avenc_wavpack: libav WavPack encoder
libav:  avenc_tta: libav TTA (True Audio) encoder
libav:  avenc_sonicls: libav Sonic lossless encoder
libav:  avenc_sonic: libav Sonic encoder
libav:  avenc_real_144: libav RealAudio 1.0 (14.4K) encoder
libav:  avenc_nellymoser: libav Nellymoser Asao encoder
libav:  avenc_mp2fixed: libav MP2 fixed point (MPEG audio layer 2) encoder
libav:  avenc_mp2: libav MP2 (MPEG audio layer 2) encoder
libav:  avenc_g723_1: libav G.723.1 encoder
libav:  avenc_eac3: libav ATSC A/52 E-AC-3 encoder
libav:  avenc_dca: libav DCA (DTS Coherent Acoustics) encoder
libav:  avenc_alac: libav ALAC (Apple Lossless Audio Codec) encoder
libav:  avenc_ac3_fixed: libav ATSC A/52A (AC-3) encoder
libav:  avenc_ac3: libav ATSC A/52A (AC-3) encoder
libav:  avenc_aac: libav AAC (Advanced Audio Coding) encoder
libav:  avenc_s302m: libav SMPTE 302M encoder
libav:  avenc_comfortnoise: libav RFC 3389 comfort noise generator encoder
voamrwbenc:  voamrwbenc: AMR-WB audio encoder
voaacenc:  voaacenc: AAC audio encoder
gsm:  gsmenc: GSM audio encoder
adpcmenc:  adpcmenc: ADPCM encoder
bz2:  bz2enc: BZ2 encoder
pnm:  pnmenc: PNM image encoder
webp:  webpenc: WEBP image encoder
schro:  schroenc: Dirac Encoder
kate:  kateenc: Kate stream encoder
gstsiren:  sirenenc: Siren Encoder element
dtls:  dtlsenc: DTLS Encoder
dtls:  dtlssrtpenc: DTLS-SRTP Encoder
mimic:  mimenc: Mimic Encoder
srtp:  srtpenc: SRTP encoder
subenc:  srtenc: Srt encoder
subenc:  webvttenc: WebVTT encoder
openjpeg:  openjpegenc: OpenJPEG JPEG2000 encoder
mpeg2enc:  mpeg2enc: mpeg2enc video encoder
sbc:  sbcenc: Bluetooth SBC audio encoder
vorbis:  vorbisenc: Vorbis audio encoder
theora:  theoraenc: Theora video encoder
opus:  opusenc: Opus audio encoder
encoding:  encodebin: Encoder Bin
NvMedia Video:  nvmediah264videnc: NvMedia H.264 Encoder

Dear dariusz.filipski,
Could you share input image format and bit width

Sure. It’s either YUV420 or BGR888, 1280x1080px.

Hi dariusz.filipski,

Please take a look at below samples and use the attached configuration file for lossless encoding.

[|attachment](upload:// (4.01 KB)

Thanks! I’ll check it up early next week.

I confirm it works, thanks!

Encoded with:

./nvmimg_enc -cf h264_lossless_cavlc.cfg

and decoded with:

gst-launch-1.0 filesrc location=output_IYUV.264 ! h264parse ! avdec_h264 ! filesink location=decoded_IYUV.raw

gives bit-identical file with the input raw one. Encoding of a bigger file (1936x1216) takes a bit less than 10ms.

Technical question - how many of those can I run in parallel? I’d like to encode streams from 4 cameras at the same time. Does the hardware supports it?
Is it so that just two encoder instances can be created? Looking at specification of NvMediaIEPFeedFrame at: I see only two possible values of instanceId. Does it mean I could only run two encoding threads in parallel?

For PX2, please use NVMEDIA_ENCODER_INSTANCE_0. It can support creating multiple threads (call IEPcreate with NVMEDIA_ENCODER_INSTANCE_0) and feed frame in parallel. HW will schedule/encode one frame after other in serial manner. Thanks!