blubb444
2nd August 2012, 23:26
I've been googling around quite a bit now but I couldn't find a satisfactory answer yet, so to my question: I have an image sequence from my camera which I want to read and process with Avisynth. Is there a way to import JPEGs that are encoded in 4:2:2 colourspace (according to MediaInfo) directly into Avisynth with that colourspace (without prior conversion to RGB?) ImageSource says it only accepts RGB24, RGB32 and Y8. Are there other import plugins that could do the job?
Also, can I find out somehow which 4:2:2 they are encoded in (I don't care about byte ordering but where the chroma pixels refer to compared to the luma pixels, there are apparently several possibilities, considering one row (columns don't matter in 4:2:2): If luma is on 0, 1, 2, 3, 4, 5, 6... then chroma could be on a) 0, 2, 4... b) 0.5, 2.5, 4.5,.... or c) 1, 3, 5,...)? Or is there are standard when it comes to JPGs?
I also thought about losslessly stroing the JPGs as an MJPEG-AVI and importing that afterwards, there's a tool for that on sourceforge but it seems to be for Linux. Also I saw that it's apparently possible with mencoder but to be honest I'm too stupid to actually download/install mencoder as a CLI, all I find is always mplayer. Is there a similar possibility in ffmpeg?
EDIT: I found a very crude workaround: When I load the images with FFImageSource, they're correctly decoded to 4:2:2. The remaining problem is that I can only load a small number (~100) images like that per script before hitting the 2GB RAM limit, so I have to split, encode to multiple files (only 2 at the moment, I have 180 1920x1080 images to process but there could be more or bigger images in the future) and join them with mkvmerge (therefore useless I-frames are written)
But at that point another question arises: I don't know how to tell x264 to use the JPEG matrix for the YUV->RGB conversion.
With some eye tests I found the best similarity (visually no difference) if I use ConvertToRGB("PC.601"), preview in VirtualDub, export as BMP and compare to the original JPG (both opened in IrfanView, I'm switching back and forth via the Windows application icon), but since I don't want to do any conversion before encoding I'd like to somehow write that matrix info to the h.264 stream. I can tell x264 to use PC range but in the list over here: http://mewiki.project357.com/wiki/X264_Settings#colorprim BT.601 doesn't show up, so I'm not specifying it at the moment. If I play the file with MPC-HC (LAV+madVR) it naturally assumes BT.709 (because it's HD) so the colours are slightly off.
So if it's somehow possible to write the info ("use BT.601 when decoding") to the encoded file, where should it go? To "colorprim", "transfer" or "colormatrix"? I don't really understand the difference between those three to be honest.
EDIT2: Finally found a mencoder CLI, now it's really easy and a matter of seconds to make an MJPEG out of the single JPEGs, still I can't get this to work together with AviSynth (AviSource says it doesn't read MJPEG, DirectShowSource decodes to RGB, if I force pixel_type to YUV2 it goes on strike too (says it wants to have, among others, "RGB", "YV12", or "YUV2"(!)) and FFVideoSource says file is "un-indexable"), direct encoding with x264 and watching with MPC-HC (colourspace is correct) works though, so if I want to do processing without going over RGB then I guess I'll have to encode it to a lossless file first. And apparently, BT.601 is called bt470bg by x264, still don't know whether to put it under colormatrix or colorprim, I put it on both and it seems to look legit.
Also, can I find out somehow which 4:2:2 they are encoded in (I don't care about byte ordering but where the chroma pixels refer to compared to the luma pixels, there are apparently several possibilities, considering one row (columns don't matter in 4:2:2): If luma is on 0, 1, 2, 3, 4, 5, 6... then chroma could be on a) 0, 2, 4... b) 0.5, 2.5, 4.5,.... or c) 1, 3, 5,...)? Or is there are standard when it comes to JPGs?
I also thought about losslessly stroing the JPGs as an MJPEG-AVI and importing that afterwards, there's a tool for that on sourceforge but it seems to be for Linux. Also I saw that it's apparently possible with mencoder but to be honest I'm too stupid to actually download/install mencoder as a CLI, all I find is always mplayer. Is there a similar possibility in ffmpeg?
EDIT: I found a very crude workaround: When I load the images with FFImageSource, they're correctly decoded to 4:2:2. The remaining problem is that I can only load a small number (~100) images like that per script before hitting the 2GB RAM limit, so I have to split, encode to multiple files (only 2 at the moment, I have 180 1920x1080 images to process but there could be more or bigger images in the future) and join them with mkvmerge (therefore useless I-frames are written)
But at that point another question arises: I don't know how to tell x264 to use the JPEG matrix for the YUV->RGB conversion.
With some eye tests I found the best similarity (visually no difference) if I use ConvertToRGB("PC.601"), preview in VirtualDub, export as BMP and compare to the original JPG (both opened in IrfanView, I'm switching back and forth via the Windows application icon), but since I don't want to do any conversion before encoding I'd like to somehow write that matrix info to the h.264 stream. I can tell x264 to use PC range but in the list over here: http://mewiki.project357.com/wiki/X264_Settings#colorprim BT.601 doesn't show up, so I'm not specifying it at the moment. If I play the file with MPC-HC (LAV+madVR) it naturally assumes BT.709 (because it's HD) so the colours are slightly off.
So if it's somehow possible to write the info ("use BT.601 when decoding") to the encoded file, where should it go? To "colorprim", "transfer" or "colormatrix"? I don't really understand the difference between those three to be honest.
EDIT2: Finally found a mencoder CLI, now it's really easy and a matter of seconds to make an MJPEG out of the single JPEGs, still I can't get this to work together with AviSynth (AviSource says it doesn't read MJPEG, DirectShowSource decodes to RGB, if I force pixel_type to YUV2 it goes on strike too (says it wants to have, among others, "RGB", "YV12", or "YUV2"(!)) and FFVideoSource says file is "un-indexable"), direct encoding with x264 and watching with MPC-HC (colourspace is correct) works though, so if I want to do processing without going over RGB then I guess I'll have to encode it to a lossless file first. And apparently, BT.601 is called bt470bg by x264, still don't know whether to put it under colormatrix or colorprim, I put it on both and it seems to look legit.