diff --git a/examples/hve_encode_raw_h264.c b/examples/hve_encode_raw_h264.c index 9f71efc..9c5d2d2 100644 --- a/examples/hve_encode_raw_h264.c +++ b/examples/hve_encode_raw_h264.c @@ -10,7 +10,7 @@ */ #include //printf, fprintf -#include //uint8_t +#include //uint8_t, uint16_t #include "../hve.h" @@ -19,8 +19,8 @@ const int HEIGHT=720; const int FRAMERATE=30; int SECONDS=10; const char *DEVICE=NULL; //NULL for default or device e.g. "/dev/dri/renderD128" -const char *PIXEL_FORMAT="nv12"; //NULL for default (NV12) or pixel format e.g. "rgb0" -const int PROFILE=FF_PROFILE_H264_HIGH; //or FF_PROFILE_H264_MAIN, FF_PROFILE_H264_CONSTRAINED_BASELINE, ... +const char *PIXEL_FORMAT="p010le"; //NULL for default (NV12) or pixel format e.g. "rgb0" +const int PROFILE=FF_PROFILE_HEVC_MAIN_10; //or FF_PROFILE_H264_MAIN, FF_PROFILE_H264_CONSTRAINED_BASELINE, ... const int BFRAMES=0; //max_b_frames, set to 0 to minimize latency, non-zero to minimize size const int BITRATE=0; //average bitrate in VBR @@ -39,8 +39,8 @@ int main(int argc, char* argv[]) struct hve_config hardware_config = {WIDTH, HEIGHT, FRAMERATE, DEVICE, PIXEL_FORMAT, PROFILE, BFRAMES, BITRATE}; struct hve *hardware_encoder; - //prepare file for raw H.264 output - FILE *output_file = fopen("output.h264", "w+b"); + //prepare file for raw HEVC output + FILE *output_file = fopen("output.hevc", "w+b"); if(output_file == NULL) return fprintf(stderr, "unable to open file for output\n"); @@ -66,29 +66,31 @@ int main(int argc, char* argv[]) int encoding_loop(struct hve *hardware_encoder, FILE *output_file) { struct hve_frame frame = { 0 }; - int frames=SECONDS*FRAMERATE, f, failed; + int frames=SECONDS*FRAMERATE, f, failed, i; - //we are working with NV12 because we specified nv12 pixel format + //we are working with P010LE because we specified p010le pixel format //when calling hve_init, in principle we could use other format //if hardware supported it (e.g. RGB0 is supported on my Intel) - uint8_t Y[WIDTH*HEIGHT]; //dummy NV12 luminance data - uint8_t color[WIDTH*HEIGHT/2]; //dummy NV12 color data + uint16_t Y[WIDTH*HEIGHT]; //dummy p010le luminance data (or p016le) + uint16_t color[WIDTH*HEIGHT/2]; //dummy p010le color data (or p016le) //fill with your stride (width including padding if any) - frame.linesize[0] = frame.linesize[1] = WIDTH; + frame.linesize[0] = frame.linesize[1] = WIDTH*2; //encoded data is returned in FFmpeg packet AVPacket *packet; for(f=0;favctx->sample_aspect_ratio = (AVRational){ 1, 1 }; h->avctx->pix_fmt = AV_PIX_FMT_VAAPI; + //Profiles + //https://ffmpeg.org/doxygen/3.4/avcodec_8h.html if(config->profile) h->avctx->profile = config->profile; h->avctx->max_b_frames = config->max_b_frames;