@@ -81,11 +81,20 @@ int av_frame_copy(AVFrame *dst, const AVFrame *src)
8181
8282#endif // LIBAVUTIL_VERSION_INT <= 53.5.0 (ffmpeg 2.2)
8383
84+ void avcpp_null_deleter (void * /* opaque*/ , uint8_t */*data*/)
85+ {
86+ }
87+
8488} // anonymous namespace
8589
8690namespace av
8791{
8892
93+ VideoFrame::VideoFrame ()
94+ {
95+
96+ }
97+
8998VideoFrame::VideoFrame (PixelFormat pixelFormat, int width, int height, int align)
9099{
91100 m_raw->format = pixelFormat;
@@ -231,6 +240,49 @@ bool VideoFrame::copyToBuffer(std::vector<uint8_t> &dst, int align, OptionalErro
231240 return copyToBuffer (dst.data (), dst.size (), align, ec);
232241}
233242
243+ namespace {
244+ VideoFrame _wrap (const void *data, size_t size, PixelFormat pixelFormat, int width, int height, int align,
245+ void (*deleter)(void *opaque, uint8_t *data), void *opaque)
246+ {
247+ VideoFrame out;
248+
249+ auto frame = out.raw ();
250+
251+ frame->format = pixelFormat;
252+ frame->width = width;
253+ frame->height = height;
254+
255+ // setup buffers
256+ frame->buf [0 ] = av_buffer_create (const_cast <uint8_t *>(static_cast <const uint8_t *>(data)), size, deleter, opaque, AV_BUFFER_FLAG_READONLY );
257+
258+ av_image_fill_arrays (frame->data ,
259+ frame->linesize ,
260+ frame->buf [0 ]->data ,
261+ pixelFormat, width, height, align);
262+
263+ frame->extended_data = frame->data ;
264+
265+ return out;
266+ }
267+ }
268+
269+ VideoFrame VideoFrame::wrap (const void *data, size_t size, PixelFormat pixelFormat, int width, int height, int align)
270+ {
271+ return _wrap (data, size, pixelFormat, width, height, align, avcpp_null_deleter, nullptr );
272+ }
273+
274+ #ifdef __cpp_lib_span
275+ VideoFrame VideoFrame::wrap (std::span<const std::byte> data, PixelFormat pixelFormat, int width, int height, int align)
276+ {
277+ return wrap (data.data (), data.size (), pixelFormat, width, height, align);
278+ }
279+
280+ VideoFrame VideoFrame::wrap (std::span<const std::byte> data, void (*deleter)(void *opaque, uint8_t *data),
281+ void *opaque, PixelFormat pixelFormat, int width, int height, int align)
282+ {
283+ return _wrap (data.data (), data.size (), pixelFormat, width, height, align, deleter, opaque);
284+ }
285+ #endif
234286
235287AudioSamples::AudioSamples (SampleFormat sampleFormat, int samplesCount, uint64_t channelLayout, int sampleRate, int align)
236288{
0 commit comments