Hardware HEVC(H.265) encoding

Post Reply
Luke.go
Posts: 613
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 76 times
Been thanked: 86 times
Contact:

Hardware HEVC(H.265) encoding

Post by Luke.go »

Before the this thread, I was introduced H.265 Hardware Encoding feature works on Android. -viewtopic.php?f=204&t=42120
Now, you can use this feature, H.265 Hardware Encoding on the Ubuntu.
Luckily, I found this thread viewtopic.php?f=136&t=23680, it could be applied to me.
And, here are my repos about it.

https://github.com/xiane/libvphevcodec
https://github.com/xiane/testHevcApi
https://github.com/xiane/amlcap


First repo is advanced version of the c2_vpcode but it is based on the amlogic's original thing. Second repo is basic video encoding demos. Third repo is based on the crashoverride's repo.

To use H.265, HEVC library, just three apis are offered.

1) init the encoder.

Code: Select all

/**
 * init encoder
 *
 *@param : codec_id: codec type
 *@param : width: video width
 *@param : height: video height
 *@param : frame_rate: framerate
 *@param : bit_rate: bitrate
 *@param : gop GOP: max I frame interval
 *@return : if success return encoder handle,else return <= 0
 */
vl_codec_handle_t vl_video_encoder_init(vl_codec_id_t codec_id, int width, int height, int frame_rate, int bit_rate, int gop);
2) encode the input frame.

Code: Select all

/**
 * encode video
 *
 *@param : handle
 *@param : type: frame type
 *@param : in: data to be encoded
 *@param : in_size: data size
 *@param : out: data output,HEVC need header(0x00,0x00,0x00,0x01),and format must be I420(apk set param out,through jni,so modify "out" in the function,don't change address point)
 *@return :if success return encoded data length,else return error
 */
int vl_video_encoder_encode(vl_codec_handle_t handle, vl_frame_type_t type, unsigned char *in, unsigned int outputBufferLen, unsigned char *out, vl_img_format_t format);
3) close the encoder.

Code: Select all

/**
 * destroy encoder
 *
 *@param :handle: encoder handle
 *@return :if success return 1,else return 0
 */
int vl_video_encoder_destroy(vl_codec_handle_t handle);
This three apis are very similar to previous version. :)
However, these three APIs can be modified or regenerated or separated to support the other project in the future, like.... ffmpeg? But NOT NOW. :)
Last edited by Luke.go on Thu Apr 01, 2021 6:01 pm, edited 1 time in total.

Luke.go
Posts: 613
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 76 times
Been thanked: 86 times
Contact:

Re: Hardware HEVC(H.264) encoding

Post by Luke.go »

The testHevcApi is used to encoding the nv12, nv12 format videos to H.265 one.
Just follow the below command.

Code: Select all

$ git clone https://github.com/xiane/testHevcApi
$ cd testHevcApi
$ git submodule init
$ git submodule update
$ make
And,

Code: Select all

$ cd hevc_enc
$ sudo make install
$ cd ..
And, let's try encoding! you should have the NV12 or NV12 format videos. and here is usage manual

Code: Select all

Amlogic HEVC Encode API
 usage: output [srcfile][outfile][width][height][gop][framerate][bitrate][num]
  options  :
  srcfile  : yuv data url in your root fs
  outfile  : stream url in your root fs
  width    : width
  height   : height
  gop      : I frame refresh interval
  framerate: framerate
   bitrate  : bit rate
   num      : encode frame count
   fmt      : encode input fmt 1:nv12, 2:nv21

Luke.go
Posts: 613
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 76 times
Been thanked: 86 times
Contact:

Re: Hardware HEVC(H.264) encoding

Post by Luke.go »

In the third repo,I just a little bit changed it to use H.265 Hardware Encoder. AND changed name to the 'amlcap'. because it worked both ODROID-C4 and ODROID-N2.
The basic usage is very similar to the crashoverride's one.Just like this.

Code: Select all

./amlcap -o -|ffmpeg -framerate 30 -f hevc -i - -vcodec copy video.mp4
These users thanked the author Luke.go for the post:
odroid (Thu Apr 01, 2021 6:02 pm)

User avatar
rooted
Posts: 8490
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 740 times
Been thanked: 342 times
Contact:

Re: Hardware HEVC(H.265) encoding

Post by rooted »

What are the limitations? Will it encode 4K @ 60fps?

Luke.go
Posts: 613
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 76 times
Been thanked: 86 times
Contact:

Re: Hardware HEVC(H.265) encoding

Post by Luke.go »

− H.265/H.264 video encoding up to 1080P@60fps with low latency :) <- from S905X3 Datasheet!, ODROID-N2 Also has the same spec.

mad_ady
Posts: 9374
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, C4, N1, N2, H2, Go, Go Advance
Location: Bucharest, Romania
Has thanked: 599 times
Been thanked: 660 times
Contact:

Re: Hardware HEVC(H.265) encoding

Post by mad_ady »

Great job! It should be on the wiki!

User avatar
rooted
Posts: 8490
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 740 times
Been thanked: 342 times
Contact:

Re: Hardware HEVC(H.265) encoding

Post by rooted »

Luke.go wrote:− H.265/H.264 video encoding up to 1080P@60fps with low latency :) <- from S905X3 Datasheet!, ODROID-N2 Also has the same spec.
1080p @ 60fps is great, I don't usually keep up with the datasheets so thank you for the answer.

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 0 guests