Editing AviSource

From Avisynth wiki
Jump to: navigation, search

Warning: You are not logged in.

Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
<div style="max-width:62em" >
+
{{Template:Func4Def|AviSource(string filename [, ... ], [bool audio &#61; true], [string pixel_type &#61; "FULL"], [string fourCC], [int vtrack &#61; 0], [int atrack &#61; 0])|OpenDMLSource(string filename [, ... ], [bool audio &#61; true], [string pixel_type &#61; "FULL"], [string fourCC], [int vtrack &#61; 0], [int atrack &#61; 0])|AviFileSource(string filename [, ... ], [bool audio &#61; true], [string pixel_type &#61; "FULL"], [string fourCC], [int vtrack &#61; 0], [int atrack &#61; 0])|WavSource(string filename [, ... ])}}
  
<div {{BlueBox2|40|0|3px solid purple}} >
+
'''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]].
{{AvsPlusFullname}}<br>
+
Up-to-date documentation: [https://avisynthplus.readthedocs.io/en/latest/avisynthdoc/corefilters/avisource.html https://avisynthplus.readthedocs.io]
+
</div>
+
  
'''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.
+
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).
  
<div {{NotaBeneWidthIndent|56|2|none}} >
+
'''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.
'''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 '''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''.
+
===== Parameters =====
</div>
+
  
'''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>.
+
All parameters are optional.
</div>
+
:;audio (default true)
 +
::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.
  
== Syntax and Parameters ==
+
:;pixel_type
<div style="max-width:68em" >
+
::Chooses the output color format of the decompressor. Valid values are "[[YV24]]", "[[YV16]]", "[[YV12]]", "[[YV411]]", "[[YUY2]]", "[[RGB32]]", "[[RGB24]]", "[[Y8]]", "AUTO" and "FULL" (default value).
{{Func3Def
+
|AviSource(string ''filename'' [, ...] [, bool "''audio''", string "''pixel_type''", string "''fourCC''", int "''vtrack''", int "''atrack''", {{AvsPluscon}} bool "''utf8''"])
+
|AviFileSource(string ''filename'' [, ...] [, bool "''audio''", string "''pixel_type''", string "''fourCC''", int "''vtrack''", int "''atrack''", {{AvsPluscon}} bool "''utf8''"])
+
|OpenDMLSource(string ''filename'' [, ...] [, bool "''audio''", string "''pixel_type''", string "''fourCC''", int "''vtrack''", int "''atrack''", {{AvsPluscon}} bool "''utf8''"])
+
}}
+
  
{{FuncDef
+
::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]].
|WavSource(string ''filename'' [, ...][, {{AvsPluscon}} bool "''utf8''"])
+
}}
+
  
:{{Par2|filename|string|}}
+
::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 ...
::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. {{AvsPluscon}} utf8 file names are supported since Avs+r2768.
+
  
:{{Par2|audio|bool|true}}
+
::This parameter has no effect if the video is in an uncompressed format, because no decompressor will be used in that case.  
::If true, load the first audio stream, or the stream specified by {{FuncArg|atrack}} if present. If false, audio is disabled.
+
  
:{{Par2|pixel_type|string|"FULL"}}
+
::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")
::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.
+
:;fourCC
::*If "AUTO", AviSynth will use the alternate (older) order as shown.
+
::Forces use of a different codec than the default taken from the [[FourCC]] of the video stream.
:::{|class="wikitable"
+
!pixel_type
+
!colspan="8" style="text-align:left;"|&nbsp; Color formats, 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 ...
+
  
::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''' with bad codecs when the width of the picture is not divisible by 4.
+
:;vtrack (default 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.
  
:{{Par2|fourCC|string|(auto from source)}}
+
:;atrack (default 0)
::Forces AviSynth to use a specific decoder instead of the one specified in the source file. See [[FourCC]] for more information.
+
::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.
  
:{{Par2|vtrack|int|0}}
+
===== Helpful hints =====
::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}}
+
* There is a limit of (about 50) AviSource calls in script. See [http://forum.doom9.org/showthread.php?t=131687 discussion].
::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.
+
  
:{{AvsPluscon}}
+
* 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.
:{{Par2|utf8|bool|false}}
+
::If true, file name is treated as utf8. Since r2768.
+
  
</div>
+
* From v2.53 AVISource can also open DV type 1 video input (only video, not audio).
  
== Notes ==
+
* 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:
<div style="max-width:62em" >
+
==== Joining clips ====
+
  
* There is a limit (of about 50, sometimes fewer) '''AviSource''' calls in script - see [http://forum.doom9.org/showthread.php?t=131687 discussion]. If the limit is exceeded, you will see the error message
+
:1. Force the same output as the input color format. Thus for example (if the input is RGB):
:: ''AVISource: couldn't locate a decompressor for fourcc ....''
+
:If you need to join more AVIs, try [[VirtualDub]] (limit > 700)
+
  
* [[Clip_properties|Media properties]] must be compatible, meaning they must have:
+
::<code>AviSource("file.avi", pixel_type="RGB32")</code>
:# the same height and width;
+
:# the same color format (as presented by the decoder);
+
:# the same frame rate (''precisely'' the same, not approximately); and
+
:# 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.
+
:2. Correct it with the filter [[ColorYUV]]:
  
==== Windows 7 users ====
+
::<code>AviSource("file.avi").ColorYUV(levels="PC->TV")</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 [http://ffmpeg.zeranoe.com/builds/ ffmpeg] to rewrite the header to an extensible format (just do a stream copy; it always writes extensible headers)
+
===== More on codecs =====
<div {{BoxWidthIndent|32|2}} >
+
ffmpeg -i "bad.wav" -c copy "good.wav"
+
</div>
+
  
==== Helpful hints ====
+
Some reference threads:
  
* 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.
 
 
* '''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 [[Convert|conversion]]. To avoid this conversion, try to specify another, compatible output format - for example:
 
:*If the video was encoded as [[RGB]], try {{FuncArg|pixel_type}}="RGB24" or "RGB32";
 
:*If the video was encoded as [[YUV]], try {{FuncArg|pixel_type}}="YV12", "YUY2" or "YV24".
 
:If that does not work, try [[FFmpegSource]], [[LSMASHSource]] or (if absolutely necessary) [[DirectShowSource]].
 
 
==== 10+ bit inputs ====
 
{{AvsPluscon}}
 
:When a classic 'pixel_type' shares more internal formats (such as YUV422P10 first tries to request the v210 then P210 format) you can specify one of the specific format directly. Note that high bit-depth RGBP (Planar RGB) is prioritized against packed RGB48/64.
 
 
:The 'FourCCs for ICDecompressQuery' column means that when a codec supports the format, it will serve the frame in that one, Avisource then will convert it to the proper colorspace.
 
 
  Full support list. Non *-marked formats (FourCC column) are supported since r2724.
 
  'pixel_type' Avs+ Format  FourCC(s) for ICDecompressQuery
 
  YV24        YV24          *YV24
 
  YV16        YV16          *YV16
 
  YV12        YV12          *YV12
 
  YV411        YV411        *Y41B
 
  YUY2        YUY2          *YUY2
 
  RGBP10      RGBP10        G3[0][10]  r210  R10k
 
  r210        RGBP10        r210
 
  R10k        RGBP10        R10k           
 
  RGBP        RGBP10        G3[0][10]  r210  R10k
 
              RGBP12        G3[0][12]
 
              RGBP14        G3[0][14]
 
              RGBP16        G3[0][16]
 
              RGBAP10      G4[0][10]
 
              RGBAP12      G4[0][12]
 
              RGBAP14      G4[0][14]
 
              RGBAP16      G4[0][16]
 
  RGB32        RGB32        *BI_RGB internal constant (0) with bitcount=32
 
  RGB24        RGB24        *BI_RGB internal constant (0) with bitcount=24
 
  RGB48        RGB48        BGR[48]    b48r
 
  RGB64        RGB64        *BRA[64]  b64a
 
  Y8          Y8            Y800      Y8[32][32]  GREY
 
  Y            Y8            Y800      Y8[32][32]  GREY
 
              Y10          Y1[0][10]
 
              Y12          Y1[0][12]
 
              Y14          Y1[0][14]
 
              Y16          Y1[0][16]
 
  YUV422P10    YUV422P10    v210      P210
 
  v210        YUV422P10    v210
 
  P210        YUV422P10    P210
 
  YUV422P16    YUV422P16    P216
 
  P216        YUV422P16    P216
 
  YUV420P10    YUV420P10    P010
 
  P010        YUV422P10    P010
 
  YUV420P16    YUV420P16    P016
 
  P016        YUV422P16    P016
 
  YUV444P10    YUV444P10    v410
 
  v410        YUV444P10    v410
 
 
==== More on codecs ====
 
Some reference threads:
 
 
*[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]
</div>
 
  
== Examples ==
+
===== Examples =====
<div style="max-width:62em" >
+
 
* C programmers note: backslashes are not doubled; forward slashes work too
+
# C programmers note: backslashes are not doubled; forward slashes work too
<div {{BoxWidthIndent|48|1}} >
+
 
  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")
</div>
 
  
* Splice two clips together; the following statements do the same thing.
+
# the following is the same as AVISource("cap1.avi") + AVISource("cap2.avi"):
<div {{BoxWidthIndent|48|1}} >
+
AviSource("cap1.avi") + AviSource("cap2.avi")
+
 
  AVISource("cap1.avi", "cap2.avi")
 
  AVISource("cap1.avi", "cap2.avi")
</div>
 
  
* Splice two clips together where frame rates do not match.
+
# disables audio and request RGB32 decompression
<div {{BoxWidthIndent|48|1}} >
+
  AVISource("cap.avi", false, "RGB32")
  A = AviSource("FileA.avi") # "29.97" fps (30000/1001)
+
B = AviSource("FileB.avi") # 30.0000 fps
+
A ++ B.[[AssumeFPS]](A)
+
</div>
+
  
* Splice two clips together where one of them contains no audio.
+
# opens a DV using the Canopus DV Codec
<div {{BoxWidthIndent|48|1}} >
+
  AviSource("cap.avi", false, fourCC="CDVC")
  A = AviSource("FileA.avi") # with audio
+
  B = AviSource("FileB.avi") # no audio stream
+
# opens an avi (for example DivX3) using the XviD Codec
A ++ [[AudioDub]](B, [[BlankClip]](A)) # insert silent audio with same format
+
  AviSource("cap.avi", false, fourCC="XVID")
</div>
+
  
* Disable audio and request RGB32 decompression
+
# splicing two clips where one of them contains no audio.
<div {{BoxWidthIndent|48|1}} >
+
# when splicing the clips must be compatible (have the same video and audio properties):
  AVISource("cap.avi", ''audio''=false, ''pixel_type''="RGB32")
+
  A = AviSource("FileA.avi")
</div>
+
B = AviSource("FileB.avi") # No audio stream
 +
A ++ AudioDub(B, BlankClip(A))
  
* Open a DV, forcing the Canopus DV Codec
+
# opens YV12 where the width is not a multiple of four
<div {{BoxWidthIndent|48|1}} >
+
  Avisource("D:\Projects\test.avi", pixel_type="+YV12")
  AviSource("cap.avi", ''fourCC''="CDVC")
+
</div>
+
  
* Open a file, forcing the [[Xvid|XviD]] Codec
+
# opens the second video and second audio stream of a clip
<div {{BoxWidthIndent|48|1}} >
+
  AviSource("D:\Projects\test_multi10.avi", vtrack=1, atrack=1)
  AviSource("cap.avi", ''fourCC''="XVID")
+
</div>
+
  
* Open a YV12 video with a bad codec where the width is not a multiple of four
+
===== Windows7 users =====
<div {{BoxWidthIndent|48|1}} >
+
Avisource("D:\Projects\test.avi", ''pixel_type''="+YV12")
+
</div>
+
  
* opens the first video and second audio stream of a clip
+
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).
<div {{BoxWidthIndent|48|1}} >
+
AviSource("D:\Projects\test_multi10.avi", ''vtrack''=0, ''atrack''=1)
+
</div>
+
</div>
+
  
 
+
===== Changes =====
== Changes ==
+
 
{| border="1"
 
{| border="1"
|-
 
| {{AvsPluscon}} r2724
 
| Added 10+ bits new color formats
 
 
|-  
 
|-  
 
| v2.60
 
| v2.60
Line 242: Line 109:
 
| Added fourCC option.
 
| Added fourCC option.
 
|}
 
|}
 
  
 
{{FilterCat|Internal filters|Media file filters|Source_filters}}
 
{{FilterCat|Internal filters|Media file filters|Source_filters}}

Please note that all contributions to Avisynth wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Avisynth wiki:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)
Personal tools