# How to get out manipulated frames lossless?

**URL:** <https://forum.opencv.org/t/how-to-get-out-manipulated-frames-lossless/14873>\
**Category:** C++\
**Tags:** videoio\
**Created:** [October 16, 2023, 8:42am UTC](https://forum.opencv.org/t/how-to-get-out-manipulated-frames-lossless/14873 "2023-10-16T08:42:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nji9](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@nji9](https://forum.opencv.org/u/nji9)\
**Post date:** [October 16, 2023, 8:42am UTC](https://forum.opencv.org/t/how-to-get-out-manipulated-frames-lossless/14873/1 "2023-10-16T08:42:02Z")

</div>

It’s not long that I came to OpenCV so my experience  
is quite limited.  
Recently I had the task of analysing/ manipulation  
video material where OpenCV’s algs do fit very well.  
But first of all I checked if there are no problems  
reading in a video and writing it out losslessly right away.  
I wasn’t successful with it, no matter what I tried:

I read a video (YUV4.2.1) from file by VideoCapture,  
get the frames into Mat structure  
and write them back by a VideoWriter.  
But the existing lossless codecs (FFV1 and HFYU) produce  
all a bit darker than the original (as they are converted to RGBA?).

So my question:  
How do I get out video material lossless?  
(Somewhere I read to use ffmpeg directly…  
Does this mean I should write a VideoCapture on my own?)

Actually I cannot understand how this could be a problem  
as I’m at v.3.4.10, and not 0.4beta… 🙂

Thank you for hints.

---

<div class="post-metadata">

**Author:** ![nji9](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@nji9](https://forum.opencv.org/u/nji9)\
**Post date:** [October 17, 2023, 8:50am UTC](https://forum.opencv.org/t/how-to-get-out-manipulated-frames-lossless/14873/2 "2023-10-17T08:50:27Z")

</div>

Addendum:  
Can anybody please confirm or disconfirm that?  
BTW Not only that the specifications of FFV1 and HFYU do not allow RGB(A).  
Also VideoWriter’s AVC1 output is bad and wrong.  
Will this do in v.4.8?

---

<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:** [October 17, 2023, 10:01am UTC](https://forum.opencv.org/t/how-to-get-out-manipulated-frames-lossless/14873/3 "2023-10-17T10:01:42Z")

</div>

> [@nji9](#):
>
> VideoWriter’s AVC1 output is bad and wrong.

no. it is perfectly fine. you might have to adjust bitrate or quality level.

> [@nji9](#):
>
> losslessly

use a lossless codec and it can be. do you think you used lossless codecs?

apart from compression, there’s the matter of color spaces.

> [@nji9](#):
>
> Does this mean I should write a VideoCapture on my own?)

that might be best. use ffmpeg’s libraries directly.

there are ways to disable some of the processing that opencv performs on decoded video frames. I can’t tell if that will satisfy you.

best to write your own.

---

<div class="post-metadata">

**Author:** ![nji9](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@nji9](https://forum.opencv.org/u/nji9)\
**Post date:** [October 17, 2023, 10:24am UTC](https://forum.opencv.org/t/how-to-get-out-manipulated-frames-lossless/14873/4 "2023-10-17T10:24:26Z")

</div>

Thanks for your reply 🙂  
Still…

1. There is no way to adjust bitrate level. Just the quality level. And setting this has NO effect at all. The default value (which?) produces bad and wrong result filtes. Did you checked it by yourself? I did.
2. As I wrote opencv only offers only FFV1 and HFYU for lossless encoding. And VideoWrite always writes them as RGB(A) (as mentioned which doesn’t exist by specification).
3. What do you mean by “use ffmepeg’s libraries directly”? Write my own VideoWriter?
4. Again: Does v.4.8. works correctly (not in theory but in practise)?

---

<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:** [October 17, 2023, 11:03am UTC](https://forum.opencv.org/t/how-to-get-out-manipulated-frames-lossless/14873/5 "2023-10-17T11:03:51Z")

</div>

> [@nji9](#):
>
> Did you checked it by yourself? I did.

provide a [MRE](https://stackoverflow.com/help/minimal-reproducible-example) and I might.

> [@nji9](#):
>
> There is no way to adjust bitrate level.

there is. just undocumented.

- [Documentation for OPENCV\_FFMPEG\_WRITER\_OPTIONS and OPENCV\_FFMPEG\_CAPTURE\_OPTIONS · Issue #21155 · opencv/opencv · GitHub](https://github.com/opencv/opencv/issues/21155)
- [https://github.com/search?q=repo%3Aopencv%2Fopencv%20OPENCV\_FFMPEG\_WRITER\_OPTIONS&type=code](https://github.com/search?q=repo%3Aopencv%2Fopencv%20OPENCV_FFMPEG_WRITER_OPTIONS&type=code)
