Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. Domains: forum.doom9.org / forum.doom9.net / forum.doom9.se |
|
|
#1 | Link |
|
Registered User
Join Date: Feb 2009
Posts: 16
|
XYZ to RGB colorspace conversion
So, i've got DCP-file in MXF-conteiner, and i need to re-encode video to common format (for example h.264 in matroska).
As you know, in MXF there are lots of JPEG2000-compressed frames with images sampled by 12 bits per channel, and the channels are X, Y and Z (CIE 1931 color space). FFmpeg can demux MXF container and decode JPEG200 (through libopenjpeg), but it can not convert colorspace from XYZ to RGB (see discussion), so i only can get picture with ugly colors. I thought that it would be nice to build pipeline with ffmpeg and some colorspace converter, for example: Code:
ffmpeg -i input.mxf -pix_fmt rgb48le -f rawvideo pipe:1 | xyztorgb | \ ffmpeg -i pipe:0 -blah-blah-blah output.mkv I also tried to extract one frame from my MXF-file and applied color transform matrix with imagemagick: Code:
ffmpeg -i input.mxf -pix_fmt rgb48le -f rawvideo -frames 1 temp.rgb && \
convert -depth 16 -size 2048x858 \
-color-matrix "3.240479 -1.537150 -0.498535 \
-0.969256 1.875992 0.041556 \
0.055648 -0.204043 1.057311" \
temp.rgb \
-depth 8 temp.png
The main task is to write some converter. I wrote this code (see attachment), but it is not able to do colorspace conversion right. Any ideas, gentlemen? |
|
|
|
|
|
#2 | Link |
|
Registered User
Join Date: Feb 2009
Posts: 16
|
Ok, gentlemen!
I was confused since ffmpeg told me that output colorspace was rgb48le, so i used little endian order for double-byte encoded components: Code:
X = (six[0] * 256 + six[1]) / 65535.0; Y = (six[2] * 256 + six[3]) / 65535.0; Z = (six[4] * 256 + six[5]) / 65535.0; Code:
X = (six[1] * 256 + six[0]) / 65535.0; Y = (six[3] * 256 + six[2]) / 65535.0; Z = (six[5] * 256 + six[4]) / 65535.0; |
|
|
|
|
|
#3 | Link |
|
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,406
|
With little endian, first byte would be the the least significant byte, for big endian, it is the
most significant byte, so your second code snip is correct for little endian, eg i86. I would though prefer to read it formatted as below Code:
X = (six[0] + six[1] * 256) / 65535.0; Y = (six[2] + six[3] * 256) / 65535.0; Z = (six[4] + six[5] * 256) / 65535.0;
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 12th June 2012 at 16:11. |
|
|
|
|
|
#4 | Link |
|
Registered User
Join Date: Feb 2009
Posts: 16
|
Thank you, StainlessS!
To test my code i downloaded this trailer. This command works well for me: Code:
ffmpeg -i trec.mxf \
-f rawvideo -pix_fmt rgb48le pipe:1 | ./xyztorgb | \
ffmpeg -r 24 -s 2048x858 -f rawvideo -pix_fmt rgb24 -i pipe:0 \
-pix_fmt yuv420p -f yuv4mpegpipe pipe:1 | \
x264 --profile high --level 4.1 --ref 4 \
--bframes 4 --b-adapt 2 --b-pyramid normal \
--deblock -1:-1 \
--crf 20 --rc-lookahead 60 --ratetol 10.0 \
--aq-mode 2 \
--8x8dct \
--partitions all --direct auto --weightp 2 --me umh --subme 10 \
--psy-rd 1.0:0.15 --trellis 2 \
--no-fast-pskip --no-dct-decimate \
--output trec.mkv \
--demuxer y4m --threads 4 -
|
|
|
|
|
|
#5 | Link |
|
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,406
|
Code:
if (inputcsp = 2) I would try using float rather than double, the extra precision of double is probably superflous. If source for i86 only then handle differently as native little endian, ie use unsigned short[3] rather than unsigned char[6], otherwise, might be better (depending on compiler) to use shift by 8 rather rather than multiply by 256. Also could try to input and output multiple samples at once rather than one at a time. {with more buffer space, (eg six[256][6 or 3 depending type], and Three[256][3])} and deal with the number of samples all at once before writing to output. (obviously have to use value returned from fread function) Could pre-calculate scaled to 1 (full range) X-Y-Z-values in 65536 array of double/float. Lots of room to speed up, good luck.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 12th June 2012 at 22:56. |
|
|
|
|
|
#6 | Link |
|
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,442
|
Not only that, it should be
if (outputcsp == 2) and similarly use == in the earlier line if (inputcsp = 1) Using '=' instead of '==' means the conditions will always evaluate to 'true' (non-zero). However, as the program stands, inputsp and outputcsp are always 1 and 2 respectively, so in practice it makes no difference to the result. |
|
|
|
|
|
#7 | Link |
|
47.952fps@71.928Hz
Join Date: Mar 2011
Posts: 940
|
Are there any full packages/guides that are updated to help convert DCP/MXF trailers to h264/mkv?
I'm on Windows 7, 64bit. It's not easy trying to read through all the threads. A lot of information is jumbled around and there's no single post with updated information. It's all fragmented so I have no idea what to do. I've got several mxf/dcp trailers (2D and 3D) and would like to convert them to h264/mkv. I've googled and found a lot of tools but a lot of them have very little documentation or very little coherent support threads/forums. There also seems to be a lot of source codes you need to compile yourself (of which I have no experience) with patches and updates. I've already got OpenDCP and OpenJPEG 2.0 installed. I've also got in my arsenal: MXFSource AVISynth Plugin 0.1, Open Cinema Tools Release 1.1.2, OpenJPEG library and codecs. I have Zeranoe FFmpeg builds and x264 from x264.nl. I read somewhere that a custom ffmpeg will need to be compiled from source?
__________________
Win10 (x64) build 19041 NVIDIA GeForce GTX 1060 3GB (GP106) 3071MB/GDDR5 | (r435_95-4) NTSC | DVD: R1 | BD: A AMD Ryzen 5 2600 @3.4GHz (6c/12th, I'm on AVX2 now!)
|
|
|
|
|
|
#12 | Link | ||
|
47.952fps@71.928Hz
Join Date: Mar 2011
Posts: 940
|
Untested and Mirrored
Quote:
Quote:
Rio 3D Put your 3D glasses.rar I'm okay with batch scripts. A GUI would come in handy for single projects. Mind you, I'm still doing just simple batch scripts without all the other functions or brackets. Babysteps.
__________________
Win10 (x64) build 19041 NVIDIA GeForce GTX 1060 3GB (GP106) 3071MB/GDDR5 | (r435_95-4) NTSC | DVD: R1 | BD: A AMD Ryzen 5 2600 @3.4GHz (6c/12th, I'm on AVX2 now!)
|
||
|
|
|
|
|
#14 | Link | |
|
47.952fps@71.928Hz
Join Date: Mar 2011
Posts: 940
|
I've changed the "inputcsp = 2" and added the double equal signs as suggested in the original ".c" anway.
I've tried the batch script from post #4 (with putting the "xyztorgb.c" into the ffmpeg ((2013-02-16) git-b9c5448 static 32bit build) folder and the folder with the mxf files as well)) but I keep getting frame rate errors. The Rio 3D glasses has a frame rate of 48 and I get "Timecode frame rate X/1 not supported" and the batch closes. It's an even 48.000 fps. I then just copied the batch script and ran it in CMD and got this tidbit before it spat out more errors... Quote:
I'm not having any luck googling anything about ffmpeg and 48fps. I don't know what I'm doing wrong.
__________________
Win10 (x64) build 19041 NVIDIA GeForce GTX 1060 3GB (GP106) 3071MB/GDDR5 | (r435_95-4) NTSC | DVD: R1 | BD: A AMD Ryzen 5 2600 @3.4GHz (6c/12th, I'm on AVX2 now!)
|
|
|
|
|
|
|
#15 | Link | |
|
Registered User
Join Date: Dec 2002
Posts: 5,565
|
Quote:
ffmpeg -i "3D Glasses.mxf" -i "3D Glasses_audio.mxf" -vf scale=1920:-1 -sws_flags bicubic -pix_fmt yuv420p -vcodec libx264 -preset medium -crf 18 -acodec ac3 -ab 384k output.mkv I'm not sure if I got the scaling correctly (to 1920 width and 4:2:0 for consumer players). You could of course pipe to raw video and audio and do other conversions yourself. |
|
|
|
|
|
|
#16 | Link | |
|
47.952fps@71.928Hz
Join Date: Mar 2011
Posts: 940
|
Quote:
The MKV has MediaInfo data and does show up as 24fps. However, the file size is only 622 bytes with no actual data. There's no video, no audio; just a blank screen. I still get the 48/1 fps error. Code:
[mxf @ 00000000021d9520] Timecode frame rate 48/1 not supported
__________________
Win10 (x64) build 19041 NVIDIA GeForce GTX 1060 3GB (GP106) 3071MB/GDDR5 | (r435_95-4) NTSC | DVD: R1 | BD: A AMD Ryzen 5 2600 @3.4GHz (6c/12th, I'm on AVX2 now!)
|
|
|
|
|
![]() |
| Tags |
| xyz rgb convert ffmpeg |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|