| 220 | } |
| 221 | |
| 222 | int main(int argc, char **argv) |
| 223 | { |
| 224 | const AVCodec *enc_codec; |
| 225 | int ret = 0; |
| 226 | AVPacket *dec_pkt; |
| 227 | |
| 228 | if (argc != 4) { |
| 229 | fprintf(stderr, "Usage: %s <input file> <encode codec> <output file>\n" |
| 230 | "The output format is guessed according to the file extension.\n" |
| 231 | "\n", argv[0]); |
| 232 | return -1; |
| 233 | } |
| 234 | |
| 235 | ret = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_VAAPI, NULL, NULL, 0); |
| 236 | if (ret < 0) { |
| 237 | fprintf(stderr, "Failed to create a VAAPI device. Error code: %s\n", av_err2str(ret)); |
| 238 | return -1; |
| 239 | } |
| 240 | |
| 241 | dec_pkt = av_packet_alloc(); |
| 242 | if (!dec_pkt) { |
| 243 | fprintf(stderr, "Failed to allocate decode packet\n"); |
| 244 | goto end; |
| 245 | } |
| 246 | |
| 247 | if ((ret = open_input_file(argv[1])) < 0) |
| 248 | goto end; |
| 249 | |
| 250 | if (!(enc_codec = avcodec_find_encoder_by_name(argv[2]))) { |
| 251 | fprintf(stderr, "Could not find encoder '%s'\n", argv[2]); |
| 252 | ret = -1; |
| 253 | goto end; |
| 254 | } |
| 255 | |
| 256 | if ((ret = (avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, argv[3]))) < 0) { |
| 257 | fprintf(stderr, "Failed to deduce output format from file extension. Error code: " |
| 258 | "%s\n", av_err2str(ret)); |
| 259 | goto end; |
| 260 | } |
| 261 | |
| 262 | if (!(encoder_ctx = avcodec_alloc_context3(enc_codec))) { |
| 263 | ret = AVERROR(ENOMEM); |
| 264 | goto end; |
| 265 | } |
| 266 | |
| 267 | ret = avio_open(&ofmt_ctx->pb, argv[3], AVIO_FLAG_WRITE); |
| 268 | if (ret < 0) { |
| 269 | fprintf(stderr, "Cannot open output file. " |
| 270 | "Error code: %s\n", av_err2str(ret)); |
| 271 | goto end; |
| 272 | } |
| 273 | |
| 274 | /* read all packets and only transcoding video */ |
| 275 | while (ret >= 0) { |
| 276 | if ((ret = av_read_frame(ifmt_ctx, dec_pkt)) < 0) |
| 277 | break; |
| 278 | |
| 279 | if (video_stream == dec_pkt->stream_index) |
nothing calls this directly
no test coverage detected