RawSource

Loading raw video data from files

for AviSynth 2.5x

RawSource (string "file", int "widht", int "height", string "pixel_type", string "index", bool "show")

RawSource opens a video file which contains YUV2, YV16, YV12, RGB or Y8 video data.
There are three ways how the positions of the video frame data are calculated:

Supported pixel_types are:
  RGB, RGBA, BGR, BGRA (interleaved RGB without subsampling, resulting in AviSynth's RGB24 or RGB32)
  YUYV, YVYU, UYVY, VYUY (interleaved horizontally subsampled resulting in AviSynth's YUV2)
  YV16 (planar horizontally subsampled, it is converted to AviSynth's YUV2)
  I420, YV12 (planar horizontally and vertically subsampled resulting in AviSynth's YV12)
  Y8 (luma only resulting in AviSynth's YV12 grey, waiting for Avisynth 2.6 with native Y8 support)

Maximal width is 2880.
The framerate is fixed to 25fps, you can change it with AssumeFPS, if you need (e.g. for NTSC-material).

With show=true the actually used byteposition for that frame is displayed, followed by:
 K = position given in index is used
 D = position by adding current delta is used
 B = position by adding currend big_delta is used

Some simple examples:

RawSource("d:\yuv4mpeg.yuv")  #this assumes there is a valid YUV4MPEG2-header inside.
                              #If not, default values are used: width=720, height=576, pixel_type="YUV2"

RawSource("d:\src6_625.raw",720,576,"BGRA") # really a raw file
# if you are unsure about the pixel_type, simply try out all possible values.

Using an index-string:

You can enter the byte positions of the video frames directly.

RawSource("d:\yuv.mov",720,576,"UYVY", index="0:192512 1:1021952 25:21120512 50:42048512 75:62976512")

This is useful if it's not really raw video, but e.g. uncompressed MOV files or a file with some kind of header.
It will work whenever the spacing of the frames is fixed or has at least two fixed intervalls (e.g. audio data interleaved with the video every 25th frame).
You enter pairs of framenumber:byteposition.
Internally there are two step values (for the byte positions): delta and big_delta.
delta is stored everytime when two adjacent framenumbers are given, the default value is width*height*bytes_per_pixel.
big_delta is stored, when three framenumbers with the same two intervals are given. The default value is 0 (meaning there is no useful big_delta present)..
If those conditions are not met, the internal values of delta and big_delta is not updated, only the given bytepositions in the index are used.
big_delta is reset to 0 if the resulting position would be behind the given one (see beyond).

Here are some possible cases:

  0:    0
frame 0 starts at byte 0, step to frame 1 is default = width*height*bytes_per_pixel
  0:10000
frame 0 starts at 10000
  0: 5000
  1:15000
frame 0 at 5000
frame 1 at 15000 (delta is set to 10000)
frame 2 at 25000 (using delta)
frame 3 at 35000 (using delta)
  0:  5000
  1: 15000



25:290000 50:590000 75:890000
frame 0 at 5000
frame 1 at 15000 (delta=10000)
frame 2 at 25000
...
frame 25 at 290000 (using entry instead of delta which would be at 255000)
frame 26 at 300000 (still using delta)
...
frame 50 at 590000 (using entry instead of delta)
>> because 25...50 = 50...75 now big_delta is set to 300000 (590000-290000)
frame 51 at 600000 (still using delta)
...
frame 75 at 890000 (using entry which is the same as using big_delta)
... 
frame 100 at 1190000 (using big_delta)
frame 101 at 1200000 (using delta)
...
frame 125 at 1490000 (using big_delta)
  0:  5000
  1: 15000
 25:290000
 50:590000
 75:890000
100:950000
the same as in the previous example



frame 75 at 890000
>> because 890000+300000 > 950000 now big_delta is reset to 0.
frame 100 at 950000
frame 101 at 960000 (using delta)
...
frame 125 at 1200000 (there is NO big_delta)

The index string is treated as a filename, if there is an "." inside. The data is then read from that file, line breaks don't matter.

Finding those byte positions:

With yuvscan.exe you can try to analyze files which contain YUV-data with only valid luma and chroma data (~16-240).
The program searches for big uninterrupted blocks without bytes < 16 or >240 and generates a "index.txt"-file, which can be used directly with rawsource (if you are really lucky, at least).
It's only a command line version, you can change the default parameters. If you know the height and width of the data, the output will be much better.

Usage:
yuvscan.exe filename triggerlength threshold round_by_bytes

triggerlength: how long must one frame be (in bytes)
threshold: what are considered valid YUV data (default 10, which means 10 ... 255-10)
round_by_bytes: as most data is stored at nice positions, the output can be rounded. default 9 which means 2^9 = $100

 

Ernst Peché, 2005-10-13

Version 2006-07-28 - Added Y8 support (by Fizick, http://avisynth.org.ru)