This example shows how to do VAAPI-accelerated encoding. now only support NV12 raw file, usage like: vaapi_encode 1920 1080 input.yuv output.h264
/*
* Video Acceleration API (video encoding) encode sample
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* @file
* Intel VAAPI-accelerated encoding example.
*
* @example vaapi_encode.c
* This example shows how to do VAAPI-accelerated encoding. now only support NV12
* raw file, usage like: vaapi_encode 1920 1080 input.yuv output.h264
*
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
{
int err = 0;
fprintf(stderr, "Failed to create VAAPI frame context.\n");
return -1;
}
fprintf(stderr, "Failed to initialize VAAPI frame context."
return err;
}
return err;
}
{
goto end;
}
while (1) {
break;
}
end:
}
int main(
int argc,
char *argv[])
{
if (argc < 5) {
fprintf(stderr, "Usage: %s <width> <height> <input file> <output file>\n", argv[0]);
return -1;
}
if (!(fin = fopen(argv[3], "r"))) {
fprintf(stderr, "Fail to open input file : %s\n", strerror(errno));
return -1;
}
if (!(fout = fopen(argv[4], "w+b"))) {
fprintf(stderr, "Fail to open output file : %s\n", strerror(errno));
err = -1;
goto close;
}
if (err < 0) {
fprintf(stderr,
"Failed to create a VAAPI device. Error code: %s\n",
av_err2str(err));
goto close;
}
fprintf(stderr, "Could not find encoder.\n");
err = -1;
goto close;
}
goto close;
}
/* set hw_frames_ctx for encoder's AVCodecContext */
fprintf(stderr, "Failed to set hwframe context.\n");
goto close;
}
fprintf(stderr,
"Cannot open video encoder codec. Error code: %s\n",
av_err2str(err));
goto close;
}
while (1) {
goto close;
}
/* read data into software frame, and transfer them into hw frame */
goto close;
if ((err = fread((uint8_t*)(sw_frame->
data[0]),
size, 1, fin)) <= 0)
break;
if ((err = fread((uint8_t*)(sw_frame->
data[1]),
size/2, 1, fin)) <= 0)
break;
goto close;
}
fprintf(stderr,
"Error code: %s.\n",
av_err2str(err));
goto close;
}
if (!hw_frame->hw_frames_ctx) {
goto close;
}
fprintf(stderr, "Error while transferring frame data to surface."
goto close;
}
fprintf(stderr, "Failed to encode.\n");
goto close;
}
}
/* flush encoder */
err = 0;
close:
if (fin)
fclose(fin);
if (fout)
fclose(fout);
return err;
}