Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add color_range to CodecContext/Frame #686

Merged
merged 5 commits into from
Nov 28, 2023
Merged

Conversation

johanjeppsson
Copy link
Contributor

@johanjeppsson johanjeppsson commented Jul 6, 2020

Hi!

I recently found PyAV, and I am very impressed with how flexible and powerful it is compared to my old go-to-solution, which was calling ffmpeg with a subprocess call! :)

I realized that the color_range option was not implemented so I gave it a shot. Specifically, this can be needed when the default color range for YUV (0-255 or 16-235) needs to be overridden for a codec.

Since I am not deeply familiar with PyAV or the FFmpeg source code, my approach might not be the way to go, and if so I'm happy to update it based on your suggestions. In particular, the change in reformatter.pyx doesn't seem like the right solution to me. As far as I can tell it works as intended, but it definitely has a smell to it...

Also, some tests should probably also be added for this. I don't know if it's enough to test that the color_range property is set as expected when provided as an option, or if some decoding with different color_ranges are preferable?

@johanjeppsson johanjeppsson marked this pull request as draft July 6, 2020 19:27
@johanjeppsson johanjeppsson marked this pull request as ready for review July 8, 2020 13:55
av/video/codeccontext.pyx Outdated Show resolved Hide resolved
@jlaine
Copy link
Member

jlaine commented Aug 27, 2020

@mikeboers I am not familiar with this, any thoughts?

@mikeboers
Copy link
Member

I like the idea.

I'm intrigued by the method of passing the current range to the reformatter by respecting the frame. But we already have {src,dst}_colorspace being passed to the reformatter, so I'm not keen on having two methods of specifying different aspects of the color transform.

Casually looking at it, this block feels like it will have lots of weird state issues.

I think it would be cool to:

  • Have colorspace and color_range properties on a frame.
  • Have the reformatter have {src,dst}_{colorspace,color_range} params.
  • Have the src params take default values from the frame if None.

@jlaine
Copy link
Member

jlaine commented Aug 28, 2020

By the way, could you rebase your changes, it should give you a clean CI baseline?

@johanjeppsson
Copy link
Contributor Author

By the way, could you rebase your changes, it should give you a clean CI baseline?

I think that it should be rebased now.

I like the idea.

I'm intrigued by the method of passing the current range to the reformatter by respecting the frame. But we already have {src,dst}_colorspace being passed to the reformatter, so I'm not keen on having two methods of specifying different aspects of the color transform.

Casually looking at it, this block feels like it will have lots of weird state issues.

I think it would be cool to:

* Have `colorspace` and `color_range` properties on a frame.

* Have the reformatter have `{src,dst}_{colorspace,color_range}` params.

* Have the src params take default values from the frame if None.

Your suggestion sound good, but I feel that I don't have a full grasp all the implications that might come from changing this section. I'll try to have look at it later (hopefully tomorrow) when I have a bit more time on my hands.

Change-Id: I42451b3b84ea7ca4ae645566d1ef4709e0326f92
@johanjeppsson
Copy link
Contributor Author

I like the idea.

I'm intrigued by the method of passing the current range to the reformatter by respecting the frame. But we already have {src,dst}_colorspace being passed to the reformatter, so I'm not keen on having two methods of specifying different aspects of the color transform.

Casually looking at it, this block feels like it will have lots of weird state issues.

I think it would be cool to:

* Have `colorspace` and `color_range` properties on a frame.

* Have the reformatter have `{src,dst}_{colorspace,color_range}` params.

* Have the src params take default values from the frame if None.

I've given your suggestion a shot. Have a look and let me know what you think!

@johanjeppsson
Copy link
Contributor Author

Should I do anything else here?

@jlaine
Copy link
Member

jlaine commented Feb 26, 2021

@mikeboers as I really have no insights into this could you just let me know if this is good to merge?

@riaqn
Copy link

riaqn commented Sep 30, 2021

I wonder what's the status on this PR? really useful to me...

@mfoglio
Copy link

mfoglio commented Nov 23, 2021

Is this feature available in PyAv 8.0.3?

input_container = av.open(url)
input_container.streams.video[0].codec_context.color_range
Traceback (most recent call last):
  File "/home/ubuntu/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
AttributeError: 'av.video.codeccontext.VideoCodecContext' object has no attribute 'color_range'

@jlaine
Copy link
Member

jlaine commented Mar 6, 2022

Unless @mikeboers objects, my only additional request here would be to have some unit tests which exercise:

  • the new getters / setters
  • the additional arguments to reformat

@mikeboers
Copy link
Member

I'm game. 👍

@vade
Copy link

vade commented Nov 10, 2022

Curious on the status of this PR, as this functionality is almost mandatory on professional videos with colorspaces outside of the standard rec.709 assumptions.

Thank you.

@djhaskin987
Copy link

@mikeboers @jlaine I would like to offer my services if there is anything else needed to get this PR across the finish line.

I am very grateful for the existence of this library. It has helped immensely at my place of work in doing what we do. This PR would really allow add that extra polish to something I'm working on at work.

You should let me help. What can I do?

@hmaarrfk
Copy link
Contributor

As an outsider (but also user of this library) I think that generally the norm in the open source community is to:

  1. Attempt to fork off @johanjeppsson work
  2. Maintain their git commit history (rebase or merge)
  3. Build commits onto of it to address @jlaine's requests for light testing

@jlaine
Copy link
Member

jlaine commented Nov 9, 2023

@WyattBlue I think something went badly wrong with your git manipulation, there are now ten of commits in this PR?

@WyattBlue
Copy link
Member

@jlaine I think I reverted those dummy commits. Didn't know merging in a fork would edit the PR.

@WyattBlue WyattBlue added the tests requested Please add tests to your PR label Nov 11, 2023
@WyattBlue WyattBlue merged commit 8aa5fe7 into PyAV-Org:main Nov 28, 2023
16 checks passed
@WyattBlue WyattBlue removed the tests requested Please add tests to your PR label Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants