AviSource

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(Undo revision 5753 by Raffriff42 (talk))
(formatting, links, phrasing)
Line 1: Line 1:
{{Template:Func4Def|AviSource(string filename [, ... ], [bool audio = true], [string pixel_type = "FULL"], [string fourCC], [int vtrack = 0], [int atrack = 0])|OpenDMLSource(string filename [, ... ], [bool audio = true], [string pixel_type = "FULL"], [string fourCC], [int vtrack = 0], [int atrack = 0])|AviFileSource(string filename [, ... ], [bool audio = true], [string pixel_type = "FULL"], [string fourCC], [int vtrack = 0], [int atrack = 0])|WavSource(string filename [, ... ])}}
+
'''AviSource''' takes one or more file names and returns a clip with all files joined end to end. Note the file formats must be compatible - see [[#Joining_Clips|''Joining Clips'']] below.
  
'''AviSource''' takes as argument one or more file name in quotes, and reads in the file(s) using either the Video-for-Windows "[[AVI|AVIFile]]" interface, or AviSynth's built-in OpenDML code (taken from [[VirtualDub]]). This filter can read any file for which there's an [[AVI|AVIFile]] handler. This includes not only [[AVI]] files but also [[WAV]] files, [[AVS]] (AviSynth script) files, and VDR ([[VirtualDub]] [[frameserver]]) files. If you give multiple filenames as arguments, the clips will be spliced together with [[Splice|UnalignedSplice]].
+
<div {{NotaBeneWidthIndent|56|2|none}} >
 +
'''AviSource''' tries to read the file(s) using Avisynth's built-in [http://www.jmcgowan.com/avitech.html#OpenDML ''OpenDML''] interface (derived from [[VirtualDub]] code) where possible; if the file(s) are not in OpenDML format, it uses the Video for Windows [http://www.jmcgowan.com/avitech.html#VFW ''AVIFile''] interface.  
  
The AviSource filter examines the file to determine its type and passes it to either the AVIFile handler or the [[OpenDML]] handler as appropriate. In case you have trouble with one or the other handler, you can also use the '''OpenDMLSource''' and '''AviFileSource''' filters, which force the use of one or the other handler. Either handler can read ordinary (< 2GB) AVI files, but only the OpenDML handler can read larger [[AVI]] files, and only the AVIFile handler can read other file types like [[WAV]], VDR and AVS. There is built-in support for ACM (Audio Compression Manager) audio (e.g. mp3-AVIs).
+
If you have trouble with one or the other interface, '''OpenDMLSource''' and '''AviFileSource''' will force the use of ''OpenDML'' or ''AVIFile'', respectively. Only ''OpenDML'' can read [[AVI]] files larger than 2 GB, but ''AVIFile'' is more versatile: it can read any file (under 2 GB) for which there exist appropriate ''stream handlers'', including not only [[AVI]] but also [[WAV]], AviSynth scripts, ([[AVS]]), and VirtualDub [[frameserver]] files (VDR). There is built-in support for decoding  with [http://en.wikipedia.org/wiki/Windows_legacy_audio_components#Audio_Compression_Manager ''Audio Compression Manager''] (MP3, AAC, AC3, etc).
 +
</div>
  
'''WavSource''' can be used to open a WAV file, or the audio stream from an AVI file. This can be used, for example, if your video stream is damaged or its compression method is not supported on your system.
+
'''WavSource''' will open a WAV file, or the audio stream from an AVI file. This can be used, for example, if your video stream is damaged or its compression method is not supported on your system.
  
===== Parameters =====
+
== Syntax and Parameters ==
 +
{{Template:Func3Def
 +
|AviSource(string ''filename'' [, ...] [, bool "''audio''", string "''pixel_type''", string "''fourCC''", int "''vtrack''", int "''atrack''"])
 +
|AviFileSource(string ''filename'' [, ...] [, bool "''audio''", string "''pixel_type''", string "''fourCC''", int "''vtrack''", int "''atrack''"])
 +
|OpenDMLSource(string ''filename'' [, ...] [, bool "''audio''", string "''pixel_type''", string "''fourCC''", int "''vtrack''", int "''atrack''"])
 +
}}
  
All parameters are optional.
+
{{Template:FuncDef
:;audio (default true)
+
|WavSource(string ''filename'' [, ...])
::When set to true it will load the audio stream (as specified by the atrack parameter) if present. When set to false, it will not load any audio streams.
+
}}
  
:;pixel_type
+
:{{Par2|filename|string|}}
::Chooses the output color format of the decompressor. Valid values are "[[YV24]]", "[[YV16]]", "[[YV12]]", "[[YV411]]", "[[YUY2]]", "[[RGB32]]", "[[RGB24]]", "[[Y8]]", "AUTO" and "FULL" (default value).  
+
::One or more file names. The files will be joined into a single clip with [[Splice|UnalignedSplice]]. Note the file formats must be compatible - see [[#Joining_Clips|''Joining Clips'']] below.
  
::If omitted or set to "FULL", AviSynth will use the first format supported by the decompressor (in the following order: [[YV24]], [[YV16]], [[YV12]], [[YV411]], [[YUY2]], [[RGB32]], [[RGB24]] and [[Y8]]). If set to "AUTO", AviSynth will use the old ordering: [[YV12]], [[YUY2]], [[RGB32]], [[RGB24]] and [[Y8]].
+
:{{Par2|audio|bool|true}}
 +
::If true, load the first audio stream, or the stream specified by {{FuncArg|atrack}} if present. If false, audio is disabled.
  
::To put it in different words: if you don't specify something it will try to output the AVI as [[YV24]], if that isn't possible it tries [[YV16]] and if that isn't possible it tries [[YV12]], etc ...
+
:{{Par2|pixel_type|string|"FULL"}}
 +
::Chooses the output color format of the decompressor. Valid values are listed in the table below. This argument has no effect if the video is uncompressed, because no decompressor will be used in that case.  
  
::This parameter has no effect if the video is in an uncompressed format, because no decompressor will be used in that case.  
+
::*If omitted or "FULL", AviSynth will use the first format supported by the decompressor, in the order shown in the table below.
 +
::*If "AUTO", AviSynth will use the alternate (older) order as shown.
 +
:::{|class="wikitable"
 +
!align="center" colspan="9" |Valid {{FuncArg|pixel_type}} values, listed by decoding priority (high to low)
 +
|-
 +
!style="width:5em; text-align:center;"|FULL
 +
|style="width:5em; text-align:center;"|[[YV24]]
 +
|style="width:5em; text-align:center;"|[[YV16]]
 +
|style="width:5em; text-align:center;"|[[YV12]]
 +
|style="width:5em; text-align:center;"|[[YV411]]
 +
|style="width:5em; text-align:center;"|[[YUY2]]
 +
|style="width:5em; text-align:center;"|[[RGB32]]
 +
|style="width:5em; text-align:center;"|[[RGB24]]
 +
|style="width:5em; text-align:center;"|[[Y8]]
 +
|-
 +
!style="width:5em; text-align:center;"|AUTO
 +
|
 +
|
 +
|style="width:5em; text-align:center;"|[[YV12]]
 +
|
 +
|style="width:5em; text-align:center;"|[[YUY2]]
 +
|style="width:5em; text-align:center;"|[[RGB32]]
 +
|style="width:5em; text-align:center;"|[[RGB24]]
 +
|style="width:5em; text-align:center;"|[[Y8]]
 +
|}
 +
::In other words, if you don't specify anything, it will try to output [[YV24]]; if that isn't possible it tries [[YV16]], and if that isn't possible it tries [[YV12]], etc ...
  
::Adding a '+' to the start of the pixel_type for planar formats assumes the lines are padded DWORD aligned in memory instead of packed. This can correct skew or tearing of the decoded video. E.g AviSource("...", pixel_type="+YV12"). This problem shows up when the width of the picture is not divisible by 4.
+
::For [[Planar|planar]] color formats, adding a '''<tt>'+'</tt>''' prefix, ''e.g.'' <code>AviSource(..., pixel_type="'''+'''YV12")</code>, tells AviSynth the video rows are DWORD aligned in memory instead of packed. This can fix skew or tearing of the decoded video when the width of the picture is not divisible by 4.
  
:;fourCC
+
:{{Par2|fourCC|string|(auto from source)}}
::Forces use of a different codec than the default taken from the [[FourCC]] of the video stream.
+
::Forces use of a different codec than the default, taken from the [[FourCC]] of the video stream.
  
:;vtrack (default 0)
+
:{{Par2|vtrack|int|0}}
::When vtrack is specified it will load the vtrack videostream (where we start counting at zero). When the videostream is not found, an error will be returned.
+
::Specify a numbered video track. Track numbers start from zero, and are guaranteed to be continuous (i.e. there must be a track ''1'' if there is a track 0 and a track ''2''). If no video stream numbered {{FuncArg|vtrack}} exists, an error will be raised.  
  
:;atrack (default 0)
+
:{{Par2|atrack|int|0}}
::When atrack is specified it will load the atrack audiostream (where we start counting at zero). When the audiostream is not found, no audio will be loaded.
+
::Specify a numbered audio track. Track numbers start from zero, and are guaranteed to be continuous (i.e. there must be a track ''1'' if there is a track 0 and a track ''2''). If no audio stream numbered {{FuncArg|atrack}} exists, no error will be raised, and no audio will be returned.
  
===== Helpful hints =====
 
  
* There is a limit of (about 50) AviSource calls in script. See [http://forum.doom9.org/showthread.php?t=131687 discussion].
+
== Notes ==
 +
==== Joining clips ====
  
* Sometimes the colors will be distorted when loading a [[DivX]] clip in AviSynth v2.5 (the chroma channels U and V are swapped), due to a bug in DivX (5.02 and older). You can use [[Swap|SwapUV]] to correct it.
+
* There is a limit of (about 50) '''AviSource''' calls in script. See [http://forum.doom9.org/showthread.php?t=131687 discussion].
  
* From v2.53 AVISource can also open DV type 1 video input (only video, not audio).
+
* File formats must be compatible; that means:
 +
:# Both clips have the same height and width.
 +
:# Both clips have the same frame rate (''precisely'' the same, not approximately)
 +
:# Both clips have the same audio sample rate, bit depth and number of channels.
 +
:# Both clips have the same color format (as presented by the decoder)
  
* Some MJPEG/DV codecs do not give correct CCIR 601 compliant output when using AVISource. The problem could arise if the input and output color format of the codec are different. For example if the input color format is YUY2, while the output format is RGB, or vice versa. There are two ways to resolve it:
+
* See the VirtualDub blog post [http://www.virtualdub.org/blog/pivot/entry.php?id=73 Appending streams and mismatch errors] for a more in-depth explanation.
  
:1. Force the same output as the input color format. Thus for example (if the input is RGB):
+
==== Windows 7 users ====
  
::<code>AviSource("file.avi", pixel_type="RGB32")</code>
+
'''WavSource''' under Windows 7 is unable to load WAV files with 32-bit IEEE Float samples having the [http://forum.doom9.org/showthread.php?t=170444 WAVEFORMAT structure]. You can use [[ConvertAudioTo16bit]] or you can use [http://ffmpeg.zeranoe.com/builds/ ffmpeg] to rewrite the header to an extensible format (just do a stream copy, <tt>-a:copy</tt>; it always writes extensible headers).
  
:2. Correct it with the filter [[ColorYUV]]:
+
==== Helpful hints ====
  
::<code>AviSource("file.avi").ColorYUV(levels="PC->TV")</code>
+
* Sometimes the colors will be distorted when loading a [[DivX]] clip in AviSynth v2.5 (the chroma channels U and V are swapped), due to a bug in DivX (5.02 and older). You can use [[Swap|SwapUV]] to correct it.
  
===== More on codecs =====
+
* '''AVISource''' can also open DV type 1 video input (only video, not audio).
  
Some reference threads:
+
* Some MJPEG/DV codecs do not give correct CCIR 601 compliant output when using '''AVISource'''. The problem could arise if the input and output color format of the codec are different. For example if the input color format is YUY2, while the output format is RGB, or vice versa. There are two ways to resolve it:
 +
:1. Force the same output as the input color format. Thus for example (if the input is RGB):
 +
::<tt>AviSource("file.avi", pixel_type="RGB32")</tt>
 +
:2. Correct it with the filter [[ColorYUV]]:
 +
::<tt>AviSource("file.avi").ColorYUV(levels="PC->TV")</tt>
  
 +
==== More on codecs ====
 
*[http://forum.doom9.org/showthread.php?s=&postid=330657 MJPEG codecs]
 
*[http://forum.doom9.org/showthread.php?s=&postid=330657 MJPEG codecs]
 
*[http://forum.doom9.org/showthread.php?s=&threadid=58110 DV codecs]
 
*[http://forum.doom9.org/showthread.php?s=&threadid=58110 DV codecs]
  
===== Examples =====
+
 
 +
== Examples ==
  
 
  # C programmers note: backslashes are not doubled; forward slashes work too
 
  # C programmers note: backslashes are not doubled; forward slashes work too
Line 66: Line 110:
 
  WAVSource("f:/soundtrack.wav")
 
  WAVSource("f:/soundtrack.wav")
  
  # the following is the same as AVISource("cap1.avi") + AVISource("cap2.avi"):
+
  # The following statements do the same thing:
 +
# (to join clips, file formats must be compatible - see [[#Notes|''Notes'']] on this page)
 +
AviSource("cap1.avi") + AviSource("cap2.avi")
 
  AVISource("cap1.avi", "cap2.avi")
 
  AVISource("cap1.avi", "cap2.avi")
  
  # disables audio and request RGB32 decompression
+
  # Disable audio and request RGB32 decompression
  AVISource("cap.avi", false, "RGB32")
+
  AVISource("cap.avi", '''audio'''=false, "RGB32")
  
  # opens a DV using the Canopus DV Codec
+
  # Open a DV, forcing the Canopus DV Codec
  AviSource("cap.avi", false, fourCC="CDVC")
+
  AviSource("cap.avi", '''fourCC'''="CDVC")
 
   
 
   
  # opens an avi (for example DivX3) using the XviD Codec
+
  # Open a file, forcing the [[Xvid|XviD]] Codec
  AviSource("cap.avi", false, fourCC="XVID")
+
  AviSource("cap.avi", '''fourCC'''="XVID")
  
  # splicing two clips where one of them contains no audio.
+
  # Splice two clips together, where one of them contains no audio.
# when splicing the clips must be compatible (have the same video and audio properties):
+
 
  A = AviSource("FileA.avi")
 
  A = AviSource("FileA.avi")
 
  B = AviSource("FileB.avi") # No audio stream
 
  B = AviSource("FileB.avi") # No audio stream
  A ++ AudioDub(B, BlankClip(A))
+
  A ++ [[AudioDub]]B, [[BlankClip]](A)) # insert silent audio with same format
 
+
# opens YV12 where the width is not a multiple of four
+
Avisource("D:\Projects\test.avi", pixel_type="+YV12")
+
  
  # opens the second video and second audio stream of a clip
+
  # Open a YV12 video where the width is not a multiple of four
  AviSource("D:\Projects\test_multi10.avi", vtrack=1, atrack=1)
+
  Avisource("D:\Projects\test.avi", pixel_type="'''+'''YV12")
  
===== Windows7 users =====
+
# opens the first video and second audio stream of a clip
 +
AviSource("D:\Projects\test_multi10.avi", '''vtrack'''=0, '''atrack'''=1)
  
WavSource under Windows 7 is unable to load WAV files with 32-bit IEEE Float samples having the [http://forum.doom9.org/showthread.php?t=170444 WAVEFORMAT structure]. Guess they screwed something up in AVIFileSource. You can use ffmpeg to rewrite the header to an extensible format (just do a stream copy, -a:copy, it always writes extensible headers).
 
  
===== Changes =====
+
== Changes ==
 
{| border="1"
 
{| border="1"
 
|-  
 
|-  

Revision as of 04:28, 9 January 2016

AviSource takes one or more file names and returns a clip with all files joined end to end. Note the file formats must be compatible - see Joining Clips below.

AviSource tries to read the file(s) using Avisynth's built-in OpenDML interface (derived from VirtualDub code) where possible; if the file(s) are not in OpenDML format, it uses the Video for Windows AVIFile interface.

If you have trouble with one or the other interface, OpenDMLSource and AviFileSource will force the use of OpenDML or AVIFile, respectively. Only OpenDML can read AVI files larger than 2 GB, but AVIFile is more versatile: it can read any file (under 2 GB) for which there exist appropriate stream handlers, including not only AVI but also WAV, AviSynth scripts, (AVS), and VirtualDub frameserver files (VDR). There is built-in support for decoding with Audio Compression Manager (MP3, AAC, AC3, etc).

WavSource will open a WAV file, or the audio stream from an AVI file. This can be used, for example, if your video stream is damaged or its compression method is not supported on your system.

Contents

Syntax and Parameters

AviSource(string filename [, ...] [, bool "audio", string "pixel_type", string "fourCC", int "vtrack", int "atrack"])
AviFileSource(string filename [, ...] [, bool "audio", string "pixel_type", string "fourCC", int "vtrack", int "atrack"])
OpenDMLSource(string filename [, ...] [, bool "audio", string "pixel_type", string "fourCC", int "vtrack", int "atrack"])

WavSource(string filename [, ...])

string  filename =
One or more file names. The files will be joined into a single clip with UnalignedSplice. Note the file formats must be compatible - see Joining Clips below.
bool  audio = true
If true, load the first audio stream, or the stream specified by atrack if present. If false, audio is disabled.
string  pixel_type = "FULL"
Chooses the output color format of the decompressor. Valid values are listed in the table below. This argument has no effect if the video is uncompressed, because no decompressor will be used in that case.
  • If omitted or "FULL", AviSynth will use the first format supported by the decompressor, in the order shown in the table below.
  • If "AUTO", AviSynth will use the alternate (older) order as shown.
Valid pixel_type values, listed by decoding priority (high to low)
FULL YV24 YV16 YV12 YV411 YUY2 RGB32 RGB24 Y8
AUTO YV12 YUY2 RGB32 RGB24 Y8
In other words, if you don't specify anything, it will try to output YV24; if that isn't possible it tries YV16, and if that isn't possible it tries YV12, etc ...
For planar color formats, adding a '+' prefix, e.g. AviSource(..., pixel_type="+YV12"), tells AviSynth the video rows are DWORD aligned in memory instead of packed. This can fix skew or tearing of the decoded video when the width of the picture is not divisible by 4.
string  fourCC = (auto from source)
Forces use of a different codec than the default, taken from the FourCC of the video stream.
int  vtrack = 0
Specify a numbered video track. Track numbers start from zero, and are guaranteed to be continuous (i.e. there must be a track 1 if there is a track 0 and a track 2). If no video stream numbered vtrack exists, an error will be raised.
int  atrack = 0
Specify a numbered audio track. Track numbers start from zero, and are guaranteed to be continuous (i.e. there must be a track 1 if there is a track 0 and a track 2). If no audio stream numbered atrack exists, no error will be raised, and no audio will be returned.


Notes

Joining clips

  • There is a limit of (about 50) AviSource calls in script. See discussion.
  • File formats must be compatible; that means:
  1. Both clips have the same height and width.
  2. Both clips have the same frame rate (precisely the same, not approximately)
  3. Both clips have the same audio sample rate, bit depth and number of channels.
  4. Both clips have the same color format (as presented by the decoder)

Windows 7 users

WavSource under Windows 7 is unable to load WAV files with 32-bit IEEE Float samples having the WAVEFORMAT structure. You can use ConvertAudioTo16bit or you can use ffmpeg to rewrite the header to an extensible format (just do a stream copy, -a:copy; it always writes extensible headers).

Helpful hints

  • Sometimes the colors will be distorted when loading a DivX clip in AviSynth v2.5 (the chroma channels U and V are swapped), due to a bug in DivX (5.02 and older). You can use SwapUV to correct it.
  • AVISource can also open DV type 1 video input (only video, not audio).
  • Some MJPEG/DV codecs do not give correct CCIR 601 compliant output when using AVISource. The problem could arise if the input and output color format of the codec are different. For example if the input color format is YUY2, while the output format is RGB, or vice versa. There are two ways to resolve it:
1. Force the same output as the input color format. Thus for example (if the input is RGB):
AviSource("file.avi", pixel_type="RGB32")
2. Correct it with the filter ColorYUV:
AviSource("file.avi").ColorYUV(levels="PC->TV")

More on codecs


Examples

# C programmers note: backslashes are not doubled; forward slashes work too
AVISource("d:\capture.avi")
AVISource("c:/capture/00.avi")
WAVSource("f:\soundtrack.wav")
WAVSource("f:/soundtrack.wav")
# The following statements do the same thing:
# (to join clips, file formats must be compatible - see Notes on this page)
AviSource("cap1.avi") + AviSource("cap2.avi")
AVISource("cap1.avi", "cap2.avi")
# Disable audio and request RGB32 decompression
AVISource("cap.avi", audio=false, "RGB32")
# Open a DV, forcing the Canopus DV Codec
AviSource("cap.avi", fourCC="CDVC")

# Open a file, forcing the XviD Codec
AviSource("cap.avi", fourCC="XVID")
# Splice two clips together, where one of them contains no audio.
A = AviSource("FileA.avi")
B = AviSource("FileB.avi") # No audio stream
A ++ AudioDubB, BlankClip(A)) # insert silent audio with same format
# Open a YV12 video where the width is not a multiple of four
Avisource("D:\Projects\test.avi", pixel_type="+YV12")
# opens the first video and second audio stream of a clip
AviSource("D:\Projects\test_multi10.avi", vtrack=0, atrack=1)


Changes

v2.60 Added new color formats, "AUTO" and "FULL".
Added multiple video and audio stream support
Add '+' to pixel_type for padded planar support.
v2.55 Added fourCC option.
Personal tools