AviSource

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (one more touch-up)
(one more touch-up)
Line 1: Line 1:
'''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 [[#Notes|''Notes'']] below.
+
'''AviSource''' takes one or more files - not only [[AVI]] but also [[WAV]] (audio), [[AVS]] (AviSynth scripts), and [http://www.virtualdub.org/docs_frameserver.html VDR] ([[VirtualDub]] frameserver) files. There is built-in [http://en.wikipedia.org/wiki/Windows_legacy_audio_components#Audio_Compression_Manager ''Audio Compression Manager''] support for decoding compressed audio tracks (MP3, AAC, AC3, etc). If more than one file name is given, '''AviSource''' returns a clip with all files joined end to end. For the files to be joined, the media properties must be compatible - see [[#Notes|Notes]] below.
  
 
<div {{NotaBeneWidthIndent|56|2|none}} >
 
<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.  
 
'''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.  
  
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).
+
If '''AviSource''' has trouble with one or the other interface, '''OpenDMLSource''' and '''AviFileSource''' will force the use of ''OpenDML'' or ''AVIFile'', respectively. Only ''OpenDML'' can read files larger than 2 GB, but only ''AVIFile'' can read non-AVI files (odd, given its name) like the ones listed in the opening paragraph. It can read any file (under 2 GB) for which there exist appropriate ''stream handlers''.  
 
</div>
 
</div>
  
'''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.
+
'''WavSource''' will open a [[WAV]] file, or an audio-only AVI file. It will also return the audio stream from a normal video+audio AVI. This might be useful if your video stream is damaged or unreadable, or simply as a shortcut for<tt> AviSource(</tt>...<tt>).[[KillVideo]]</tt>.
  
 
== Syntax and Parameters ==
 
== Syntax and Parameters ==
Line 21: Line 21:
  
 
:{{Par2|filename|string|}}
 
:{{Par2|filename|string|}}
::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 [[#Notes|''Notes'']] below.
+
::One or more file names. The files will be joined into a single clip with [[Splice|UnalignedSplice]]. To join files, the media properties must be compatible - see [[#Notes|Notes]] below.
  
 
:{{Par2|audio|bool|true}}
 
:{{Par2|audio|bool|true}}
Line 27: Line 27:
  
 
:{{Par2|pixel_type|string|"FULL"}}
 
:{{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.  
+
::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, as 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 omitted or "FULL", AviSynth will use the first format supported by the decompressor, in the order shown in the table below.
Line 56: Line 56:
 
::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 ...
 
::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|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.
+
::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.
  
 
:{{Par2|fourCC|string|(auto from source)}}
 
:{{Par2|fourCC|string|(auto from source)}}
::Forces use of a different codec than the default, taken from the [[FourCC]] of the video stream.
+
::Tells AviSynth to assume a new [[FourCC]] to force the use of a different decoder.
  
 
:{{Par2|vtrack|int|0}}
 
:{{Par2|vtrack|int|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 {{FuncArg|vtrack}} exists, an error will be raised.  
+
::Specifies 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.  
  
 
:{{Par2|atrack|int|0}}
 
:{{Par2|atrack|int|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 {{FuncArg|atrack}} exists, no error will be raised, and no audio will be returned.
+
::Specifies 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.
  
  
Line 73: Line 73:
 
* There is a limit of (about 50) '''AviSource''' calls in script. See [http://forum.doom9.org/showthread.php?t=131687 discussion].
 
* There is a limit of (about 50) '''AviSource''' calls in script. See [http://forum.doom9.org/showthread.php?t=131687 discussion].
  
* File formats must be compatible; that means:
+
* [[Clip_properties|Media properties]] must be compatible, meaning they must have:
:# Both clips have the same height and width.
+
:# the same height and width;
:# Both clips have the same frame rate (''precisely'' the same, not approximately)
+
:# the same color format (as presented by the decoder);
:# Both clips have the same audio sample rate, bit depth and number of channels.
+
:# the same frame rate (''precisely'' the same, not approximately); and
:# Both clips have the same color format (as presented by the decoder)
+
:# the same audio sample rate, bit depth and number of channels.
  
 
* 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.
 
* 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.
Line 83: Line 83:
 
==== Windows 7 users ====
 
==== Windows 7 users ====
  
* '''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).
+
* '''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 [http://ffmpeg.zeranoe.com/builds/ ffmpeg] to rewrite the header to an extensible format (just do a stream copy; it always writes extensible headers)
 +
<div {{BoxWidthIndent|32|2}} >
 +
ffmpeg -i "bad.avi" -c copy "good.avi"
 +
</div>
  
 
==== Helpful hints ====
 
==== Helpful hints ====
Line 91: Line 94:
 
* '''AVISource''' can also open DV type 1 video input (only video, not audio).
 
* '''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:
+
* Some video files get decoded with the wrong color standard ('Rec601'/'Rec709') or luma range ('Full'/'TV'). This problem can arise if the input and output color formats are different, forcing a [[Convert|conversion]]. To avoid this conversion, try to specify another, compatible output format - for example:
:1. Force the same output as the input color format. Thus for example (if the input is RGB):
+
:*If the video was encoded as [[RGB]], try {{FuncArg|pixel_type}}="RGB24" or "RGB32";
::<tt>AviSource("file.avi", pixel_type="RGB32")</tt>
+
:*If the video was encoded as [[YUV]], try {{FuncArg|pixel_type}}="YV12", "YUY2" or "YV24".
:2. Correct it with the filter [[ColorYUV]]:
+
:If that does not work, try [[FFmpegSource]], [[LSMASHSource]] or (if absolutely necessary) [[DirectShowSource]].
::<tt>AviSource("file.avi").ColorYUV(levels="PC->TV")</tt>
+
  
 
==== More on codecs ====
 
==== More on codecs ====
Line 107: Line 109:
 
  # C programmers note: backslashes are not doubled; forward slashes work too
 
  # C programmers note: backslashes are not doubled; forward slashes work too
 
  AVISource("d:\capture.avi")
 
  AVISource("d:\capture.avi")
AVISource("c:/capture/00.avi")
 
WAVSource("f:\soundtrack.wav")
 
 
  WAVSource("f:/soundtrack.wav")
 
  WAVSource("f:/soundtrack.wav")
  
  # The following statements do the same thing:
+
  # Splice two clips together; 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") + AviSource("cap2.avi")
 
  AVISource("cap1.avi", "cap2.avi")
 
  AVISource("cap1.avi", "cap2.avi")
 +
 +
# Splice two clips together where frame rates do not match.
 +
A = AviSource("FileA.avi") # "29.97" fps (30000/1001)
 +
B = AviSource("FileB.avi") # 30.0000 fps
 +
A ++ B.[[AssumeFPS]](A)
 +
 +
# Splice two clips together where one of them contains no audio.
 +
A = AviSource("FileA.avi") # with audio
 +
B = AviSource("FileB.avi") # no audio stream
 +
A ++ [[AudioDub]]B, [[BlankClip]](A)) # insert silent audio with same format
  
 
  # Disable audio and request RGB32 decompression
 
  # Disable audio and request RGB32 decompression
  AVISource("cap.avi", '''audio'''=false, "RGB32")
+
  AVISource("cap.avi", ''audio''=false, ''pixel_type''="RGB32")
  
 
  # Open a DV, forcing the Canopus DV Codec
 
  # Open a DV, forcing the Canopus DV Codec
  AviSource("cap.avi", '''fourCC'''="CDVC")
+
  AviSource("cap.avi", ''fourCC''="CDVC")
+
 
 
  # Open a file, forcing the [[Xvid|XviD]] Codec
 
  # Open a file, forcing the [[Xvid|XviD]] Codec
  AviSource("cap.avi", '''fourCC'''="XVID")
+
  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 ++ [[AudioDub]]B, [[BlankClip]](A)) # insert silent audio with same format
+
  
 
  # Open a YV12 video where the width is not a multiple of four
 
  # Open a YV12 video where the width is not a multiple of four
  Avisource("D:\Projects\test.avi", pixel_type="'''+'''YV12")
+
  Avisource("D:\Projects\test.avi", ''pixel_type''="+YV12")
  
 
  # opens the first video and second audio stream of a clip
 
  # opens the first video and second audio stream of a clip
  AviSource("D:\Projects\test_multi10.avi", '''vtrack'''=0, '''atrack'''=1)
+
  AviSource("D:\Projects\test_multi10.avi", ''vtrack''=0, ''atrack''=1)
  
  

Revision as of 15:33, 9 January 2016

AviSource takes one or more files - not only AVI but also WAV (audio), AVS (AviSynth scripts), and VDR (VirtualDub frameserver) files. There is built-in Audio Compression Manager support for decoding compressed audio tracks (MP3, AAC, AC3, etc). If more than one file name is given, AviSource returns a clip with all files joined end to end. For the files to be joined, the media properties must be compatible - see Notes 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 AviSource has trouble with one or the other interface, OpenDMLSource and AviFileSource will force the use of OpenDML or AVIFile, respectively. Only OpenDML can read files larger than 2 GB, but only AVIFile can read non-AVI files (odd, given its name) like the ones listed in the opening paragraph. It can read any file (under 2 GB) for which there exist appropriate stream handlers.

WavSource will open a WAV file, or an audio-only AVI file. It will also return the audio stream from a normal video+audio AVI. This might be useful if your video stream is damaged or unreadable, or simply as a shortcut for AviSource(...).KillVideo.

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. To join files, the media properties must be compatible - see Notes 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, as 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)
Tells AviSynth to assume a new FourCC to force the use of a different decoder.
int  vtrack = 0
Specifies 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
Specifies 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.
  1. the same height and width;
  2. the same color format (as presented by the decoder);
  3. the same frame rate (precisely the same, not approximately); and
  4. the same audio sample rate, bit depth and number of channels.

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 ffmpeg to rewrite the header to an extensible format (just do a stream copy; it always writes extensible headers)
ffmpeg -i "bad.avi" -c copy "good.avi"

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 video files get decoded with the wrong color standard ('Rec601'/'Rec709') or luma range ('Full'/'TV'). This problem can arise if the input and output color formats are different, forcing a conversion. To avoid this conversion, try to specify another, compatible output format - for example:
  • If the video was encoded as RGB, try pixel_type="RGB24" or "RGB32";
  • If the video was encoded as YUV, try pixel_type="YV12", "YUY2" or "YV24".
If that does not work, try FFmpegSource, LSMASHSource or (if absolutely necessary) DirectShowSource.

More on codecs

Some reference threads:


Examples

# C programmers note: backslashes are not doubled; forward slashes work too
AVISource("d:\capture.avi")
WAVSource("f:/soundtrack.wav")
# Splice two clips together; the following statements do the same thing.
AviSource("cap1.avi") + AviSource("cap2.avi")
AVISource("cap1.avi", "cap2.avi")
# Splice two clips together where frame rates do not match.
A = AviSource("FileA.avi") # "29.97" fps (30000/1001)
B = AviSource("FileB.avi") # 30.0000 fps
A ++ B.AssumeFPS(A)
# Splice two clips together where one of them contains no audio.
A = AviSource("FileA.avi") # with audio
B = AviSource("FileB.avi") # no audio stream
A ++ AudioDubB, BlankClip(A)) # insert silent audio with same format
# Disable audio and request RGB32 decompression
AVISource("cap.avi", audio=false, pixel_type="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")
# 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