Log in

View Full Version : Using AVISynth to Process RGB48 SGI files


Aegwyn11
14th April 2013, 01:32
Hi all, I have some sources that came as SGI images stored as RGB48, so I created a script to convert them to something usable, while trying to keep as much of the master's fidelity as possible. Hopefully this is useful to someone :)

This is done using FFmpeg, Sashimi (http://forum.doom9.org/showthread.php?p=1403600#post1403600), Dither (http://forum.doom9.org/showthread.php?p=1386559), and avs2yuv (http://komisar.gin.by/tools/avs2yuv/avs2yuv-0.24bm2.zip).

#Use FFmpeg to build raw RGB file from individual SGI images
#ffmpeg -f image2 -i "input (%d).sgi" -c:v rawvideo input.rgb

#Build RGB Stack16
MSB = RawReader("source.rgb", "RGB", 3840, 2160, packing="16:0:8")
LSB = RawReader("source.rgb", "RGB", 3840, 2160, packing="16:8:8")
StackVertical(MSB, LSB)


#Crop 16:9 input for 4:3 Presentation
#FWid = Int(Float(Height/2)*Float(4)/3)
#Crop((Width-Fwid)/2,0,FWid,Height)


#Letterbox 16:9 input for 4:3 presentation
#BarHei = Int(((Float(Width/4)*3)-Float(Height/2))/2)
#Dither_addborders16(0,BarHei,0,BarHei)


#Convert RGB Stack16 to YUV Stack16
#4:2:0 Chroma
#Red = ShowRed("YV12")
#Green = ShowGreen("YV12")
#Blue = ShowBlue("YV12")
#Dither_convert_rgb_to_yuv(Red, Green, Blue, matrix="709", output="YV12")

#4:2:2 Chroma
Red = ShowRed("YUY2").ConvertToYV16()
Green = ShowGreen("YUY2").ConvertToYV16()
Blue = ShowBlue("YUY2").ConvertToYV16()
Dither_convert_rgb_to_yuv(Red, Green, Blue, matrix="709", output="YV16")


#Resize
Dither_resize16(1920, 1080, kernel="spline36")


#Interlace if needed
#AssumeTFF()
#SeparateFields()
#SelectEvery(4,0,3)
#Weave()


#Prepare for 8 bit output
#DitherPost()


#Prepare for 10 bit output (flags will be wrong, so must be piped or saved as raw YUV before using)
Dither_quantize(10,reducerange=true)
Dither_out()

#Command to save YUV (select correct chroma):
#avs2yuv -raw -csp I42X output.avs -o output.yuv

#Example piping command (select correct chroma on avs2yuv and select correct chroma/size on FFmpeg):
#avs2yuv -raw -csp I42X output.avs - | ffmpeg -y -f rawvideo -pix_fmt yuv42Xp10le -s widthxheight -i - output.yuv