LSMASHSource/LWLibavVideoSource
From Avisynth wiki
(Difference between revisions)
m (→Description) |
(Add note stating that FPS must be explicitly set when working with AVI files that have null/drop frames) |
||
(14 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | + | <div style="max-width:62em" > | |
− | + | {{FilterCat|External_filters|Plugin_functions|Source_filters}} | |
+ | This function uses [http://en.wikipedia.org/wiki/Libav#Video_codecs libavcodec] as a video decoder and libavformat as a demuxer. | ||
<br> | <br> | ||
<br> | <br> | ||
− | |||
− | |||
− | |||
− | |||
== [[Script variables|Syntax and Parameters]] == | == [[Script variables|Syntax and Parameters]] == | ||
− | :{{Template:FuncDef|LWLibavVideoSource (string source, int "stream_index", int "threads", bool "cache", int "seek_mode", int "seek_threshold", bool "dr", bool "repeat", int "dominance", | + | :{{Template:FuncDef|LWLibavVideoSource (string source, int "stream_index", int "threads", bool "cache", string "cachefile", int "seek_mode", int "seek_threshold", bool "dr", int "fpsnum", int "fpsden", bool "repeat", int "dominance", string "format", string "decoder", int "prefer_hw", int "ff_loglevel")}} |
<br> | <br> | ||
::{{Par2|source|string| }} | ::{{Par2|source|string| }} | ||
− | :::The path of the source file | + | :::The path of the source file; path can be omitted if the source file is in the same directory as the AviSynth script (*.avs). |
<br> | <br> | ||
::{{Par2|stream_index|int|-1}} | ::{{Par2|stream_index|int|-1}} | ||
Line 24: | Line 21: | ||
:::The index file avoids parsing all frames in the source file at the next or later access. | :::The index file avoids parsing all frames in the source file at the next or later access. | ||
:::Parsing all frames is very important for frame accurate seek. | :::Parsing all frames is very important for frame accurate seek. | ||
+ | <br> | ||
+ | ::{{Par2|cachefile|string|source + ".lwi"}} | ||
+ | :::The filename of the index file (where the indexing data is saved). | ||
<br> | <br> | ||
::{{Par2|seek_mode|int|0}} | ::{{Par2|seek_mode|int|0}} | ||
:::How to process when any error occurs during decoding a video frame. | :::How to process when any error occurs during decoding a video frame. | ||
− | :::: | + | ::::*0 : Normal |
:::::This mode retries sequential decoding from the next closest RAP up to 3 cycles when any decoding error occurs. | :::::This mode retries sequential decoding from the next closest RAP up to 3 cycles when any decoding error occurs. | ||
:::::If all 3 trial failed, retry sequential decoding from the last RAP by ignoring trivial errors. | :::::If all 3 trial failed, retry sequential decoding from the last RAP by ignoring trivial errors. | ||
:::::Still error occurs, then return the last returned frame. | :::::Still error occurs, then return the last returned frame. | ||
− | :::: | + | ::::*1 : Unsafe |
:::::This mode retries sequential decoding from the next closest RAP up to 3 cycles when any fatal decoding error occurs. | :::::This mode retries sequential decoding from the next closest RAP up to 3 cycles when any fatal decoding error occurs. | ||
:::::If all 3 trial failed, then return the last returned frame. | :::::If all 3 trial failed, then return the last returned frame. | ||
− | :::: | + | ::::*2 : Aggressive |
:::::This mode returns the last returned frame when any fatal decoding error occurs. | :::::This mode returns the last returned frame when any fatal decoding error occurs. | ||
− | |||
::: * RAP is an abbreviation of random accessible point. | ::: * RAP is an abbreviation of random accessible point. | ||
<br> | <br> | ||
Line 42: | Line 41: | ||
:::The threshold to decide whether a decoding starts from the closest RAP to get the requested video frame or doesn't. | :::The threshold to decide whether a decoding starts from the closest RAP to get the requested video frame or doesn't. | ||
::::Let's say | ::::Let's say | ||
− | ::::: | + | :::::the threshold is T, |
::::and | ::::and | ||
− | ::::: | + | :::::you request to seek the M-th frame called f(M) from the N-th frame called f(N). |
::::If M > N and M - N <= T, then | ::::If M > N and M - N <= T, then | ||
:::::the decoder tries to get f(M) by decoding frames from f(N) sequentially. | :::::the decoder tries to get f(M) by decoding frames from f(N) sequentially. | ||
Line 58: | Line 57: | ||
:::The output resolution will be aligned to be mod16-width and mod32-height by assuming two vertical 16x16 macroblock. | :::The output resolution will be aligned to be mod16-width and mod32-height by assuming two vertical 16x16 macroblock. | ||
:::For H.264 streams, in addition, 2 lines could be added because of the optimized chroma MC. | :::For H.264 streams, in addition, 2 lines could be added because of the optimized chroma MC. | ||
+ | <br> | ||
+ | ::{{Par2|fpsnum|int|0}} | ||
+ | :::Forced frame rate numerator. | ||
+ | :::If frame rate is set to a positive value, output frame rate is forced to the specified value by padding and/or dropping frames. | ||
+ | :::Otherwise, output frame rate is set to a computed average frame rate and the output process is performed by actual frame-by-frame. | ||
+ | :::<br> | ||
+ | :::NOTE: You must explicitly set this if the source is an AVI file that contains null/drop frames that you would like to keep. For example, AVI files captured using VirtualDub commonly contain null/drop frames that were inserted during the capture process. Unless you provide this parameter, these null frames will be discarded, commonly resulting in loss of audio/video sync. | ||
+ | <br> | ||
+ | ::{{Par2|fpsden|int|1}} | ||
+ | :::Forced frame rate denominator. | ||
+ | :::See 'fpsnum' in details. | ||
<br> | <br> | ||
::{{Par2|repeat|bool|false}} | ::{{Par2|repeat|bool|false}} | ||
:::Reconstruct frames by the flags specified in video stream and then treat all frames as interlaced if set to true and usable. | :::Reconstruct frames by the flags specified in video stream and then treat all frames as interlaced if set to true and usable. | ||
+ | :::Note that this option is ignored when VFR->CFR conversion is enabled. | ||
<br> | <br> | ||
::{{Par2|dominance|int|0}} | ::{{Par2|dominance|int|0}} | ||
:::Which field, top or bottom, is displayed first. | :::Which field, top or bottom, is displayed first. | ||
− | :::: | + | ::::*0 : Obey source flags |
− | :::: | + | ::::*1 : TFF i.e. Top -> Bottom |
− | :::: | + | ::::*2 : BFF i.e. Bottom -> Top |
:::This option is enabled only if one or more of the following conditions is true. | :::This option is enabled only if one or more of the following conditions is true. | ||
::::- 'repeat' is set to true. | ::::- 'repeat' is set to true. | ||
::::- There is a video frame consisting of two separated field coded pictures | ::::- There is a video frame consisting of two separated field coded pictures | ||
− | |||
− | |||
− | |||
− | |||
− | |||
<br> | <br> | ||
::{{Par2|format|string|""}} | ::{{Par2|format|string|""}} | ||
Line 118: | Line 124: | ||
|- | |- | ||
|"YUV420P12" | |"YUV420P12" | ||
− | |12-bit 4:2:0 planar | + | |12-bit 4:2:0 planar |
|- | |- | ||
|"YUV422P12" | |"YUV422P12" | ||
− | |12-bit 4:2:2 planar | + | |12-bit 4:2:2 planar |
|- | |- | ||
|"YUV444P12" | |"YUV444P12" | ||
− | |12-bit 4:4:4 planar | + | |12-bit 4:4:4 planar |
|- | |- | ||
|"YUV420P14" | |"YUV420P14" | ||
− | |14-bit 4:2:0 planar | + | |14-bit 4:2:0 planar |
|- | |- | ||
|"YUV422P14" | |"YUV422P14" | ||
− | |14-bit 4:2:2 planar | + | |14-bit 4:2:2 planar |
|- | |- | ||
|"YUV444P14" | |"YUV444P14" | ||
− | |14-bit 4:4:4 planar | + | |14-bit 4:4:4 planar |
|- | |- | ||
|"YUV420P16" | |"YUV420P16" | ||
Line 143: | Line 149: | ||
|"YUV444P16" | |"YUV444P16" | ||
|16-bit 4:4:4 planar | |16-bit 4:4:4 planar | ||
+ | |- | ||
+ | |"YUVA420P8" | ||
+ | |8-bit 4:2:0:4 planar with alpha channel | ||
+ | |- | ||
+ | |"YUVA422P8" | ||
+ | |8-bit 4:2:2:4 planar with alpha channel | ||
+ | |- | ||
+ | |"YUVA444P8" | ||
+ | |8-bit 4:4:4:4 planar with alpha channel | ||
+ | |- | ||
+ | |"YUVA420P10" | ||
+ | |10-bit 4:2:0:4 planar with alpha channel | ||
+ | |- | ||
+ | |"YUVA422P10" | ||
+ | |10-bit 4:2:2:4 planar with alpha channel | ||
+ | |- | ||
+ | |"YUVA444P10" | ||
+ | |10-bit 4:4:4:4 planar with alpha channel | ||
+ | |- | ||
+ | |"YUVA420P12" | ||
+ | |12-bit 4:2:0:4 planar with alpha channel | ||
+ | |- | ||
+ | |"YUVA422P12" | ||
+ | |12-bit 4:2:0:4 planar with alpha channel | ||
+ | |- | ||
+ | |"YUVA444P12" | ||
+ | |12-bit 4:4:4:4 planar with alpha channel | ||
+ | |- | ||
+ | |"YUVA420P16" | ||
+ | |16-bit 4:2:0:4 planar with alpha channel | ||
+ | |- | ||
+ | |"YUVA422P16" | ||
+ | |16-bit 4:2:2:4 planar with alpha channel | ||
+ | |- | ||
+ | |"YUVA420P16" | ||
+ | |16-bit 4:4:4:4 planar with alpha channel | ||
+ | |- | ||
+ | |"Y8" | ||
+ | |[[Y8]] / Grayscale | ||
+ | |- | ||
+ | |"Y10" | ||
+ | |10-bit grayscale (ffmpeg only) | ||
+ | |- | ||
+ | |"Y12" | ||
+ | |12-bit grayscale | ||
+ | |- | ||
+ | |"Y16" | ||
+ | |16-bit grayscale | ||
|- | |- | ||
|"YUY2" | |"YUY2" | ||
Line 150: | Line 204: | ||
|[[RGB24]] / 4:4:4 interleaved | |[[RGB24]] / 4:4:4 interleaved | ||
|- | |- | ||
− | + | |"RGB32" | |
+ | |[[RGB32]] / 4:4:4:4 interleaved | ||
+ | |- | ||
+ | |"RGB48" | ||
+ | |16-bit RGB / 4:4:4 interleaved | ||
+ | |- | ||
+ | |"RGB64" | ||
+ | |16-bit RGBA / 4:4:4:4 interleaved | ||
+ | |- | ||
+ | |"GBRP8" | ||
+ | |8-bit RGB / 4:4:4 planar | ||
+ | |- | ||
+ | |"GBRP10" | ||
+ | |10-bit RGB / 4:4:4 planar | ||
+ | |- | ||
+ | |"GBRP12" | ||
+ | |12-bit RGB / 4:4:4 planar | ||
+ | |- | ||
+ | |"GBRP14" | ||
+ | |14-bit RGB / 4:4:4 planar | ||
+ | |- | ||
+ | |"GBRP16" | ||
+ | |16-bit RGB / 4:4:4 planar | ||
+ | |- | ||
+ | |"GBRAP8" | ||
+ | |8-bit RGBA / 4:4:4:4 planar | ||
+ | |- | ||
+ | |"GBRAP10" | ||
+ | |10-bit RGBA / 4:4:4:4 planar | ||
+ | |- | ||
+ | |"GBRAP12" | ||
+ | |12-bit RGBA / 4:4:4:4 planar | ||
+ | |- | ||
+ | |"GBRAP14" | ||
+ | |14-bit RGBA / 4:4:4:4 planar | ||
+ | |- | ||
+ | |"GBRAP16" | ||
+ | |16-bit RGBA / 4:4:4:4 planar | ||
+ | |- | ||
+ | ! colspan="2"| High bit depth is only supported in AviSynth+ and VapourSynth | ||
|} | |} | ||
:::Note: direct rendering is not available at all if pixel format is forced. | :::Note: direct rendering is not available at all if pixel format is forced. | ||
<br> | <br> | ||
− | + | ::{{Par2|decoder|string|""}} | |
− | + | :::Names of preferred decoder candidates, separated by comma. For instance, if you prefer to use the 'h264_qsv' and 'mpeg2_qsv' decoders instead of the generally used 'h264' and 'mpeg2video' decoder, then specify as "h264_qsv,mpeg2_qsv". The evaluations are done in the written order and the first matched decoder, if any, is used. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
<br> | <br> | ||
+ | ::{{Par2|ff_loglevel|int|0}} | ||
+ | :::Set the log level in FFmpeg. | ||
+ | :::* 0 : AV_LOG_QUIET - Print no output. | ||
+ | :::* 1 : AV_LOG_PANIC - Something went really wrong and we will crash now. | ||
+ | :::* 2 : AV_LOG_FATAL - Something went wrong and recovery is not possible. | ||
+ | :::* 3 : AV_LOG_ERROR - Something went wrong and cannot losslessly be recovered. However, not all future data is affected. | ||
+ | :::* 4 : AV_LOG_WARNING - Something somehow does not look correct. This may or may not lead to problems. | ||
+ | :::* 5 : AV_LOG_INFO - Standard information. | ||
+ | :::* 6 : AV_LOG_VERBOSE - Detailed information. | ||
+ | :::* 7 : AV_LOG_DEBUG - Stuff which is only useful for libav* developers. | ||
+ | :::* 8 : AV_LOG_TRACE - Extremely verbose debugging, useful for libav* development. | ||
<br> | <br> | ||
+ | </div> | ||
+ | |||
+ | == Examples == | ||
+ | <div style="max-width:62em" > | ||
+ | <div {{BoxWidthIndent|56|1}} > | ||
+ | ## LWLibavVideoSource with default settings: | ||
+ | '''LWLibavVideoSource'''("source.m2ts", stream_index=-1, threads=0, | ||
+ | \ cache=true, cachefile="source.lwi" seek_mode=0, seek_threshold=10, | ||
+ | \ dr=false, fpsnum=0, fpsden=1, repeat=false, dominance=0, | ||
+ | \ format="", decoder="", prefer_hw=0, ff_loglevel=0) | ||
+ | </div> | ||
+ | <div {{BoxWidthIndent|56|1}} > | ||
+ | ## Decoding 10bit, YUV 4:2:0 source and converting to 8-bit. | ||
+ | '''LWLibavVideoSource'''(<''path''>, format="YUV420P10") | ||
+ | [[ConvertBits]](8, dither=0) ## '0' means on, '-1' means off | ||
+ | </div> | ||
+ | </div> | ||
+ | |||
----------------------------------------------- | ----------------------------------------------- | ||
'''Back to [[LSMASHSource]] ←''' | '''Back to [[LSMASHSource]] ←''' |
Latest revision as of 05:35, 4 August 2024
This function uses libavcodec as a video decoder and libavformat as a demuxer.
[edit] Syntax and Parameters
- LWLibavVideoSource (string source, int "stream_index", int "threads", bool "cache", string "cachefile", int "seek_mode", int "seek_threshold", bool "dr", int "fpsnum", int "fpsden", bool "repeat", int "dominance", string "format", string "decoder", int "prefer_hw", int "ff_loglevel")
- string source =
- The path of the source file; path can be omitted if the source file is in the same directory as the AviSynth script (*.avs).
- string source =
- int stream_index = -1
- The stream index to open in the source file. The value -1 means trying to get the video stream which has the largest resolution.
- int stream_index = -1
- int threads = 0
- The number of threads to decode a stream by libavcodec.
- The value 0 means the number of threads is determined automatically and then the maximum value will be up to 16.
- int threads = 0
- bool cache = true
- Create the index file (.lwi) to the same directory as the source file if set to true.
- The index file avoids parsing all frames in the source file at the next or later access.
- Parsing all frames is very important for frame accurate seek.
- bool cache = true
- string cachefile = source + ".lwi"
- The filename of the index file (where the indexing data is saved).
- string cachefile = source + ".lwi"
- int seek_mode = 0
- How to process when any error occurs during decoding a video frame.
- 0 : Normal
- This mode retries sequential decoding from the next closest RAP up to 3 cycles when any decoding error occurs.
- If all 3 trial failed, retry sequential decoding from the last RAP by ignoring trivial errors.
- Still error occurs, then return the last returned frame.
- 1 : Unsafe
- This mode retries sequential decoding from the next closest RAP up to 3 cycles when any fatal decoding error occurs.
- If all 3 trial failed, then return the last returned frame.
- 2 : Aggressive
- This mode returns the last returned frame when any fatal decoding error occurs.
- * RAP is an abbreviation of random accessible point.
- How to process when any error occurs during decoding a video frame.
- int seek_mode = 0
- int seek_threshold = 10
- The threshold to decide whether a decoding starts from the closest RAP to get the requested video frame or doesn't.
- Let's say
- the threshold is T,
- and
- you request to seek the M-th frame called f(M) from the N-th frame called f(N).
- If M > N and M - N <= T, then
- the decoder tries to get f(M) by decoding frames from f(N) sequentially.
- If M < N or M - N > T, then
- check the closest RAP at the first.
- After the check, if the closest RAP is identical with the last RAP, do the same as the case M > N and M - N <= T.
- Otherwise, the decoder tries to get f(M) by decoding frames from the frame which is the closest RAP sequentially.
- Let's say
- The threshold to decide whether a decoding starts from the closest RAP to get the requested video frame or doesn't.
- int seek_threshold = 10
- * RAP is an abbreviation of random accessible point.
- bool dr = false
- Try direct rendering from the video decoder if set to true.
- The output resolution will be aligned to be mod16-width and mod32-height by assuming two vertical 16x16 macroblock.
- For H.264 streams, in addition, 2 lines could be added because of the optimized chroma MC.
- bool dr = false
- int fpsnum = 0
- Forced frame rate numerator.
- If frame rate is set to a positive value, output frame rate is forced to the specified value by padding and/or dropping frames.
- Otherwise, output frame rate is set to a computed average frame rate and the output process is performed by actual frame-by-frame.
- NOTE: You must explicitly set this if the source is an AVI file that contains null/drop frames that you would like to keep. For example, AVI files captured using VirtualDub commonly contain null/drop frames that were inserted during the capture process. Unless you provide this parameter, these null frames will be discarded, commonly resulting in loss of audio/video sync.
- int fpsnum = 0
- int fpsden = 1
- Forced frame rate denominator.
- See 'fpsnum' in details.
- int fpsden = 1
- bool repeat = false
- Reconstruct frames by the flags specified in video stream and then treat all frames as interlaced if set to true and usable.
- Note that this option is ignored when VFR->CFR conversion is enabled.
- bool repeat = false
- int dominance = 0
- Which field, top or bottom, is displayed first.
- 0 : Obey source flags
- 1 : TFF i.e. Top -> Bottom
- 2 : BFF i.e. Bottom -> Top
- This option is enabled only if one or more of the following conditions is true.
- - 'repeat' is set to true.
- - There is a video frame consisting of two separated field coded pictures
- Which field, top or bottom, is displayed first.
- int dominance = 0
- string format = ""
- Force specified output pixel format if 'format' is specified.
- The following formats are available currently.
- string format = ""
Format Comments "YUV420P8" YV12 / 4:2:0 planar "YUV422P8" YV16 / 4:2:2 planar "YUV444P8" YV24 / 4:4:4 planar "YUV410P8" 4:1:0 planar "YUV411P8" YV411 / 4:1:1 planar "YUV420P9" 9-bit 4:2:0 planar "YUV422P9" 9-bit 4:2:2 planar "YUV444P9" 9-bit 4:4:4 planar "YUV420P10" 10-bit 4:2:0 planar "YUV422P10" 10-bit 4:2:2 planar "YUV444P10" 10-bit 4:4:4 planar "YUV420P12" 12-bit 4:2:0 planar "YUV422P12" 12-bit 4:2:2 planar "YUV444P12" 12-bit 4:4:4 planar "YUV420P14" 14-bit 4:2:0 planar "YUV422P14" 14-bit 4:2:2 planar "YUV444P14" 14-bit 4:4:4 planar "YUV420P16" 16-bit 4:2:0 planar "YUV422P16" 16-bit 4:2:2 planar "YUV444P16" 16-bit 4:4:4 planar "YUVA420P8" 8-bit 4:2:0:4 planar with alpha channel "YUVA422P8" 8-bit 4:2:2:4 planar with alpha channel "YUVA444P8" 8-bit 4:4:4:4 planar with alpha channel "YUVA420P10" 10-bit 4:2:0:4 planar with alpha channel "YUVA422P10" 10-bit 4:2:2:4 planar with alpha channel "YUVA444P10" 10-bit 4:4:4:4 planar with alpha channel "YUVA420P12" 12-bit 4:2:0:4 planar with alpha channel "YUVA422P12" 12-bit 4:2:0:4 planar with alpha channel "YUVA444P12" 12-bit 4:4:4:4 planar with alpha channel "YUVA420P16" 16-bit 4:2:0:4 planar with alpha channel "YUVA422P16" 16-bit 4:2:2:4 planar with alpha channel "YUVA420P16" 16-bit 4:4:4:4 planar with alpha channel "Y8" Y8 / Grayscale "Y10" 10-bit grayscale (ffmpeg only) "Y12" 12-bit grayscale "Y16" 16-bit grayscale "YUY2" YUY2 / 4:2:2 interleaved "RGB24" RGB24 / 4:4:4 interleaved "RGB32" RGB32 / 4:4:4:4 interleaved "RGB48" 16-bit RGB / 4:4:4 interleaved "RGB64" 16-bit RGBA / 4:4:4:4 interleaved "GBRP8" 8-bit RGB / 4:4:4 planar "GBRP10" 10-bit RGB / 4:4:4 planar "GBRP12" 12-bit RGB / 4:4:4 planar "GBRP14" 14-bit RGB / 4:4:4 planar "GBRP16" 16-bit RGB / 4:4:4 planar "GBRAP8" 8-bit RGBA / 4:4:4:4 planar "GBRAP10" 10-bit RGBA / 4:4:4:4 planar "GBRAP12" 12-bit RGBA / 4:4:4:4 planar "GBRAP14" 14-bit RGBA / 4:4:4:4 planar "GBRAP16" 16-bit RGBA / 4:4:4:4 planar High bit depth is only supported in AviSynth+ and VapourSynth
- Note: direct rendering is not available at all if pixel format is forced.
- string decoder = ""
- Names of preferred decoder candidates, separated by comma. For instance, if you prefer to use the 'h264_qsv' and 'mpeg2_qsv' decoders instead of the generally used 'h264' and 'mpeg2video' decoder, then specify as "h264_qsv,mpeg2_qsv". The evaluations are done in the written order and the first matched decoder, if any, is used.
- string decoder = ""
- int ff_loglevel = 0
- Set the log level in FFmpeg.
- 0 : AV_LOG_QUIET - Print no output.
- 1 : AV_LOG_PANIC - Something went really wrong and we will crash now.
- 2 : AV_LOG_FATAL - Something went wrong and recovery is not possible.
- 3 : AV_LOG_ERROR - Something went wrong and cannot losslessly be recovered. However, not all future data is affected.
- 4 : AV_LOG_WARNING - Something somehow does not look correct. This may or may not lead to problems.
- 5 : AV_LOG_INFO - Standard information.
- 6 : AV_LOG_VERBOSE - Detailed information.
- 7 : AV_LOG_DEBUG - Stuff which is only useful for libav* developers.
- 8 : AV_LOG_TRACE - Extremely verbose debugging, useful for libav* development.
- Set the log level in FFmpeg.
- int ff_loglevel = 0
[edit] Examples
## LWLibavVideoSource with default settings: LWLibavVideoSource("source.m2ts", stream_index=-1, threads=0, \ cache=true, cachefile="source.lwi" seek_mode=0, seek_threshold=10, \ dr=false, fpsnum=0, fpsden=1, repeat=false, dominance=0, \ format="", decoder="", prefer_hw=0, ff_loglevel=0)
## Decoding 10bit, YUV 4:2:0 source and converting to 8-bit. LWLibavVideoSource(<path>, format="YUV420P10") ConvertBits(8, dither=0) ## '0' means on, '-1' means off
Back to LSMASHSource ←