# Getting frames from h264 data pointer

**URL:** https://forum.opencv.org/t/getting-frames-from-h264-data-pointer/13175
**Category:** C++
**Created:** [May 12, 2023, 12:59pm UTC](https://forum.opencv.org/t/getting-frames-from-h264-data-pointer/13175 "2023-05-12T12:59:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ricardo\_Sutana](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/ricardo_sutana/32/7878_2.png) [@Ricardo\_Sutana](https://forum.opencv.org/u/Ricardo_Sutana)
#### Post date: [May 12, 2023, 12:59pm UTC](https://forum.opencv.org/t/getting-frames-from-h264-data-pointer/13175/1 "2023-05-12T12:59:27Z")

</div>

Hi folks  
I’m working on SDK for insta360 camera.  
this is the repository for the sdk

> **[GitHub - Insta360Develop/CameraSDK-Cpp: CameraSDK-Cpp is a C++ library to...](https://github.com/Insta360Develop/CameraSDK-Cpp)**
>
> CameraSDK-Cpp is a C++ library to control Insta360 cameras. - GitHub - Insta360Develop/CameraSDK-Cpp: CameraSDK-Cpp is a C++ library to control Insta360 cameras.

The provided sdk has a live stream mode that create and write the stream into a h.h264 file.  
This is the function responsible to write the data into a file:

`void OnVideoData(const uint8_t* data, size_t size, int64_t timestamp, uint8_t streamType, int stream_index = 0) override {}`

My question is about how to display those images stored into the pointer ‘data’ .

I tried

```auto
void OnVideoData(const uint8_t* data, size_t size, int64_t timestamp, uint8_t streamType, int stream_index = 0) override {
            // Create a cv::Mat object from the data pointer
            cv::Mat encodedImage(1, size, CV_8UC1, const_cast<uint8_t*>(data));

            imgDecoded = imdecode(encodedImage,IMREAD_ANYCOLOR);
            cv::imshow("Decoded Image", imgDecoded);
            cv::waitKey(1);

        }

```

but got the error `terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.2.0) ../modules/highgui/src/window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'`

any one could give me a hint about how display those frames.  
I would like to use pure OpenCV. However, I’m open to use FFmpeg, but I just have a zero experience with FFmpeg.

thakyou

---

<div class="post-metadata">

### Author: ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)
#### Post date: [May 12, 2023, 1:36pm UTC](https://forum.opencv.org/t/getting-frames-from-h264-data-pointer/13175/2 "2023-05-12T13:36:25Z")

</div>

can you use any other of their callbacks?

that one is purely for encoded video, and expects you to write it to a file or send it onto the network. it’s a video stream, which requires context. there are no individual “pictures”. it’s video frames. it would require an actual video codec to decode.

there is absolutely no sense in the camera compressing this, only for you to decompress it right away.

look for an API that gives you plain video frames, as bitmaps. not bitmap files. bitmaps. uncompressed (never compressed).

you’d really want to ask _them_ about their API.

---

<div class="post-metadata">

### Author: ![Ricardo\_Sutana](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/ricardo_sutana/32/7878_2.png) [@Ricardo\_Sutana](https://forum.opencv.org/u/Ricardo_Sutana)
#### Post date: [May 12, 2023, 4:59pm UTC](https://forum.opencv.org/t/getting-frames-from-h264-data-pointer/13175/3 "2023-05-12T16:59:58Z")

</div>

Hi @crackwitz  
Thakyou for the reply.

Well…  
This is the only function that I have access to the images in terms of code.  
I can set the camera to record but I cant get the images while recording process run.

I cant open a video capture because the came is no listed on my usb ports.

So, decode those frames (I belive) is the only chance that I have to get a preview image.  
Do you have any other ideia? I’m desperately to get this work.

The API is worst the the sdk in terms of get images.

> **[GitHub - Insta360Develop/Insta360\_OSC](https://github.com/Insta360Develop/Insta360_OSC)**
>
> Contribute to Insta360Develop/Insta360\_OSC development by creating an account on GitHub.

**Update[1]**: the API is based on OSC google protocol. However, the command camera.getLivePreview is no implemented.

best regards
