This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA4VM: How to modify the output image size of v4l2h265enc

Part Number: TDA4VM

Tool/software:

If using v4l2 encoding directly, I can set the output image size using the following method:


struct v4l2_selection selection;
selection.type =V4L2_BUF TYPE_VIDEO_OUTPUT_ MPLANE;
selection.target = V4L2_SEL TGT_CROP;
selection.r.left =20;
selection.r.top =20;
selection.r.width =w;
selection.r.height = h;
ioctl(fd,VIDIOC S SELECTION,&selection);

now,Now I am using v4l2h265enc encoding, how should I set the size of the output image?

  • Hi Damon,

    With GStreamer, you would just need to set the caps to set the image size/resolution.

    Best,
    Jared

  • i use 720*1080 nv12 image, v4l2h265enc set output-io-mode : 5,but report errors,Say my buf is not available。and i use 768*1080 nv12 image,no error.

    so i understand it's an encoder alignment issue。I need a method to set the crop of the encoder。

  • Hi Damon,

    Can you send your pipeline and error log? The encoder doesn't crop, it will just encode whatever it is given. You can crop the image/video before giving it to the encoder.

    i use 720*1080 nv12 image, v4l2h265enc set output-io-mode : 5,but report errors,Say my buf is not available。and i use 768*1080 nv12 image,no error.

    Sorry, I don't understand what you're trying to say here.

    Best,
    Jared

  • Using the following method, v4l2 supports both encoding and image cropping。I noticed that there are similar settings in the source code of gstreamer,But I couldn't find the exposed function to change it。

    struct v4l2_selection selection;
    selection.type =V4L2_BUF TYPE_VIDEO_OUTPUT_ MPLANE;
    selection.target = V4L2_SEL TGT_CROP;
    selection.r.left =20;
    selection.r.top =20;
    selection.r.width =w;
    selection.r.height = h;
    ioctl(fd,VIDIOC S SELECTION,&selection);

  • Hi Damon,

    If you run gst-inspect-1.0 v4l2h265enc, you can see the possible parameters/fields for the encoding plugin. There isn't a method to crop the image.

    Element Properties:
    
      capture-io-mode     : Capture I/O mode (matches src pad)
                            flags: readable, writable
                            Enum "GstV4l2IOMode" Default: 0, "auto"
                               (0): auto             - GST_V4L2_IO_AUTO
                               (1): rw               - GST_V4L2_IO_RW
                               (2): mmap             - GST_V4L2_IO_MMAP
                               (3): userptr          - GST_V4L2_IO_USERPTR
                               (4): dmabuf           - GST_V4L2_IO_DMABUF
                               (5): dmabuf-import    - GST_V4L2_IO_DMABUF_IMPORT
      
      device              : Device location
                            flags: readable
                            String. Default: "/dev/video1"
      
      device-fd           : File descriptor of the device
                            flags: readable
                            Integer. Range: -1 - 2147483647 Default: -1 
      
      device-name         : Name of the device
                            flags: readable
                            String. Default: null
      
      extra-controls      : Extra v4l2 controls (CIDs) for the device
                            flags: readable, writable
                            Boxed pointer of type "GstStructure"
      
      min-force-key-unit-interval: Minimum interval between force-keyunit requests in nanoseconds
                            flags: readable, writable
                            Unsigned Integer64. Range: 0 - 18446744073709551615 Default: 0 
      
      name                : The name of the object
                            flags: readable, writable
                            String. Default: "v4l2h265enc0"
      
      output-io-mode      : Output side I/O mode (matches sink pad)
                            flags: readable, writable
                            Enum "GstV4l2IOMode" Default: 0, "auto"
                               (0): auto             - GST_V4L2_IO_AUTO
                               (1): rw               - GST_V4L2_IO_RW
                               (2): mmap             - GST_V4L2_IO_MMAP
                               (3): userptr          - GST_V4L2_IO_USERPTR
                               (4): dmabuf           - GST_V4L2_IO_DMABUF
                               (5): dmabuf-import    - GST_V4L2_IO_DMABUF_IMPORT
      
      parent              : The parent of the object
                            flags: readable, writable
                            Object of type "GstObject"
      
      qos                 : Handle Quality-of-Service events from downstream
                            flags: readable, writable
                            Boolean. Default: false

    The possible v4l2 controls:

    $ v4l2-ctl --list-ctrls -d /dev/video1
    
    User Controls
    
                    horizontal_flip 0x00980914 (bool)   : default=0 value=0
                      vertical_flip 0x00980915 (bool)   : default=0 value=0
                             rotate 0x00980922 (int)    : min=0 max=270 step=90 default=0 value=0 flags=modify-layout
       min_number_of_output_buffers 0x00980928 (int)    : min=1 max=32 step=1 default=1 value=1 flags=read-only
    
    Codec Controls
    
                     video_gop_size 0x009909cb (int)    : min=0 max=2047 step=1 default=0 value=0
                 video_bitrate_mode 0x009909ce (menu)   : min=0 max=1 default=1 value=1 (Constant Bitrate) flags=update
                      video_bitrate 0x009909cf (int)    : min=0 max=700000000 step=1 default=0 value=0
    frame_level_rate_control_enable 0x009909d7 (bool)   : default=0 value=0
         h264_mb_level_rate_control 0x009909da (bool)   : default=0 value=0
           number_of_mbs_in_a_slice 0x009909dc (int)    : min=0 max=65535 step=1 default=0 value=0
          slice_partitioning_method 0x009909dd (menu)   : min=0 max=1 default=0 value=0 (Single)
                    vbv_buffer_size 0x009909de (int)    : min=10 max=3000 step=1 default=1000 value=1000
                    force_key_frame 0x009909e5 (button) : value=0 flags=write-only, execute-on-write
    generate_access_unit_delimiters 0x009909e7 (bool)   : default=1 value=1
              h264_i_frame_qp_value 0x00990a5e (int)    : min=0 max=63 step=1 default=30 value=30
              h264_minimum_qp_value 0x00990a61 (int)    : min=0 max=63 step=1 default=8 value=8
              h264_maximum_qp_value 0x00990a62 (int)    : min=0 max=63 step=1 default=51 value=51
          h264_8x8_transform_enable 0x00990a63 (bool)   : default=0 value=0
                  h264_entropy_mode 0x00990a65 (menu)   : min=0 max=1 default=0 value=0 (CAVLC)
                h264_i_frame_period 0x00990a66 (int)    : min=0 max=2047 step=1 default=0 value=0
                         h264_level 0x00990a67 (menu)   : min=0 max=15 default=0 value=0 (1)
      h264_loop_filter_alpha_offset 0x00990a68 (int)    : min=-6 max=6 step=1 default=0 value=0
       h264_loop_filter_beta_offset 0x00990a69 (int)    : min=-6 max=6 step=1 default=0 value=0
              h264_loop_filter_mode 0x00990a6a (menu)   : min=0 max=2 default=0 value=0 (Enabled)
                       h264_profile 0x00990a6b (menu)   : min=0 max=7 default=0 value=0 (Baseline)
        h264_constrained_intra_pred 0x00990a7f (int)    : min=0 max=1 step=1 default=0 value=0
        h264_chroma_qp_index_offset 0x00990a80 (int)    : min=-12 max=12 step=1 default=0 value=0
              hevc_minimum_qp_value 0x00990b58 (int)    : min=0 max=63 step=1 default=8 value=8
              hevc_maximum_qp_value 0x00990b59 (int)    : min=0 max=63 step=1 default=51 value=51
              hevc_i_frame_qp_value 0x00990b5a (int)    : min=0 max=63 step=1 default=30 value=30
                       hevc_profile 0x00990b67 (menu)   : min=0 max=2 default=0 value=0 (Main)
                         hevc_level 0x00990b68 (menu)   : min=0 max=8 default=0 value=0 (1)
                   hevc_loop_filter 0x00990b6c (menu)   : min=0 max=2 default=1 value=1 (Enabled)
       hevc_loop_filter_beta_offset 0x00990b6d (int)    : min=-6 max=6 step=1 default=0 value=0
         hevc_loop_filter_tc_offset 0x00990b6e (int)    : min=-6 max=6 step=1 default=0 value=0
                  hevc_refresh_type 0x00990b6f (menu)   : min=0 max=2 default=2 value=2 (IDR)
      hevc_num_of_i_frame_b_w_2_idr 0x00990b70 (int)    : min=0 max=2047 step=1 default=0 value=0
             hevc_lossless_encoding 0x00990b71 (int)    : min=0 max=1 step=1 default=0 value=0
     hevc_constant_intra_prediction 0x00990b72 (int)    : min=0 max=1 step=1 default=0 value=0
                     hevc_wavefront 0x00990b73 (int)    : min=0 max=1 step=1 default=0 value=0
        hevc_strong_intra_smoothing 0x00990b76 (int)    : min=0 max=1 step=1 default=1 value=1
      hevc_max_num_of_candidate_mvs 0x00990b77 (int)    : min=1 max=2 step=1 default=2 value=2
                hevc_tmv_prediction 0x00990b79 (int)    : min=0 max=1 step=1 default=1 value=1
         prepend_sps_and_pps_to_idr 0x00990b84 (int)    : min=0 max=1 step=1 default=0 value=0

    An option would be to run the image through a tiovxmultiscaler plugin, and use that to crop the image before encoding it.

    Best,
    Jared