Hardware x265 encoding using gstreamer

Hi,

is it possible to use hardware-based x265 encoding using gstreamer? It seems this that the my hardware (Xperia 10 III) supports it, since Android apps (Larix broadcaster) can do it, without much CPU usage. Media Codec Info lists OMX.qcom.video.encoder.hevc and c2.android.hevc.encoder.

Peeking around with gst-inspect-1.0, it seems that droidvenc and droidvdec provide encoders and decoders based on the Android HAL. The decoder seems to support video/x-h264, video/x-h265 and video/x-vp9, while the encoder only supports video/x-h264:

[defaultuser@Xperia10III ~]$ /usr/bin/gst-inspect-1.0 droidvenc
...
  SRC template: 'src'
    Availability: Always
    Capabilities:
      video/x-h264
          stream-format: avc
              alignment: au
  
  SINK template: 'sink'
    Availability: Always
    Capabilities:
      video/x-raw(memory:DroidVideoMetaData)
                 format: { (string)YV12 }
                  width: [ 1, 2147483647 ]
                 height: [ 1, 2147483647 ]
              framerate: [ 0/1, 2147483647/1 ]
...

[defaultuser@Xperia10III ~]$ /usr/bin/gst-inspect-1.0 droidvdec
...
  SRC template: 'src'
    Availability: Always
    Capabilities:
      video/x-raw(memory:DroidMediaQueueBuffer)
                 format: { (string)NV12_64Z32, (string)YV12, (string)NV16, (string)NV12, (string)NV21, (string)YUY2, (string)RGBA, (string)RGBx, (string)RGB, (string)RGB16, (string)BGRA, (string)ENCODED }
                  width: [ 1, 2147483647 ]
                 height: [ 1, 2147483647 ]
              framerate: [ 0/1, 2147483647/1 ]
      video/x-raw
                 format: I420
                  width: [ 1, 2147483647 ]
                 height: [ 1, 2147483647 ]
              framerate: [ 0/1, 2147483647/1 ]
  
  SINK template: 'sink'
    Availability: Always
    Capabilities:
      video/x-h264
          stream-format: avc
              alignment: au
      video/x-vp9
      video/x-h265
...

hi ,how to use droidvenc in pipeline?

The pipelines for encoding? They look something like this (records default sinc to ogg/vorbis):

gst-launch-1.0 pulsesrc ! audioconvert ! vorbisenc ! oggmux ! filesink location=blah.ogg

https://gstreamer.freedesktop.org/documentation/tools/gst-launch.html?gi-language=c

I would guess there is no support for x265 because of the license costs, but that’s just a guess. I haven’t used gst-launch for video encoding since I generally just use ffmpeg.
Some useful examples at:

A complicated (and nvidia specific example) - droidvenc would go where ‘! nvv4l2h264enc’ appears

     'video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, \
     format=(string)NV12, framerate=(fraction)30/1' ! nvv4l2h264enc \
     maxperf-enable=1 bitrate=8000000 ! h264parse ! qtmux ! filesink \
     location=<filename_h264.mp4> -e

I am also looking for a way to encode using hardware. The memory:DroidVideoMetaData tag might mean that only buffers allocated by the android camera service are compatible..?

But I find that hard to believe in practice - so maybe just the gst-droid plugin is limited to supporting that. Maybe @abranson can you shed some light here? Would a raw buffer stream software allocated be encodable by droidvenc to h264 / avc?

L.E. It would suffice if encodebin[0/2] would default to hw if possible

Last time I checked those elements only took droidmedia buffers. These things tend to insist on their own internal colour formats between themselves so I think we’d have to add some conversion to support that. I guess it could also transcode or capture the screen. I’m sure it’d be possible to extend it to support non-droid buffers though.

Oh, ok.. (btw, interesting way of system closure, probably by the SoC maker..)

Would that enable better screen recording in SFOS?

I feel that the only app I’ve found (Screencast) produces too low frame rate to make howto videos that look good.

No, I think what that would need is an extension of droidmedia to encode video directly from the hw display buffers. Should be possible, but quite a bit of work.

Ok, it would be worthwhile in my eyes but I understand that lots of other things take priority.