View Issue Details

IDProjectCategoryView StatusLast Update
0000605Cinelerra-GG[All Projects] Featurepublic2022-05-13 04:48
ReporterPhyllisSmith Assigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
Status newResolutionopen 
Product Version 
Target VersionFixed in Version 
Summary0000605: Add option to prevent hard-clipping when using MPEG as the YUV color range
DescriptionSo this does not get lost, am adding it here. For details on this refer to the Forum topic:
  https://www.cinelerra-gg.org/forum/help-video/yuv-to-rgb-conversion-issues/#post-2050

Is there any way to prevent the RGB-FLOAT conversion from clipping the highlights?
Is there any way that this functionality could be changed, or an option added to prevent everything being hard-clipped when using MPEG as the YUV color range? Perhaps only hard-clip the range closer to the output after video effects have been applied?

I think that a better way of working would be to allow the values outside of 16-235 to continue to exist (rather than being hard-clipped) in a RGB-FLOAT project with color range set to MPEG. These values would be outside the legal range in the scopes, but at least we could pull them back into range and recover highlights/shadows during colour correction

It seems that the main problem is that what is seen in the compositor is simply not the same as seen in other editors or players unless MPEG is selected as the YUV color range. This comes with the caveat that anything outside the 16-235 range is hard clipped.

TagsNo tags attached.

Activities

Andrew-R

Andrew-R

2022-05-13 04:48

reporter   ~0005300

there is also 'colorspace' plugin, hopefully it also can convert part of timeline between those colorspaces
glitterball

glitterball

2022-04-23 21:03

reporter   ~0005294

@Andrew-R You are quite right about the colorspace filter: I had not seen the 'irange' option and had only played with 'range'.

When YUV color range is set to MPEG (in Cin Preferences>Appearance), setting irange to 2 in the colorspace filter does change the contrast, however the data outside the 16-235 range is already gone (clipped).

Interestingly, when YUV color range is set to JPEG, using the colorspace plugin to set the range to MPEG does not hard clip, and values outside the 16-235 range can be be brought back into range using another plugin such as Blue Banana.
Andrew-R

Andrew-R

2022-04-23 18:49

reporter   ~0005293

so, this hack shows color range for asset in it info window..

how just need to learn how to make this dropdown list, and pass user selection back to program..

asset_col_range_show.diff (1,626 bytes)
diff --git a/cinelerra-5.1/cinelerra/assetedit.C b/cinelerra-5.1/cinelerra/assetedit.C
index 9bdf847f..2f232833 100644
--- a/cinelerra-5.1/cinelerra/assetedit.C
+++ b/cinelerra-5.1/cinelerra/assetedit.C
@@ -195,7 +195,7 @@ BC_Window* AssetEdit::new_gui()
 
 int AssetEdit::window_height()
 {
-	int h = yS(128 + 64);
+	int h = yS(128 + 64 + 32);
 	if( indexable->have_audio() ) h += yS(200);
 	if( indexable->have_video() ) {
 		h += yS(160);
@@ -529,6 +529,27 @@ void AssetEditWindow::create_objects()
 				(ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_asset_modes,
 				x2 + edit_ilace_mode->get_w(), y));
 			y += title->get_h() + yS(15);
+		if( asset ) {
+			add_subwindow(title = new BC_Title(x1, y, _("Asset's color_range:")));
+			char col_range[64];
+			strcpy(col_range, "Unk");
+			if(asset->ff_color_range == 0)
+			strcpy(col_range, "PC");
+			if (asset->ff_color_range == 1)
+			strcpy(col_range, "TV");
+			sprintf(string, "%s", col_range);
+			title = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
+			add_subwindow(title);
+			y += title->get_h() + ypad5;
+/*			ilacemode_to_text(string, asset->interlace_mode);
+			AssetEditILacemode *edit_ilace_mode;
+			add_subwindow(edit_ilace_mode = new AssetEditColorRangemode(this, string, x2, y, xS(160)));
+			add_subwindow(new AssetEditColorRangePulldown(mwindow, edit_color_range_mode,
+				&asset_edit->changed_params->ff_color_range,
+				(ArrayList<BC_ListBoxItem*>*)&mwindow->color_range_modes,
+				x2 + edit_color_range_mode->get_w(), y));
+			y += title->get_h() + yS(15);*/
+		}
 		}
 	}
 	if( asset && asset->timecode >= 0 ) {
Andrew-R

Andrew-R

2022-04-23 18:08

reporter   ~0005292

so, cin already carries this info in

ff_color_range variable in asset.c

$ grep ff_color_range cinelerra/*
grep: cinelerra/armv8l: Is a directory
cinelerra/asset.C: ff_color_range = -1;
cinelerra/asset.C: ff_color_range = asset->ff_color_range;
cinelerra/asset.C: ff_color_range = GET_DEFAULT("FF_COLOR_RANGE", ff_color_range);
cinelerra/asset.C: UPDATE_DEFAULT("FF_COLOR_RANGE", ff_color_range);
cinelerra/asset.C: fprintf(fp," ff_color_range=%d\n", ff_color_range);
cinelerra/asset.h: int ff_color_space, ff_color_range;
grep: cinelerra/ci: binary file matches
grep: cinelerra/data: Is a directory
cinelerra/ffmpeg.C: if( (vid->color_range = asset->ff_color_range) < 0 )
cinelerra/ffmpeg.C:int FFMPEG::ff_color_range(int stream)
cinelerra/ffmpeg.h: int ff_color_range(int stream);
cinelerra/fileffmpeg.C: if( asset->ff_color_range < 0 )
cinelerra/fileffmpeg.C: asset->ff_color_range = ff->ff_color_range(0);
grep: cinelerra/randrik: Is a directory
grep: cinelerra/tests: Is a directory


we just need to expose it as changeable param in assetedit.c|h

or so I think...
Andrew-R

Andrew-R

2022-04-23 17:44

reporter   ~0005291

@glitterball this filter have two ranges - range for output and irange for input..

setting range to mpeg while irange at jpeg (with jpeg in prefs) definitely changes output picture...
glitterball

glitterball

2022-04-23 16:46

reporter   ~0005290

@Andrew-R

Yeah, I tried that filter, and changing the range there doesn't seem to make any difference either.
Andrew-R

Andrew-R

2022-04-23 16:31

reporter   ~0005289

@glitterball have you tried ffmpeg plugin I mentioned (with cin preference set to full)?
glitterball

glitterball

2022-04-23 16:27

reporter   ~0005288

@Andrew-R

I tried changing the x11 settings as suggested and none of the changes made any difference.
Rendering a video produces a file where the those values are clipped.

The only way to keep the full range is to set the YUV color range to 'JPEG' in appearance.
However this means that all clips must be transcoded to the same range before being imported into Cinelerra, as Cinelerra cannot handle video files with differing ranges within the same project.
Andrew-R

Andrew-R

2022-04-22 14:57

reporter   ~0005287

@glitterball, as far as I can see this preferences setting control ffmpeg's swscaler, before it converted to rgba-float.

May be x11 output clip them? try x11-opengl, try uncheck direct x11 path, also try to render into some image/video file and see if those values still around.... if they are - then we need to look at video output specifically...
glitterball

glitterball

2022-04-22 14:39

reporter   ~0005286

@Andrew-R
Sorry I wasn't clearer: it makes no visible difference to the clip (I.e. everything outside 16-35 is still clipped even with those settings).

I do get some extra error messages when adding the .opts file mostly "[swscaler @ 0x7efd9c20d900] deprecated pixel format used, make sure you did set range correctly"
Andrew-R

Andrew-R

2022-04-22 12:39

reporter   ~0005285

@glitterball

$ cat ~/matrixbench_highdivx_ac3.opts
#lowres=1
#fast=1
#video_filter=format=yuv422p
video_filter=scale=in_range=limited:out_range=full


sorry, try optS?

in my case it prints something:
[swscaler @ 0xe0d24000] No accelerated colorspace conversion found from yuv420p to rgba.
glitterball

glitterball

2022-04-22 12:17

reporter   ~0005284

@Andrew-R
Thanks for the response, I gave your suggestion a go, but unfortunately adding the .opt file didn't appear to make any difference.
Andrew-R

Andrew-R

2022-04-22 09:48

reporter   ~0005283

@glitterball, yeah, from user perspective this is good idea, nit sure if I am up to task about coding it (soecifically, not sure if ffmpeg>cin transfer has access to specifics of assets/clips)

I found another answer, you can try to add this into opt files, one per asset/file

https://superuser.com/questions/1405177/ffmpeg-how-to-handle-color-range-conversions

"Input is limited range, I want to output full range

Use the scale filter, -vf scale=in_range=limited:out_range=full"

try to put this line (without leading "-") in file named exactly like your input file just with opt extension...?

sure, this is workaround (if it works as I think it works!) and not resolution..
glitterball

glitterball

2022-04-22 08:31

reporter   ~0005282

The way Davinci Resolve handles this, is to allow the user to set whether a clip's data levels are 16-235 or 0-255 under 'Clip Attributes'.
Specifically there is a radio button under 'Clip Attributes' (right-click on a clip, then Clip Attributes) called 'Data Levels' with the following options: Auto, Video or Full.

In Cinelerra, the same options could be provided in the 'Info...' dialog box (found by right-clicking on a file in Resources>Media).

Thinking about it, this is the logical solution, as many video projects will use video files with differing frame rates, data levels etc, so it should be possible to set this on a per-file basis rather than project-wide.

I also note that the 'auto' option for data levels did not work in Davinci Resolve, and I had to set this manually.
Andrew-R

Andrew-R

2022-01-29 04:48

reporter   ~0005246

also, may be ffmpeg's filter colorspace can help here? seems to be enabled in Cingg and suppirts >8 bit depth
https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/vf_colorspace.c
Andrew-R

Andrew-R

2022-01-29 04:11

reporter   ~0005244

does same problem exist in ffmpeg? I think until recently ffmpeg was internally 8bit, so clipping may happen there...

Issue History

Date Modified Username Field Change
2022-01-28 17:39 PhyllisSmith New Issue
2022-01-29 04:11 Andrew-R Note Added: 0005244
2022-01-29 04:48 Andrew-R Note Added: 0005246
2022-04-22 08:31 glitterball Note Added: 0005282
2022-04-22 09:48 Andrew-R Note Added: 0005283
2022-04-22 12:17 glitterball Note Added: 0005284
2022-04-22 12:39 Andrew-R Note Added: 0005285
2022-04-22 14:39 glitterball Note Added: 0005286
2022-04-22 14:57 Andrew-R Note Added: 0005287
2022-04-23 16:27 glitterball Note Added: 0005288
2022-04-23 16:31 Andrew-R Note Added: 0005289
2022-04-23 16:46 glitterball Note Added: 0005290
2022-04-23 17:44 Andrew-R Note Added: 0005291
2022-04-23 18:08 Andrew-R Note Added: 0005292
2022-04-23 18:49 Andrew-R File Added: asset_col_range_show.diff
2022-04-23 18:49 Andrew-R Note Added: 0005293
2022-04-23 21:03 glitterball Note Added: 0005294
2022-05-13 04:48 Andrew-R Note Added: 0005300