Perform VAAPI-accelerated transcoding.Usage: vaapi_transcode input_stream codec output_stream e.g: - vaapi_transcode input.mp4 h264_vaapi output_h264.mp4
/*
* 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 transcoding API usage example
* @example vaapi_transcode.c
*
* Perform VAAPI-accelerated transcoding.
* Usage: vaapi_transcode input_stream codec output_stream
* e.g: - vaapi_transcode input.mp4 h264_vaapi output_h264.mp4
* - vaapi_transcode input.mp4 vp9_vaapi output_vp9.ivf
*/
#include <stdio.h>
#include <errno.h>
{
return *p;
}
fprintf(stderr, "Unable to decode this file using VA-API.\n");
}
{
fprintf(stderr, "Cannot open input file '%s', Error code: %s\n",
}
fprintf(stderr, "Cannot find input stream information. Error code: %s\n",
}
fprintf(stderr, "Cannot find a video stream in the input file. "
}
fprintf(stderr, "avcodec_parameters_to_context error. Error code: %s\n",
}
fprintf(stderr, "A hardware device reference create failed.\n");
}
fprintf(stderr, "Failed to open codec for decoding. Error code: %s\n",
}
{
fprintf(stderr,
"Error during encoding. Error code: %s\n",
av_err2str(
ret));
goto end;
}
while (1) {
break;
fprintf(stderr, "Error during writing data to output file. "
return -1;
}
}
end:
return 0;
}
{
fprintf(stderr,
"Error during decoding. Error code: %s\n",
av_err2str(
ret));
}
return 0;
fprintf(stderr,
"Error while decoding. Error code: %s\n",
av_err2str(
ret));
}
/* we need to ref hw_frames_ctx of decoder to initialize encoder's codec.
Only after we get a decoded frame, can we obtain its hw_frames_ctx */
}
/* set AVCodecContext Parameters for encoder, here we keep them stay
* the same as decoder.
* xxx: now the sample can't handle resolution change case.
*/
fprintf(stderr, "Failed to open encode codec. Error code: %s\n",
}
fprintf(stderr, "Failed to allocate stream for output format.\n");
}
fprintf(stderr, "Failed to copy the stream parameters. "
}
/* write the stream header */
fprintf(stderr, "Error while writing stream header. "
}
}
fprintf(stderr, "Error during encoding and writing.\n");
}
return 0;
}
int main(
int argc,
char **argv)
{
if (argc != 4) {
fprintf(stderr, "Usage: %s <input file> <encode codec> <output file>\n"
"The output format is guessed according to the file extension.\n"
"\n", argv[0]);
return -1;
}
fprintf(stderr,
"Failed to create a VAAPI device. Error code: %s\n",
av_err2str(
ret));
return -1;
}
if (!dec_pkt) {
fprintf(stderr, "Failed to allocate decode packet\n");
goto end;
}
goto end;
fprintf(stderr, "Could not find encoder '%s'\n", argv[2]);
goto end;
}
fprintf(stderr, "Failed to deduce output format from file extension. Error code: "
goto end;
}
goto end;
}
fprintf(stderr, "Cannot open output file. "
goto end;
}
/* read all packets and only transcoding video */
break;
}
/* flush decoder */
/* flush encoder */
/* write the trailer for output stream */
end:
}