gstreamerlibavtga

How to decode a .tga image in GStreamer?


Im trying to use GStreamer to handle read .tga files and covert them into video. The hard part is I dont know how to decode such file in GStreamer.

MacOS Preview is able to read the .tga image directly. I can see some property:

This size make sense, because 1920 x 1080 x 4 bytes == 8,294,000 bytes. And file contains .tga headers. It looks a valid loseless file.

I found the libav codec: https://gstreamer.freedesktop.org/documentation/libav/avdec_targa.html?gi-language=c

Im trying to launch such pipeline:

gst-launch-1.0 -e filesrc location=/home/user/image.tga ! image/x-tga,width=1920,height=1080,framerate=1/1 ! avdec_targa ! videoconvert ! pngenc ! filesink location=output.png

I got lots error:

Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Redistribute latency...
0:00:00.025646827   656      0x2685c60 WARN            videodecoder gstvideodecoder.c:2425:gst_video_decoder_chain:<avdec_targa0> Received buffer without a new-segment. Assuming timestamps start from 0.
0:00:00.025789186   656      0x2685c60 ERROR                  libav :0:: Not enough data available for image
0:00:00.025815987   656      0x2685c60 WARN                   libav gstavviddec.c:1864:gst_ffmpegviddec_handle_frame:<avdec_targa0> Failed to send data for decoding
0:00:00.025842800   656      0x2685c60 ERROR                  libav :0:: Not enough data to read header
0:00:00.025856014   656      0x2685c60 WARN                   libav gstavviddec.c:1864:gst_ffmpegviddec_handle_frame:<avdec_targa0> Failed to send data for decoding
0:00:00.025874318   656      0x2685c60 ERROR                  libav :0:: Bit depth 186 is not supported
0:00:00.025887348   656      0x2685c60 WARN                   libav gstavviddec.c:1864:gst_ffmpegviddec_handle_frame:<avdec_targa0> Failed to send data for decoding
0:00:00.025897921   656      0x2685c60 ERROR                  libav :0:: Not enough data to read header
0:00:00.025909691   656      0x2685c60 WARN                   libav gstavviddec.c:1864:gst_ffmpegviddec_handle_frame:<avdec_targa0> Failed to send data for decoding
0:00:00.104450817   656      0x2685c60 WARN                   libav gstavviddec.c:1864:gst_ffmpegviddec_handle_frame:<avdec_targa0> Failed to send data for decoding
0:00:00.104466306   656      0x2685c60 WARN            videodecoder gstvideodecoder.c:1140:gst_video_decoder_sink_event_default:<avdec_targa0> error: No valid frames decoded before end of stream
0:00:00.104473182   656      0x2685c60 WARN            videodecoder gstvideodecoder.c:1140:gst_video_decoder_sink_event_default:<avdec_targa0> error: no valid frames found
ERROR: from element /GstPipeline:pipeline0/avdec_targa:avdec_targa0: No valid frames decoded before end of stream
Additional debug info:
../../../../../../../../src/Gstreamer-plugins-base/gst-libs/gst/video/gstvideodecoder.c(1140): gst_video_decoder_sink_event_default (): /GstPipeline:pipeline0/avdec_targa:avdec_targa0:
no valid frames found
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...

This error doesn't make sense to me, my bit depths is 32bit according to my math above, why libav thought its 186?

Any hint to help me out?


revision 2: Wanna provide more meta data, Im trying to use Python Pillow Lib to read it:

from PIL import Image
with Image.open("imageFrame_0001.tga") as img:
    for attribute_name in dir(img):
        attribute = getattr(img, attribute_name)
        if not callable(attribute):
            print(f"{attribute_name}: {attribute}")

Got below result:

'version': 3
'shape': (1080, 1920, 4)
'typestr': '|u1'
'mode': 'RGBA',
'info': {'orientation': -1},
'tile': [],
'decoderconfig': (),
'decodermaxblock': 65536,
'fp': None,
'filename': 'imageFrame_0001.tga',
__module__: PIL.TgaImagePlugin
_category: 0
format: TGA
format_description: Targa
info: {'orientation': -1}
mode: RGBA
readonly: 0
size: (1920, 1080)
width: 1920
height: 1080

Solution

  • Thanks to Ajay,

    tools/gst-launch -e filesrc location=/home/GstreamerEncodingPoc/imageFrame_0.tga blocksize=8294418 ! image/x-tga,width=1920,height=1080,framerate=1/1 ! avdec_targa ! videoconvert ! pngenc ! filesink location=output.png
    

    This will work. When we feed .tga, seems we need to let filesrc know the block size. Default block size is 4KB.