#pragma once #ifdef VP_WITH_FFMPEG #include #include #include #include #include #include #include extern "C" { #include #include #include #include #include #include #include } #define ff_av_packet_ptr std::shared_ptr #define ff_av_frame_ptr std::shared_ptr #define ff_src_ptr std::shared_ptr #define ff_des_ptr std::shared_ptr #define ff_scaler_ptr std::shared_ptr #define alloc_ff_src(channel_index) std::make_shared(channel_index) #define alloc_ff_des(channel_index) std::make_shared(channel_index) #define alloc_ff_scaler(src_width, src_height, src_fmt, dst_width, dst_height, dst_fmt) \ std::make_shared(src_width, src_height, src_fmt, dst_width, dst_height, dst_fmt) #define alloc_ff_av_frame() \ std::shared_ptr(av_frame_alloc(), [](AVFrame *frame) { av_frame_free(&frame); }) #define alloc_ff_av_packet() \ std::shared_ptr(av_packet_alloc(), [](AVPacket *pkt) { av_packet_free(&pkt); }) namespace vp_nodes { /** * tools for color conversion & image resize using FFmpeg on CPUs. * */ class ff_scaler { private: SwsContext* sws_ctx = NULL; int m_src_width; int m_src_height; AVPixelFormat m_src_fmt; int m_dst_width; int m_dst_height; AVPixelFormat m_dst_fmt; public: /* disable copy and assignment operations */ ff_scaler(const ff_scaler&) = delete; ff_scaler& operator=(const ff_scaler&) = delete; ff_scaler(int src_width, int src_height, AVPixelFormat src_fmt, int dst_width, int dst_height, AVPixelFormat dst_fmt); ~ff_scaler(); bool scale(ff_av_frame_ptr src, ff_av_frame_ptr& dst); }; } #endif