View Full Version : Help Encoding 0-255 PC to 0-255 TV with BTB & WTW (x264)
James Freeman
4th November 2013, 10:48
I need help to encode a video captured with Camstudio in fullrange 0-255, to a TV range with 0-255 (16-235 native with BTB & WTW).
I need steps 16 & 235 to be the native black and white and steps 0-15, 236-255 to be BTB & WTW.
Much like what is in the AVS709HD Black Test Pattern.
Anything I've tried with: x264 --range --input-range, has failed to do what I want.
Again,
I need steps 16 & 235 to be the native black and white and steps 0-15, 236-255 to be BTB & WTW.
Thanks
sneaker_ger
4th November 2013, 12:32
Is that even possible? 0-255 full range does not have values that are outside that. They'd have to be extrapolated or similar.
James Freeman
4th November 2013, 12:45
Is that even possible? 0-255 full range does not have values that are outside that. They'd have to be extrapolated or similar.
Ok, lets make it simpler.
1. I have created a test pattern with blacks from 0 to 30 in Paint.
2. Then I captured an .avi video with CamStudio with the lossless codec in a regulat 0-255 PC range.
3. Now I want to convert it into a test pattern video so that step 16 is black, and 0-15 are BTB.
So that when I set range to 0-255 in MadVR (for example), steps 0-15 are clipped.
But when I set to 16-235, steps 0-15 are visible.
Exactly like AVS709HD Black Test Pattern.
How do I do that?
Maybe its encoding properties will help:
General
Complete name : E:\Monitor Calibration\AVS HD 709\Basic Settings\1-Black Clipping.mp4
Format : MPEG-4
Format profile : JVT
Codec ID : avc1
File size : 15.1 MiB
Duration : 5mn 0s
Overall bit rate : 422 Kbps
Encoded date : UTC 2010-09-20 04:04:57
Tagged date : UTC 2010-09-20 04:04:57
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : Main@L4.0
Format settings, CABAC : Yes
Format settings, ReFrames : 3 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 5mn 0s
Bit rate : 421 Kbps
Nominal bit rate : 15.0 Mbps
Maximum bit rate : 616 Kbps
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.976 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.008
Stream size : 15.1 MiB (100%)
Writing library : x264 core 104 r1713 c276662
Encoding settings : cabac=1 / ref=4 / deblock=1:0:0 / analyse=0x1:0x131 / me=tesa / subme=10 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=24 / chroma_me=1 / trellis=2 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=0 / chroma_qp_offset=-2 / threads=12 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / constrained_intra=0 / bframes=3 / b_pyramid=1 / b_adapt=2 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=0 / keyint=48 / keyint_min=4 / scenecut=40 / intra_refresh=0 / rc_lookahead=48 / rc=2pass / mbtree=1 / bitrate=15000 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / vbv_maxrate=15000 / vbv_bufsize=9000 / ip_ratio=1.40 / aq=1:1.00 / nal_hrd=none
Encoded date : UTC 2010-09-20 04:04:57
Tagged date : UTC 2010-09-20 04:18:24
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709
sneaker_ger
4th November 2013, 13:09
You would just have to make sure that x264 does not convert the range in any way, i.e. don't use --range and --input range or set them to identical values. If you set madvr to pc input and pc output nothing should be clipped, if you set it to tv input and pc output there should be clipping. In the former case black (16) will look gray though.
James Freeman
4th November 2013, 13:47
@sneaker_ger
No combination of "range" command in x264 does what I intend.
When I set MadVR to 16-235, the test pattern should retain the 0-255 range and not elevate the blacks (0) to 16.
I have attached a printscreen image of the AVS709 Black Test pattern in 16-235 range (MadVR).
You can use the "Color Picker" (Pipette) in Paint to actually see that the background is 8, which is lower than 16.
There IS information BELOW 16 and ABOVE 235 in the "16-235" range (BTB & WTW), I want to recreate that.
Thanks.
sneaker_ger
4th November 2013, 14:06
When I set MadVR to 16-235
As I indicated above madVR has two settings, one for input range and one for output range. I'd say you have to be clearer as to how you set both of them but there's not much more to be said than what I already did.
James Freeman
4th November 2013, 14:24
@sneaker_ger
The Input range is of the original AVS709HD Black Bars Test Pattern (mp4) Video.
MadVR only has one toggle for range, I set it to 16-235 to NOT clip below 16.
Now, there should not be information below 16 in a 16-235 video (I repeat myself here), but there is !!!
Its called Blacker-than-Black (you know that, but its for emphasis anyway), and I want to recreate that in my videos.
How do I do that?
sneaker_ger
4th November 2013, 14:28
MadVR only has one toggle for range, I set it to 16-235 to NOT clip below 16.
No, it has two. One in the display properties and one for the input (the one you see when you press ctrl+j). If you set the latter to 16-235 while using pc output for the display there will be clipping because madVR expands 16->0 and 235->255.
James Freeman
4th November 2013, 14:36
I don't see any input range in the info (Ctrl+J).
And I think you got that the other way around.
When MadVR set to 0-255 then it clips below 16 and stretches it to 0.
I quote myself:
...I set it to 16-235 to NOT clip below 16.
Anyone else can help me to retain BTB in my videos?
sneaker_ger
4th November 2013, 14:39
"limited range (says upstream)" means madVR treats the input as 16-235. By default display devices are set to 0-255 which means BTB and WTW will be clipped. If you set the display to 16-235 in the properties there should not be any clipping unless Windows/the graphic driver/the display is interfering somehow. From your screenshot it looks like there isn't any clipping, i.e. the output is set to 16-235.
James Freeman
4th November 2013, 14:49
Yes, I understand that sneaker_ger, I am not new to MadVR or video.
The video I captured (totally black desktop) says "full range (says upstream)" but still comes as pale grey when I play it back (with 16-235) range.
While AVS709 test pattern retain lower blacks (below 16) with this 16-235 setting.
Hence I concluded that there is no BTB in my video.
It has NOTHING to do with MadVR, I think it is somewhere in the capturing (codec) chain.
Any idea how I should enable BTB as in the AVS709 test pattern (3rd time already)?
Thanks.
sneaker_ger
4th November 2013, 15:00
The video I captured (totally black desktop) says "full range (says upstream)" but still comes as pale grey when I play it back (with 16-235) range.
Switch madVR's input range manually by pressing ctrl + alt + shift + I until it looks as desired. Is "TV" enough or does it need to be double or triple expanded?
While AVS709 test pattern retain lower blacks (below 16) with this 16-235 setting.
Hence I concluded that there is no BTB in my video.
Yes, that could be true.
Maybe you should just upload a sample of your avi. I have no experience with Camstudio, though. I trusted you when you said "a video captured with Camstudio in fullrange 0-255" but maybe something went wrong there already.
James Freeman
4th November 2013, 21:59
Thanks.
Ctrl+Shift+Alt+I did the trick to the original video (I didn't know I can do that).
I have changed from PC to TV and suddenly 16 became Black.
Good.
Now I only need to tag the video with "TV range" so that the decoder will know that its a TV range video automatically.
When I pass the original video through x264.exe it changes the rage against my will.
I have tried every range/input-range (tv, pc) command to avert this, but to no avail.
Is there a command in x264 to NOT touch the video at all? (I have tried -qp 0 but it didn't work)
Only add "TV range" tag.
sneaker_ger
4th November 2013, 22:35
I have tried every range/input-range (tv, pc) command to avert this, but to no avail.
That can't be true. Try --range tv --input-range tv.
James Freeman
4th November 2013, 22:41
That can't be true. Try --range tv --input-range tv.
No.
Now it is tagged as TV (already tried it), but 16 is not black.
x264 converts the video range no matter what.
Original video attached.
Changing it to TV input with madVR does what I want (its in PC range).
Direct Download:
http://www.mediafire.com/download/eboi1vw0wfknrzn/Black.avi
sneaker_ger
4th November 2013, 22:58
Maybe I misunderstood. I will wait for the approval of your attachment. Maybe it is the way you are decoding the video when feeding to x264, not x264 itself. Or if the source is RGB x264 does PC RGB to TV YUV and you can't flag as PC while not expanding at the same time.
As I have no experience with Camstudio I might also suggest a different way: open your paint picture with an image source filter in AviSynth and control the RGB->YUV conversion yourself.
James Freeman
4th November 2013, 23:15
Direct link added.
I think the original is already in YUV 4:4:4.
I have never used AviSynth code.
sneaker_ger
4th November 2013, 23:29
The source is RGB and that's why the conversion can't be controlled the way you want to. The AviSynth script is:
ffVideoSource("black.avi")
converttoyv12(matrix="PC.601")
You just need to install AviSynth, copy the ffms2 plugin into its plugin folder (or load manually) and open the script with 32 bit x264:
x264 script.avs -o output.h264
It will flag tv range by default. If you want to flag pc range add --range pc --input-range pc. (Equal to "x264 black.avi -o output.h264 --range pc --input-range pc")
James Freeman
5th November 2013, 07:06
I get an error:
avs [error]: avs [error]: Script error: there is no function named "FFVideoSource"
(script.avs, line 1)
x264 [error]: could not open input file `script.avs'
I tried to put ffms2.dll & ffmsindex.exe in C:\windows\system32, but no.
drmpeg
5th November 2013, 09:01
You may want to take a look at this thread on AvsForum.
http://www.avsforum.com/t/918654/creating-test-patterns
It's where I show the AVS709 folks how to make patterns (my screen name over there is dr1394).
Ron
Warperus
5th November 2013, 09:42
James Freeman
Use AviSource instead of ffVideoSource.
James Freeman
5th November 2013, 11:38
Thanks everybody.
Its not worth the hassle.
I will do with MadVR internal range changer.
sneaker_ger
5th November 2013, 13:21
I tried to put ffms2.dll & ffmsindex.exe in C:\windows\system32, but no.
The files belong into e.g. c:\program files (x86)\AviSynth 2.5\plugins
Simply using --range pc --input-range pc and ctrl + shift + alt + I works as well, of course.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.