You may refer to sample deepstream-image-meta-test, and similiar topic How to encode multiple images using the same objectMeta inside obj_meta_list - Intelligent Video Analytics / DeepStream SDK - NVIDIA Developer Forums.
There is also sample using opencv to write jpeg file: Deepstream sample code snippet - Intelligent Video Analytics / DeepStream SDK - NVIDIA Developer Forums