Log in

View Full Version : Problem reading SGI files using ScriptClip and Sashimi


Aegwyn11
15th April 2014, 16:43
Hi all, I'm trying to use ScriptClip to read a series of SGI files directly into AVISynth and having some issues.

SGI files have the image information stored as "channels" after a 512 byte file header. This is a little different than normal, as instead of having the R, then G, then B value for each pixel, you have the whole frame for R, then the whole frame for G, then the whole frame for B. In this example, the SGI files are 3840x2160 with 16bpc, so the offsets are R=512, B=16589312, and G=33178112.

Reading each "channel" in is simple enough (three instances of ScriptClip/Sashimi, with the increasing filehead offsets for the G and B channels). I can then use MergeRGB to get a regular RGB video.

These SGI files can be downloaded from:ftp://vqeg.its.bldrdoc.gov/HDTV/SVT_MultiFormat/2160p50_CgrLevels_Master_SVTdec05_/1_CrowdRun_2160p50_CgrLevels_MASTER_SVTdec05_

My problem is that this only works on the first frame. For each frame after that, the channels converge on the B channel for some reason. If I start with just the line to read in the R channel:
BlankClip(491, 3840, 2160, pixel_type="YV12").KillAudio()
ScriptClip("""RawReader(String(current_frame, "C:\Holding\1_CrowdRun_2160p50_CgrLevels_MASTER_SVTdec05_\CrowdRun_%05.0f.sgi"),
\ "Y8", 3840, 2160, packing="16:0:8", filehead=512)""")
The first frame is correct, then the second frame seems to read the G channel of the second frame, the third frame seems to read the B channel of the third frame, and all the remaining frames read the B channels. If you change the script to read in the G channel (changing filehead), the first frame will show the G channel, second will show the B channel, and B from there on. If you change the script to read in the B channel, it always shows the B channel.

I can easily skip this by using FFmpeg to concatenate the SGI file sequence into a raw RGB48 file, but I'm trying to save that step (for long sequences, the RGB48 files obviously get HUGE).

Does anyone have any clue why my issue is happening? Thanks in advance.

Gavino
15th April 2014, 19:31
BlankClip(491, 3840, 2160, pixel_type="YV12").KillAudio()
ScriptClip("""RawReader(String(current_frame, "C:\Holding\1_CrowdRun_2160p50_CgrLevels_MASTER_SVTdec05_\CrowdRun_%05.0f.sgi"),
\ "Y8", 3840, 2160, packing="16:0:8", filehead=512)""")
Shouldn't it be pixel_type="Y8", to match what RawReader is returning?

poisondeathray
15th April 2014, 19:41
sorry - semi thread hijack :D :

Is it possible to make a helper function or some workaround technique to get ffms2 (either FFVideoSource() or FFImageSource() ) to read image sequences ? ffms2 can read sgi individually and many other image formats

Aegwyn11
15th April 2014, 21:22
Shouldn't it be pixel_type="Y8", to match what RawReader is returning?

RawReader returns YV12 when you use it in Y8 or Grey mode.

Aegwyn11
15th April 2014, 21:24
sorry - semi thread hijack :D :

Is it possible to make a helper function or some workaround technique to get ffms2 (either FFVideoSource() or FFImageSource() ) to read image sequences ? ffms2 can read sgi individually and many other image formats

Hmm possibly, good idea. ScriptClip should be able to. I'll tinker a bit later...

Gavino
15th April 2014, 22:51
RawReader returns YV12 when you use it in Y8 or Grey mode.
Ah, OK then.

Here's another idea.
The symptoms suggest RawReader is returning a clip with up to 3 frames (one for each of R, G, B), depending on whether you use the offset for R, G or B (3 frames in the case of R, 2 frames for G and 1 for B). Try changing the code to this:
ScriptClip("""RawReader(... [as before] ...).Trim(0,-1)""")

foxyshadis
16th April 2014, 02:33
Why not RawReadPlanar? The last version of Sashimi has PlanarConversions.avsi to work with that.

Aegwyn11
16th April 2014, 15:56
Why not RawReadPlanar? The last version of Sashimi has PlanarConversions.avsi to work with that.

Because I'm a moron :) Thanks...functional code below for reading in as Stack16.

One note that I'm clear on...for some reason RawReadPlanar returns RGB32 when according to PlanarConversions.avsi it should return RGB24 for RGB (it should only return RGB32 for ARGB). That's why I had to use RGB32 for BlankClip.

BTW, Gavino, you were right as well...your idea worked perfectly too, but using RawReadPlanar obviously cleans the script up quite a bit.

#Create a blank clip with the right number of frames (must not exceed!!)
BlankClip(491, 3840, 2160, pixel_type="RGB32").KillAudio()

#Read individual 16-bit SGI files into AVISynth as RGBA Stack16
MSB = ScriptClip("""RawReadPlanar(String(current_frame, "C:\Holding\CrowdRun_%05.0f.sgi"),
\ "RGB", 3840, 2160, packing="16:0:8", filehead=512).FlipVertical()""")
LSB = ScriptClip("""RawReadPlanar(String(current_frame, "C:\Holding\CrowdRun_%05.0f.sgi"),
\ "RGB", 3840, 2160, packing="16:8:8", filehead=512).FlipVertical()""")

StackVertical(MSB, LSB)

Aegwyn11
16th April 2014, 16:08
sorry - semi thread hijack :D :

Is it possible to make a helper function or some workaround technique to get ffms2 (either FFVideoSource() or FFImageSource() ) to read image sequences ? ffms2 can read sgi individually and many other image formats

BTW, this works too, but not as flexibly as using Sashimi. It reads 8 bits in fine, or even 10 bits using SAPikachu's hacked version (using enable10bithack=true), but SGI files are either 8 or 16 bit (in this case 16), so in both cases you lose color information.

Very simple code for reading in 8 bit files using ffms2:
BlankClip(491, 3840, 2160, pixel_type="RGB32").KillAudio()
ScriptClip("""FFVideoSource(String(current_frame, "C:\Holding\CrowdRun_%05.0f.sgi"))""")

Aegwyn11
16th April 2014, 19:40
One more note about using ffms2 that I just noticed...each SGI file ends up getting its own ffindex file. Not super ideal.