30 {
31 avcodec_register_all();
32 AVCodec* codec_h265 = avcodec_find_decoder(AV_CODEC_ID_H265);
33 if (codec_h265 == nullptr) {
34 AERROR <<
"error: codec not found";
35 return false;
36 }
37 codec_ctx_h265_ = avcodec_alloc_context3(codec_h265);
38 if (codec_ctx_h265_ == nullptr) {
39 AERROR <<
"error: codec context alloc fail";
40 return false;
41 }
42 if (avcodec_open2(codec_ctx_h265_, codec_h265, nullptr) < 0) {
43 AERROR <<
"error: could not open codec";
44 return false;
45 }
46 yuv_frame_ = av_frame_alloc();
47 if (yuv_frame_ == nullptr) {
48 AERROR <<
"error: could not alloc yuv frame";
49 return false;
50 }
52 if (codec_jpeg == nullptr) {
53 AERROR <<
"error: jpeg Codec not found";
54 return false;
55 }
56 codec_ctx_jpeg_ = avcodec_alloc_context3(codec_jpeg);
57 if (codec_ctx_jpeg_ == nullptr) {
58 AERROR <<
"error: jpeg ctx allco fail";
59 return false;
60 }
61
62 codec_ctx_jpeg_->bit_rate = 400000;
63 codec_ctx_jpeg_->codec_type = AVMEDIA_TYPE_VIDEO;
65 codec_ctx_jpeg_->width = 1920;
66 codec_ctx_jpeg_->height = 1080;
67 codec_ctx_jpeg_->time_base = (AVRational){1, 15};
68 codec_ctx_jpeg_->pix_fmt = AV_PIX_FMT_YUVJ422P;
69 if (avcodec_open2(codec_ctx_jpeg_, codec_jpeg, nullptr) < 0) {
70 AERROR <<
"error: could not open jpeg context";
71 return false;
72 }
73 return true;
74}
#define AV_CODEC_ID_MJPEG