# How to know codec from stream captured by opencv

**URL:** <https://forum.opencv.org/t/how-to-know-codec-from-stream-captured-by-opencv/4747>\
**Category:** Python\
**Tags:** videoio\
**Created:** [August 13, 2021, 1:22pm UTC](https://forum.opencv.org/t/how-to-know-codec-from-stream-captured-by-opencv/4747 "2021-08-13T13:22:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gondimjoaom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/gondimjoaom/32/2909_2.png) [@gondimjoaom](https://forum.opencv.org/u/gondimjoaom)\
**Post date:** [August 13, 2021, 1:22pm UTC](https://forum.opencv.org/t/how-to-know-codec-from-stream-captured-by-opencv/4747/1 "2021-08-13T13:22:28Z")

</div>

I’m using opencv bindings for python to read a RTSP stream from a camera, do some operations and resend my frame via HTTP. I was wondering if opencv is making some kind of decoding from the stream, and if it is I can change de decoder used by the camera. But when I use cap.get(cv2.CAP\_PROP\_CODEC\_PIXEL\_FORMAT) it returns 808596553.0, and when I use cap.get(cv2.CAP\_PROP\_FOURCC) it returns 1668703592.0.

From these numbers, how can I know the codec being used?

I’ve seen that there is some kind of mapping as when I use cv2.VideoWriter\_fourcc(\*‘h264’) it returns 875967080, but how can I know what the numbers returned from my stream mean?

---

<div class="post-metadata">

**Author:** ![Petala\_Tuy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/petala_tuy/32/2910_2.png) [@Petala\_Tuy](https://forum.opencv.org/u/Petala_Tuy)\
**Post date:** [August 13, 2021, 2:06pm UTC](https://forum.opencv.org/t/how-to-know-codec-from-stream-captured-by-opencv/4747/2 "2021-08-13T14:06:32Z")

</div>

I am trying to figure that out too.

---

<div class="post-metadata">

**Author:** ![edinhoadm](https://avatars.discourse-cdn.com/v4/letter/e/c5a1d2/32.png) [@edinhoadm](https://forum.opencv.org/u/edinhoadm)\
**Post date:** [August 13, 2021, 2:33pm UTC](https://forum.opencv.org/t/how-to-know-codec-from-stream-captured-by-opencv/4747/3 "2021-08-13T14:33:19Z")

</div>

Use this:

```auto
def decode_fourcc(cc):

    return "".join([chr((int(cc) >> 8 * i) & 0xFF) for i in range(4)])

```

**It will return:**

875967080.0 = h264

1668703592.0 = hevc

808596553.0 = I420

---

<div class="post-metadata">

**Author:** ![gondimjoaom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/gondimjoaom/32/2909_2.png) [@gondimjoaom](https://forum.opencv.org/u/gondimjoaom)\
**Post date:** [August 13, 2021, 4:38pm UTC](https://forum.opencv.org/t/how-to-know-codec-from-stream-captured-by-opencv/4747/4 "2021-08-13T16:38:33Z")

</div>

That’s exactly what I was looking for! Thanks!
