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

wrong color space and range convert when filter graph use "format=rgba" #161

Closed
x850044053wwt opened this issue Dec 23, 2024 · 8 comments
Closed
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@x850044053wwt
Copy link

x850044053wwt commented Dec 23, 2024

input yuv444p bt709 tv range,convert to rgba format,output rgba color looks fading
ffmpeg complain when calling av_buffersrc_add_frame_flags :

[src_0 @ 0000026ab60be580] Changing video frame properties on the fly is not supported by all filters.
[src_0 @ 0000026ab60be580] filter context - w: 1080 h: 1080 fmt: 0 csp: unknown range: unknown, incoming frame - w: 1080 h: 1080 fmt: 0 csp: bt709 range: tv pts_time: 0.000989583
@JackLau1222 JackLau1222 added the enhancement New feature or request label Dec 24, 2024
@JackLau1222
Copy link
Collaborator

Thanks for your feedback, we will check and fix it as soon as possible

@x850044053wwt
Copy link
Author

x850044053wwt commented Dec 24, 2024

After confirmation, this will not be a problem,encoder make result looks fading

` nlohmann::json graph_para = {
{"dump_graph", 0}
};
auto graph = bmf::builder::Graph(bmf::builder::NormalMode,
bmf_sdk::JsonParam(graph_para));

nlohmann::json decode_para = {
{"input_path", "D:/work/bmf_example_files/big_bunny_10s_30fps.mp4"}
};
nlohmann::json enc_para = {
{"output_path", "D:/Documents/Downloads/result.mp4"}
};

auto decoder = graph.Decode(bmf_sdk::JsonParam(decode_para));
auto rgba = graph.FFMpegFilter({ decoder[0] }, "format", "rgba");
graph.Encode(rgba[0], decoder["audio"], bmf_sdk::JsonParam(enc_para));
graph.Run();`

result, first is raw image at 9s, second is yuv420p->rgba->yuv420p, they are not the same, Especially when the colors are bright
image
image

@x850044053wwt
Copy link
Author

x850044053wwt commented Dec 24, 2024

before encoder, rgba Tensor is the same as raw. There is no problem when using ffmpeg cmd:
ffmpeg -i raw.mp4 -filter_complex "[0:v]format=rgba[rgba];[rgba]format=yuv420p[yuv420p]" -map "[yuv420p]" output.mp4

@sfeiwong
Copy link
Collaborator

before encoder, rgba Tensor is the same as raw. There is no problem when using ffmpeg cmd: ffmpeg -i raw.mp4 -filter_complex "[0:v]format=rgba[rgba];[rgba]format=yuv420p[yuv420p]" -map "[yuv420p]" output.mp4

So, do you mean it's still fading after BMF encoding? What's the csc range of the encoded video?

@x850044053wwt
Copy link
Author

x850044053wwt commented Dec 24, 2024

before encoder, rgba Tensor is the same as raw. There is no problem when using ffmpeg cmd: ffmpeg -i raw.mp4 -filter_complex "[0:v]format=rgba[rgba];[rgba]format=yuv420p[yuv420p]" -map "[yuv420p]" output.mp4

So, do you mean it's still fading after BMF encoding? What's the csc range of the encoded video?

yes, it still fading after BMF encoding. before encoding csc = CS_RGB, cr= CR_JPEG. However, changing rgb ColorModel property doesn't effect encoded video.
After discovering this problem, I simply made the above example to reflect this problem.

@x850044053wwt
Copy link
Author

x850044053wwt commented Dec 24, 2024

update debug result:
1、before encoder avcodec_send_frame,dump AVFrame to yuv binary,result shows Cr data offset is Wrong
2、get_filter_frame && [i0_0]scale=1080:1440,format=pix_fmts=yuv420p[o0_0] filter graph make Cr data wrong

@sfeiwong
Copy link
Collaborator

Could you please try bellow PR to verify whether the issue was resolved?
#162

@HuHeng
Copy link
Collaborator

HuHeng commented Dec 26, 2024

After some research, if you need to convert from RGB to YUV (BT.709), you need to explicitly specify the color space. You can use either the "format" filter of FFmpeg 7.1 or the "scale" filter with some parameters to do this.

@sfeiwong sfeiwong added the documentation Improvements or additions to documentation label Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants