| 101 | } |
| 102 | |
| 103 | int main(int argc, char *argv[]) |
| 104 | { |
| 105 | int size, err; |
| 106 | FILE *fin = NULL, *fout = NULL; |
| 107 | AVFrame *sw_frame = NULL, *hw_frame = NULL; |
| 108 | AVCodecContext *avctx = NULL; |
| 109 | const AVCodec *codec = NULL; |
| 110 | const char *enc_name = "h264_vaapi"; |
| 111 | |
| 112 | if (argc < 5) { |
| 113 | fprintf(stderr, "Usage: %s <width> <height> <input file> <output file>\n", argv[0]); |
| 114 | return -1; |
| 115 | } |
| 116 | |
| 117 | width = atoi(argv[1]); |
| 118 | height = atoi(argv[2]); |
| 119 | size = width * height; |
| 120 | |
| 121 | if (!(fin = fopen(argv[3], "r"))) { |
| 122 | fprintf(stderr, "Fail to open input file : %s\n", strerror(errno)); |
| 123 | return -1; |
| 124 | } |
| 125 | if (!(fout = fopen(argv[4], "w+b"))) { |
| 126 | fprintf(stderr, "Fail to open output file : %s\n", strerror(errno)); |
| 127 | err = -1; |
| 128 | goto close; |
| 129 | } |
| 130 | |
| 131 | err = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_VAAPI, |
| 132 | NULL, NULL, 0); |
| 133 | if (err < 0) { |
| 134 | fprintf(stderr, "Failed to create a VAAPI device. Error code: %s\n", av_err2str(err)); |
| 135 | goto close; |
| 136 | } |
| 137 | |
| 138 | if (!(codec = avcodec_find_encoder_by_name(enc_name))) { |
| 139 | fprintf(stderr, "Could not find encoder.\n"); |
| 140 | err = -1; |
| 141 | goto close; |
| 142 | } |
| 143 | |
| 144 | if (!(avctx = avcodec_alloc_context3(codec))) { |
| 145 | err = AVERROR(ENOMEM); |
| 146 | goto close; |
| 147 | } |
| 148 | |
| 149 | avctx->width = width; |
| 150 | avctx->height = height; |
| 151 | avctx->time_base = (AVRational){1, 25}; |
| 152 | avctx->framerate = (AVRational){25, 1}; |
| 153 | avctx->sample_aspect_ratio = (AVRational){1, 1}; |
| 154 | avctx->pix_fmt = AV_PIX_FMT_VAAPI; |
| 155 | |
| 156 | /* set hw_frames_ctx for encoder's AVCodecContext */ |
| 157 | if ((err = set_hwframe_ctx(avctx, hw_device_ctx)) < 0) { |
| 158 | fprintf(stderr, "Failed to set hwframe context.\n"); |
| 159 | goto close; |
| 160 | } |
nothing calls this directly
no test coverage detected