How to write COM marker in jpg image?

NVIDIA Jetson Orin NX 16GB, Jetpack 5.1.2, L4T 35.4.1

When attempting to add JPEG COM markers via jpeg_write_marker() as per libjpeg documentation (called after jpeg_start_compress() but before any scanline writes), the output file gains null padding instead of valid marker data

I try to modify 05_jpeg_encode:

@@ -101,7 +101,10 @@ NvJPEGEncoder::encodeFromFd(int fd, J_COLOR_SPACE color_space,
             return -1;
     }
 
-    jpeg_start_compress (&cinfo, 0);
+    jpeg_start_compress (&cinfo, 1);
+
+    std::string message = "Hello";
+    jpeg_write_marker(&cinfo, JPEG_COM, (const JOCTET *)(message.c_str()), message.size());
 
     if (cinfo.err->msg_code)
     {

File size changes (+11 bytes)
Hex diff shows zero-padding instead of valid marker:

6544c6544
< 000198f0: ffd9                                     ..
---
> 000198f0: ffd9 0000 0000 0000 0000 0000 00         .............
  1. Does NVJPEG’s hardware-accelerated encoding support COM/APPn markers?
  2. If supported: what is the correct implementation pattern?
  3. If unsupported: are there workarounds while keeping hardware acceleration?

Hi,
This is not supported. You need to implement like:

  1. Get a JPEG file though encodeFromFd()
  2. Add the information to the JPEG file

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.