RawSource26

From Avisynth wiki
Jump to: navigation, search
Abstract
Author Chikuzen
Version 20160528
Download github.com
Category Source filters
License GPLv2?
Discussion Doom9 Thread

Contents

Description

Source filter plugin for loading raw video data from files. RawSource26 is an AviSynth 2.6 rewrite of RawSource by Ernst Pech .

Requirements


Syntax and Parameters

RawSource26 opens a video file which contains 8bit YUV444, YUV422, YUV411, YUV420, Y8, or RGB video data. There are three ways how the positions of the video frame data are calculated:

  • a YUV4MPEG2-header is found, width/height/framerate/pixeltype/fieldorder is set according to the header data. Only fixed-length FRAME headers without 'm'tag are supported.
  • width, height and pixel_type is given as arguments. Then the positions are calculated assuming that only video data is in the file.
  • an "index" string (or file) is given together with width, height, pixel_type. The index string can contain all or partial positions of the frames.


RawSource (string "file", int "width", int "height", string "pixel_type", int "fpsnum", int "fpsden", string "index", bool "show")


string  file =
Path to raw file; path can be omitted if the file is in the same folder as the AviSynth script (*.avs).


int  width = 720
int  height = 576
Dimensions of the raw file; Maximal width/height is 65536.


string  pixel_type = "YUY2"
Supported pixel_types are:
pixel_type AviSynth colorspace
"BGR", "BGR24", "RGB", "RGB24" RGB24
"BGR32", "RGBA", "RGB32", "ARGB", "ABGR" RGB32
"YUY2", "YUYV", "UYVY", "VYUY" YUY2
"YV24", "I444" YV24
"YV16", "I422" YV16
"YV411", "Y41B", "I411" YV411
"I420", "IYUV", "YV12" YV12
"NV12", "NV21" I420
"Y8", "GRAY" Y8


int  fpsnum = 25
int  fpsden = 1
The default value of framerate is 25fps, you can change it with specified 'fpsnum' and 'fpsden' if you need (e.g. for NTSC-material).


string  index = ""
See using an index-string.


bool  show = false
With show=true the actual byte position used 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 current big_delta is used


Examples

The following example assumes there is a valid YUV4MPEG2-header inside. If not, default values are used: width=720, height=576, pixel_type="YUY2"

RawSource("d:\yuv4mpeg.y4m")


Decoding a 2VUY file. First download Test.rar, it contains a color bar video in NTSC format (720x486, 29.976fps, 120 frames).
If you open the Test.2VUY file in a hex editor you can see that it has a 1024 byte header. Also, each field is stored separately (720x243). So to correctly load this file we must do something like this:

RawSource(file="Test.2VUY", width=720, height=243, pixel_type="UYVY", fpsnum=30000, fpsden=1001, index="0:1024")
AssumeFieldBased()
Weave()


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 byte positions 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.

* yuvscan.exe is included with RawSource_25_dll, hosted on the WarpEnterprises page of this site.

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


Changelog

  Version       Date            Changes
RawSource26 20160528 2016/05/28 - Add 64bit binary. 20130826 2013/08/26 - Compile for AviSynth 2.6 (Alpha 4 or greater). 20120831 2012/08/31 - Extend the size of read buffer to one frame at the maximum, and modify writing algorithm. 20110925 2011/09/25 - Change MAX_WIDTH to 65536. 20110614 2011/06/14 - Initial release (rewrite RawSource to support new features(pixel types) in AviSynth 2.6.
RawSource25 20110529 2011/05/29 - Change maximal width to 4096. - Add new parameters fpsnum/fpsden. 20110523 2011/05/23 - Add ABGR/NV12/NV21 support. - Fix parsing of YUV4MPEG2 stream header. - Fix processing of interlaced YUV4MPEG2. - Add support of ARGB / I422(YUV422planar) / YV411(YVU411planar) / YUV411planar. 20110112 2011/01/12 - added mono(Y8) colorspace suport on YUV4MPEG2.


Archived Downloads

Version Download Mirror
20130826 rawsource26-20130826.zip rawsource26-20130826.zip
20110529 RawSource_25_dll_20110529.zip RawSource_25_dll_20110529.zip


External Links

  • GitHub - RawSource_2.6x source code repository.
  • GitHub - RawSource_2.5x source code repository.
  • Doom9 Forum - Uncompressed UYVY AVI fails to load in AviSynth




Back to External Filters

Personal tools