View Full Version : L-SMASH Source
qyot27
5th March 2024, 19:32
I have another problem with LWLibav and AV1 video.
My graphics card can decode AV1, but LWLibav apparently only uses software decoding.
LWLibav prefer_hw=0 or prefer_hw=1 = 15 fps
DirectShowSource = 32 fps
Here I have uploaded the used video for testing.
https://drive.google.com/drive/folders/1Q4ikSHegEgHyL3MfaXfmfHMCV4pzBQzH?usp=drive_link
Can anyone confirm this?
At least on the Wiki, prefer_hw's arguments are only listed on the LSMASHVideoSource page despite the parameter list for LwLibavVideoSource including it, but regardless, it's something that tries to be intelligent (0 is software decoding, 1 isn't even listed as an option, 2 is Intel QSV, and 3 is a ladder that tries CUVID first, then QSV, then software decoding).
But there's no need to try to be intelligent about it if you explicitly call the correct hardware variant codec with decoder.
https://i.imgur.com/TgF1yi8l.png (https://i.imgur.com/TgF1yi8.png)
And as far as I could gather, it then also depends on what graphics card you have and how it's trying to be called. I've had issues trying to get anything (including mpv opening the file directly) to play AV1 with hwdec with D3D11 on Windows, even if FFmpeg has been linked with libvpl and has D3D11 enabled, although it generally goes several months between attempts. Maybe it finally got fixed since the last time I tried (or it was finally working in mpv the last time I tried, but I forgot).
gispos
5th March 2024, 20:16
I think I have chosen the right option, with h264 it works with the hardware decoding with my Nvidia card.
So it is written:
+ prefer_hw (default : 0)
Whether to prefer hardware accelerated decoder to software decoder.
Have no effect if 'decoder' is specified.
- 0 : Use default software decoder.
- 1 : Use NVIDIA CUVID acceleration for supported codec, otherwise use default software decoder.
- 2 : Use Intel Quick Sync Video acceleration for supported codec, otherwise use default software decoder.
- 3 : Try hardware decoder in the order of CUVID->QSV. If none is available then use default software decoder.
+ prefer_hw (default : 0)
Same as 'prefer_hw' of LSMASHVideoSource().
With DirectShowSource it runs over 100% faster, apparently the hardware decoding works better.
I use LavFilter, doesn't that also have something in common with libav?
StvG
5th March 2024, 20:22
For AV1 the threads are hardcoded (https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works/blob/master/common/decode.c#L137-L138) to 1 in order to be frame seeking accurate (same as ffms2 (at least the version I share)).
gispos
5th March 2024, 20:22
...When you're comparing the speed of LWLibav and DirectShowSource, did you compare if DirectShowSource is frame accurate when seeking?
I didn't pay attention to it, I tested it in playback and with Analisy FPS (i.e. without display playback). I have to test again, but DirectShow runs smoothly without seeking problems.
Edit:
I didn't find a position error, I set several bookmarks and jumped back and forth, and in between jumped to different positions with the slider.
DirectShowSource(SourceFile, seek=true, audio=true, video=true, convertfps=false, seekzero=false, timeout=60000)
gispos
5th March 2024, 21:27
I've had issues trying to get anything (including mpv opening the file directly).
Sorry, but the uploaded video was converted by google drive. So it is not the original.
I have uploaded it again in a 7z archive. https://drive.google.com/drive/folders/1Q4ikSHegEgHyL3MfaXfmfHMCV4pzBQzH?usp=drive_link
It's also a bit strange, VDub2 can't play the script cleanly, it keeps stalling.
AvsPmod and PotPlayer play the script smoothly without stalling.
DirectShowSource(SourceFile, seek=true, audio=true, video=true, convertfps=false, seekzero=false, timeout=60000)
/**avsp_split**/
ConvertBits(16)
DGHDRToSDR(white=1863, black=0, gamma=0.42, hue=0.00, r=1.00, g=1.00, b=1.15, tm=0.90, roll=0.70, fulldepth=false, impl="255", mode="pq")
ConvertToYV12(matrix="Rec709")
prefetch(4)
StvG
5th March 2024, 22:25
I didn't pay attention to it, I tested it in playback and with Analisy FPS (i.e. without display playback). I have to test again, but DirectShow runs smoothly without seeking problems.
Edit:
I didn't find a position error, I set several bookmarks and jumped back and forth, and in between jumped to different positions with the slider.
DirectShowSource(SourceFile, seek=true, audio=true, video=true, convertfps=false, seekzero=false, timeout=60000)
I can confirm that DirectShowSource is ok for AV1 regarding the frame seeking.
It seems from some time FFmpeg made AV1 changes so more threads can be used without affecting the seeking. You can try ffms2 5.0-RC2 (https://github.com/FFMS/ffms2/releases/tag/5.0-RC2) (it's ok AV1 seeking (https://imgbb.com/vZsFK3J) (rav1... samples)).
qyot27
6th March 2024, 00:55
Sorry, but the uploaded video was converted by google drive. So it is not the original.
I have uploaded it again in a 7z archive. https://drive.google.com/drive/folders/1Q4ikSHegEgHyL3MfaXfmfHMCV4pzBQzH?usp=drive_link
I don't think so? The 'new' file is roughly half the length of the previous one, which could likely account for the file size difference. But the result is still the same: directly specifying the decoder as av1_qsv lets LwLibavVideoSource open the file using the hardware decoder, and the choppiness present for CPU-only decoding disappears.
Attempts to use prefer_hw were fruitless, and upon more testing, I can verify that prefer_hw modes 3 and 2 both work fine with H264, HEVC, and VP9, but fails with AV1. It *always* selects software decoding.
Issue #48 (https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works/issues/48) involved testing some decoder things and introduced the LWLDECODER variable that gets set to the codec name actually used when decoding. It can be used to verify what prefer_hw is actually doing, and the results are as follows:
decoder="av1_qsv" results in LWLDECODER == "av1_qsv" and playback is smooth
prefer_hw=3 and prefer_hw=2 both result in LWLDECODER == "libdav1d" (which is software) and playback is choppy because my i5-9400 isn't up to the task of decoding 4K 10bit AV1 smoothly, even with as optimized as libdav1d is.
And after *even more* testing, the issue is centered around libdav1d. I opened an issue on the L-SMASH-Works side about this, but if the FFmpeg that it links to has libdav1d enabled, prefer_hw will not correctly detect av1_* hardware decoders.
If the FFmpeg is built without libdav1d, then prefer_hw does work and correctly selects av1_qsv. But at the same time, if libdav1d (or libaom as well, presumably) isn't enabled, then you get no software fallback for AV1, because FFmpeg does not have a native av1 decoder. It goes from 'only able to use hw decode if you manually select the av1_* hw decoder' to 'you must use prefer_hw on AV1 so it decodes at all'.
gispos
6th March 2024, 18:27
I don't think so? The 'new' file is roughly half the length of the previous one, which could likely account for the file size difference. But the result is still the same...
I suspected as I had seen 1280 x 512 pixels in your picture under the information. I have just seen that you have changed the size in the script.
decoder="av1_qsv" results in LWLDECODER == "av1_qsv" and playback is smooth
My CPU does not support Intel Quick sync video. And I find it a bit strange why CUVID cannot also be selected for AV1.
Many thanks for the detailed information.
Edit:
My CPU has Quick sync but probably no AV1. Does Quick Sync have to be installed?
Edit2:
It's done. I will not use the iGPU
qyot27
6th March 2024, 20:08
Regardless, it was addressed in the issue over on Github (https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works/issues/57). You could try with that test build.
gispos
7th March 2024, 17:45
Regardless, it was addressed in the issue over on Github (https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works/issues/57). You could try with that test build.
The test version is very good. Thank you both qyot27 and Asd-g.
4K AV1 decode with audio and prefer_hw=3, ~100 fps, DirectShowSource just half ~50 fps.
FranceBB
8th March 2024, 15:30
Does some old version work without recreating the index file for this script?
Yes, the version before this one was working fine.
Effectively, it was checking whether there was an lwi file in the same directory as the file and if it was written with the same version of LWLibav.
If it was written with an older version, then it would recreate the lwi index, otherwise it would use the one it found.
In this new version, however, it recreates the lwi file every single time, not just with AVSPmod mod but also with ffmpeg and any other application.
For instance, in this very same unchanged script, we have two different command lines calling ffmpeg and it's recreating the index files both times:
video=LWLibavVideoSource("V:\fs0\clip.dir\HSM00342.mxf", cache=true)
ch12=LWLibavAudioSource("V:\fs0\clip.dir\HSM00342.mxf", stream_index=1, cache=true)
ch34=LWLibavAudioSource("V:\fs0\clip.dir\HSM00342.mxf", stream_index=2, cache=true)
ch56=LWLibavAudioSource("V:\fs0\clip.dir\HSM00342.mxf", stream_index=3, cache=true)
ch78=LWLibavAudioSource("V:\fs0\clip.dir\HSM00342.mxf", stream_index=4, cache=true)
audio=MergeChannels(ch12, ch34, ch56, ch78)
AudioDub(video, audio)
https://i.imgur.com/cDAGEIs.png
Setting cache=true doesn't affect it as it keeps recreating it anyway and it's set to true by default anyway even when it's left unspecified.
I tried with cachefile but it is still recreating it:
video=LWLibavVideoSource("V:\fs0\clip.dir\HSM00342.mxf", cache=true, cachefile="V:\fs0\clip.dir\HSM00342.mxf.lwi")
ch12=LWLibavAudioSource("V:\fs0\clip.dir\HSM00342.mxf", stream_index=1, cache=true, cachefile="V:\fs0\clip.dir\HSM00342.mxf.lwi")
ch34=LWLibavAudioSource("V:\fs0\clip.dir\HSM00342.mxf", stream_index=2, cache=true, cachefile="V:\fs0\clip.dir\HSM00342.mxf.lwi")
ch56=LWLibavAudioSource("V:\fs0\clip.dir\HSM00342.mxf", stream_index=3, cache=true, cachefile="V:\fs0\clip.dir\HSM00342.mxf.lwi")
ch78=LWLibavAudioSource("V:\fs0\clip.dir\HSM00342.mxf", stream_index=4, cache=true, cachefile="V:\fs0\clip.dir\HSM00342.mxf.lwi")
audio=MergeChannels(ch12, ch34, ch56, ch78)
AudioDub(video, audio)
Even changing the disk didn't change a thing:
video=LWLibavVideoSource("A:\Ingest\MEDIA\temp\HSM00342.mxf", cache=true, cachefile="A:\Ingest\MEDIA\temp\HSM00342.mxf.lwi")
ch12=LWLibavAudioSource("A:\Ingest\MEDIA\temp\HSM00342.mxf", stream_index=1, cache=true, cachefile="A:\Ingest\MEDIA\temp\HSM00342.mxf.lwi")
ch34=LWLibavAudioSource("A:\Ingest\MEDIA\temp\HSM00342.mxf", stream_index=2, cache=true, cachefile="A:\Ingest\MEDIA\temp\HSM00342.mxf.lwi")
ch56=LWLibavAudioSource("A:\Ingest\MEDIA\temp\HSM00342.mxf", stream_index=3, cache=true, cachefile="A:\Ingest\MEDIA\temp\HSM00342.mxf.lwi")
ch78=LWLibavAudioSource("A:\Ingest\MEDIA\temp\HSM00342.mxf", stream_index=4, cache=true, cachefile="A:\Ingest\MEDIA\temp\HSM00342.mxf.lwi")
audio=MergeChannels(ch12, ch34, ch56, ch78)
AudioDub(video, audio)
https://i.imgur.com/AyTTwCV.png
adding a simple:
tweak(sat=1.31, dither=true)
as an example, makes it recreate the .lwi
https://i.imgur.com/VmFmSsB.png
kedautinh12
8th March 2024, 17:07
Why you still don't create a new issue report to the home page? Asd-g reads messages from here rarely. If you want to fix faster, you need report to the home page better than here
FranceBB
8th March 2024, 17:25
Who says I didn't? :P https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works/issues/58
hello_hello
10th March 2024, 06:55
Nope, it was a pretty standard script:
and as soon as I uncommented a filter and re-run it, it started recreating the .lwi file again for a third time:
it's currently 7:46PM, so it literally just started, it will grow again until it reaches 13 MB and then if I change something in the script, it will start creating it again... O_O
Doesn't L-Smash only index the video when indexing video, but when indexing audio, it indexes both?
FFMS2 is the same, as far as I know.
This
LWLibavVideoSource(Source, cachefile=IndexFile)
should create a smaller index file than this
LWLibavAudioSource(Source, cachefile=IndexFile)
assuming the source contains audio.
So this would be slower
v = LWLibavVideoSource(Source, cachefile=IndexFile)
a = LWLibavAudioSource(Source, cachefile=IndexFile)
AudioDub(v, a)
than this
a = LWLibavAudioSource(Source, cachefile=IndexFile)
v = LWLibavVideoSource(Source, cachefile=IndexFile)
AudioDub(v, a)
I haven't messed around with a file containing multiple audio streams myself, but what happens if you open the audio streams in reverse order, or you use the index file as the source? Unless that ability was removed at some stage, although it's working fine for r1164, which I think I'm using, at least for a file with a single audio stream.
LWLibavAudioSource(Source, cachefile=IndexFile)
a = LWLibavAudioSource(IndexFile)
v = LWLibavVideoSource(IndexFile)
AudioDub(v, a)
That's why I sometimes I use L-Smash in preference to FFMS2. You can batch index a bunch of files and open the index files directly later, without them having to be in the same folder as the source, much like indexing with DGIndex and then using the d2v file as the input for MPEG2Source. It was handy when I used to use MeGUI regularly, as it can run a batch of indexing jobs, and it understands lwi files can be used as the source.
FranceBB
11th March 2024, 08:43
Bug acknowledged and fixed by asd-g.
Check this commit: https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works/commit/8927ea9e7d3375b057d7810d4c790ff926986e22
Test build: https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works/files/14545956/LSMASHSource_1177.zip
As always asd-g is amazing, he's always very committed in getting things to work and replies immediately.
Kudos to him for keeping LWLibav alive and kickin.
leoenc
26th March 2024, 12:56
Linux newb here, trying to build this on Ubuntu 22.04 using the following commands:
git clone https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works
cd L-SMASH-Works/AviSynth/
mkdir build
meson . build/
ninja -C build
but compilation fails with errors about a missing lsmash.h file:
ninja: Entering directory `build/'
[1/21] Compiling C++ object liblsmashsource.so.p/libavsmash_source.cpp.o
FAILED: liblsmashsource.so.p/libavsmash_source.cpp.o
c++ -Iliblsmashsource.so.p -I. -I.. -I/usr/local/include/avisynth -I/home/leo/ffmpeg_build/include -fvisibility=hidden -fdiagnostics-color=always -DNDEBUG -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++14 -O3 -Wno-sign-compare -DXXH_INLINE_ALL -D_FILE_OFFSET_BITS=64 -mfpmath=sse -msse2 -fPIC -MD -MQ liblsmashsource.so.p/libavsmash_source.cpp.o -MF liblsmashsource.so.p/libavsmash_source.cpp.o.d -o liblsmashsource.so.p/libavsmash_source.cpp.o -c ../libavsmash_source.cpp
../libavsmash_source.cpp:29:10: fatal error: lsmash.h: No such file or directory
Any help appreciated.
qyot27
26th March 2024, 14:26
You have to build and install L-SMASH first. Which itself requires obuparse.
https://github.com/dwbuiten/obuparse
↓
https://github.com/vimeo/l-smash
↓
https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works
leoenc
26th March 2024, 16:05
@qyot27 thanks, I've built and installed obuparse and l-smash as you instructed and now getting the following error:
[21/21] Linking target liblsmashsource.so
FAILED: liblsmashsource.so
c++ -o liblsmashsource.so liblsmashsource.so.p/audio_output.cpp.o liblsmashsource.so.p/libavsmash_source.cpp.o liblsmashsource.so.p/lsmashsource.cpp.o liblsmashsource.so.p/lwlibav_source.cpp.o liblsmashsource.so.p/video_output.cpp.o liblsmashsource.so.p/.._common_audio_output.c.o liblsmashsource.so.p/.._common_decode.c.o liblsmashsource.so.p/.._common_libavsmash.c.o liblsmashsource.so.p/.._common_libavsmash_audio.c.o liblsmashsource.so.p/.._common_libavsmash_video.c.o liblsmashsource.so.p/.._common_lwindex.c.o liblsmashsource.so.p/.._common_lwlibav_audio.c.o liblsmashsource.so.p/.._common_lwlibav_dec.c.o liblsmashsource.so.p/.._common_lwlibav_video.c.o liblsmashsource.so.p/.._common_lwsimd.c.o liblsmashsource.so.p/.._common_osdep.c.o liblsmashsource.so.p/.._common_qsv.c.o liblsmashsource.so.p/.._common_resample.c.o liblsmashsource.so.p/.._common_utils.c.o liblsmashsource.so.p/.._common_video_output.c.o -Wl,--as-needed -Wl,--allow-shlib-undefined -Wl,-O1 -shared -fPIC -Wl,-rpath,/usr/local/lib -Wl,-rpath-link,/usr/local/lib -Wl,--start-group /usr/local/lib/liblsmash.a -lm /usr/local/lib/libobuparse.so /home/leo/ffmpeg_build/lib/libavcodec.a -pthread /usr/lib/gcc/x86_64-linux-gnu/11/libatomic.so /home/leo/ffmpeg_build/lib/libfdk-aac.a /home/leo/ffmpeg_build/lib/libx264.a -lpthread -ldl /home/leo/ffmpeg_build/lib/libx265.a /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.so /usr/lib/gcc/x86_64-linux-gnu/11/libgcc_s.so /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a -lrt /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libnuma.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libz.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libva.so /home/leo/ffmpeg_build/lib/libswresample.a /home/leo/ffmpeg_build/lib/libavutil.a /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libva-drm.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libva-x11.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libvdpau.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libX11.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libdrm.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libxcb.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libXau.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libXdmcp.so /home/leo/ffmpeg_build/lib/libavformat.a /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libgnutls.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libgmp.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libunistring.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libhogweed.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libnettle.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libtasn1.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libidn2.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libp11-kit.so /home/leo/ffmpeg_build/lib/libswscale.a -Wl,--end-group
/usr/bin/ld: /usr/local/lib/liblsmash.a(box.o): warning: relocation against `isom_fiel_box_default' in read-only section `.text'
/usr/bin/ld: /home/leo/ffmpeg_build/lib/libavcodec.a(vc1dsp_mmx.o): relocation R_X86_64_PC32 against symbol `ff_pw_9' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Any ideas?
qyot27
26th March 2024, 16:09
I figured that was going to be the next error. Linking static libraries (read: ffmpeg in a custom prefix, since most guides that do that build it as static) into a shared library (liblsmashsource) requires adding -Wl,-Bsymbolic to the LDFLAGS of the shared library when you configure it.
PKG_CONFIG_PATH=$HOME/ffmpeg_build/lib/pkgconfig LDFLAGS=-Wl,-Bsymbolic meson setup <build options>
leoenc
26th March 2024, 16:34
@qyot27 I'm probably missing something as I ran the following and got the same error:
git clone https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works
cd L-SMASH-Works/AviSynth/
mkdir build
PKG_CONFIG_PATH=$HOME/ffmpeg_build/lib/pkgconfig LDFLAGS=-Wl,-Bsymbolic meson setup . build
ninja -C build/
qyot27
26th March 2024, 17:59
NVIDIA users:
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
sudo checkinstall --pkgname=nv-codec-headers --pkgversion="0:$(git rev-list --count HEAD)-g$(git rev-parse --short HEAD)" --backup=no --deldoc=yes --delspec=yes --deldesc=yes --strip=yes --fstrans=no --default
Intel users:
sudo apt-get install libvpl-dev
AV1 software decoding with libdav1d:
sudo apt-get install libdav1d-dev
FFmpeg-minimal:
Use --enable-libdav1d for AV1 software decoding
Use --enable-vpl to enable QSV hardware decoders
FFmpeg autodetects the nv-codec-headers, so the nvdec decoders should be automatically enabled
git clone https://git.videolan.org/git/ffmpeg.git
mkdir -p ffmpeg/ffmpeg-build
cd ffmpeg/ffmpeg-build
../configure --prefix=$HOME/ffmpeg_build_minimal \
--enable-gpl --enable-version3 --disable-encoders \
--disable-muxers --disable-doc --disable-debug --enable-libdav1d \
--enable-libvpl --cpu=native --extra-cflags="-march=native" && \
make -j$(nproc) && \
make install
obuparse:
git clone https://github.com/dwbuiten/obuparse.git && \
cd obuparse && \
make && \
sudo make install
The install step might throw an error if the symlink to libobuparse.so already exists; that can be safely ignored.
l-smash:
git clone https://github.com/vimeo/l-smash.git
cd l-smash
./configure --extra-cflags="-march=native -fPIC" && \
make -j$(nproc) && \
sudo checkinstall --pkgname=lsmash --pkgversion="0:$(git rev-list --count HEAD)-g$(git rev-parse --short HEAD)" --backup=no --deldoc=yes --delspec=yes --deldesc=yes --strip=yes --fstrans=no --default
LSMASHSource:
git clone https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works.git && \
mkdir -p L-SMASH-Works/AviSynth/build && \
cd L-SMASH-Works/AviSynth/build && \
PKG_CONFIG_PATH=$HOME/ffmpeg_build_minimal/lib/pkgconfig LDFLAGS="-Wl,-Bsymbolic" meson setup .. && \
ninja && \
sudo checkinstall --pkgname=lsmashsource --pkgversion="1:$(git rev-list --count HEAD)-g$(git rev-parse --short HEAD)" --backup=no --deldoc=yes --delspec=yes --deldesc=yes --strip=yes --stripso=yes --addso=yes --fstrans=no --default ninja install
(Alternatively, instead of installing it to the system, just copy liblsmashsource.so to either ~/.avisynth or ~/.local/lib/avisynth)
leoenc
26th March 2024, 19:24
Working great now, thanks!
LigH
28th March 2024, 09:16
I found a WMV which I want to convert, and in my experience, L-SMASH Works does that quite well, in general; but in this case I noticed that the audio gets async at the end of the clip. I can't check easily how much it is in the beginning, as there is only music, the interview starts after about 40 minutes, and here it is clearly out of sync in the Avisynth script. But when I play the WMV in a media player (MPC-HC with LAV Filters or ffplay), it is nicely in sync.
I wonder if the file is a result of concatenated smaller clips with originally audio streams exceeding the video streams, which are still contained in the resulting file, so an Avisynth source filter decodes them linearly, but they get skipped (or missing frames frozen) when a media player syncs to timestamps ... if that is even possible with this container.
I'll try to circumvent that for my conversion (e.g. remux to WMV with ffmpeg; remux to MKV with ffmpeg or mkvtoolnix; use DSS), yet I stay curious what might cause this difference.
Or are there possibly parameters for LwLibav(Video/Audio)Source I should test?
Music Fan
28th March 2024, 09:46
Could this wmv have been encoded in VFR mode ? Which might cause the async.
LigH
28th March 2024, 09:56
MediaInfo reports VFR mode, but that is only related to the multiplexing format. I doubt that the frame actually varies. But I am not sure how to test that with certainty.
Music Fan
28th March 2024, 10:41
I haven't done it for years but you can try directshowsource with convertfps=false. You should see directly if the number of frames is still the same (which does not mean that the sync will be perfect but maybe better).
LigH
28th March 2024, 13:08
It is indeed. Just by a few hundred frames, but the result is in sync late.
LSMASHVideoSource("input.mp4",fpsnum=60000,fpsden=1001)
should it give me a video file with fps 59.94 and normal length? It turns my 23s file into 6h :)
LSMASHVideoSource("input.mp4").ChangeFPS(59.94) works ok.
Selur
4th April 2024, 04:44
@rgr: you might want your source, since that does seem to work fine here.
tebasuna51
4th April 2024, 16:20
WARNING: in the last (LSMASHSource.dll 2024/04/02) LSMASHAudioSource is broken (https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works/issues/63) (wrong channels and decode), use always LWLibavAudioSource than seems work fine.
tebasuna51
8th April 2024, 08:47
v1194 seems work now with wav files.
BTW LSMASHAudioSource don't work for all raw audio, for instance raw eac3 or aac can't be read. Use only for "MP4, MOV, [ISO Base Media] and its derived file formats."
Use always LWLibavAudioSource to decode audio.
rgr
10th April 2024, 11:43
@rgr: you might want your source, since that does seem to work fine here.
??? I don't understand.
rgr
10th April 2024, 14:02
Should I have double indexing?
Creating lwi index file 100%
Creating lwi index file 12%
v=LWLibavVideoSource("test.mp4",fpsnum=50)
AudioDub(v, LWLibavAudioSource("test.mp4"))
Selur
11th April 2024, 04:26
you might want your source, since that does seem to work fine here
=>
you might want to share your source, since that does seem to work fine here
FranceBB
11th April 2024, 06:47
Yes, if you index the video and then the audio, first it does the video, then it does the audio, hence you see two lines.
If you look at the lwi file, it gets bigger as it gets updated.
Once it's done, it won't index it again. :)
By the way, if you wanna see instances in which it may index things twice by mistake (not this case) you can just stare at the lwi index. If it gets overwritten and shrinks in size before raising again then something is wrong, but if it just grows then everything is fine.
In this case I'm sure it just grows as you're indexing the audio too, so everything is fine. ;)
Emulgator
11th April 2024, 08:28
I am developing a snippet to automate audio decoding across a choice of audio decoders, here to control DRC (lower, deactivate/discard, invert) for decoding purposes.
Test source is a BD .m2ts with Track 1: 2.0 .ac3 + Track 2: 5.1 .dts.
Manually giving "5.1"or "0x3f" or "FL+FR+FC+LFE+SL+SR" decodes nicely, but I need to leave the channel layout default to LWLibavAudioSource, because the script can not know whats inside the source.
"Apply" needs to hand over all parameters up to the wanted one (drc_scale) in sequence. All the other parameters seem to work, so I can hand these over.
Now layout is parsed before drc_scale, so I am searching for the LWLibavAudioSource default layout parameter to hand this over too.
The 1194 readme says "", but this won't give any audio. "-1" does not and "0" does not and "0x0" does not help either. (BTW, bool indexingpr = true is missing in readme example line, but listed in explanations.)
#...we assume last() containing video already
audsrc="LWLibavAudioSource" #Asd-g versions only, here 1194
Libavaudtrk=2 #int stream_index = -1 #-1: default stream
Libavaudcache=true #bool cache = true
Libavaudcachefile=String(audfolder)+String(audfile)+String(audpid)+String(audext)+".lwi"#string cachefile = source +".lwi"
Libavaudavsync=false #bool av_sync = false
Libavaudlayout=""#"5.1"#"0x3f"#"FL+FR+FC+LFE+SL+SR" #string layout = "" | CN ? No Audio | 5.1 -> "5.1" or "FL+FR+FC+LFE+SL+SR" or "0x3f"
Libavaudrate=0 #int rate = 0
Libavauddecoder="" #string decoder = ""
Libavaudffloglevel=0 #int ff_loglevel = 0
Libavaudcachedir="" #string cachedir = ""
Libavindexingpr=true #bool indexingpr = true
Libavauddrcscale=0.0 #float drc_scale = 1.0 #0.0 deactivates DRC, -values invert the DRC processing
Libavaudffopts="" #string ff_options = ""
Exist(String(avfolder)+String(avfile0)+String(avext0)) ? Apply(vidsrc,String(avfolder)+String(avfile0)+String(avext0))\
: Assert(false, "! NO SUCH AV FILE -> " + String(avfolder)+String(avfile0)+String(avext0) + "<- NO SUCH AV FILE !")
try {AudioDub(last,Apply(audsrc,String(audfolder)+String(audfile)+String(audpid)+String(audext),Libavaudtrk,Libavaudcache,Libavaudcachefile,Libavaudavsync,Libavaudlayout,Libavaudrate,Libavauddecoder,Libavaudffloglevel,Libavaudcachedir,Libavindexingpr,Libavauddrcscale,Libavaudffopts))}
catch (err) {last}
If I comment the try/catch lines out and run only
AudioDub(last,Apply(audsrc,String(audfolder)+String(audfile)+String(audpid)+String(audext),Libavaudtrk,Libavaudcache,Libavaudcachefile,Libavaudavsync,Libavaudlayout,Libavaudrate,Libavauddecoder,Libavaudffloglevel,Libavaudcachedir,Libavindexingpr,Libavauddrcscale,Libavaudffopts))
I get: "LWLibavAudioSource: Failed to open resampler."
Asd-g, what do I have to pass as default here ? Or is it a bug ?
rgr
11th April 2024, 10:55
=>
you might want to share your source, since that does seem to work fine here
Yes of course. But it's private, so I can only send it to the plugin author.
rgr
11th April 2024, 10:57
Yes, if you index the video and then the audio, first it does the video, then it does the audio, hence you see two lines.
If you look at the lwi file, it gets bigger as it gets updated.
Once it's done, it won't index it again. :)
Thanks.
So it would be good to introduce the "LWLibavSource" command like ffms2 or BS :)
hello_hello
12th April 2024, 16:52
Thanks.
So it would be good to introduce the "LWLibavSource" command like ffms2 or BS :)
I've been meaning to update this function for a long time, probably years, so it'll work with the latest L-SMASH Source.
I've only given it a quick check. It should be fine, but let me know if you find any issues.
# ===============================================================================
# LibavSource2
# ===============================================================================
#
# Similar to the original LibavSource2, but audio is enabled by default.
# Both video and audio can be disabled.
# Audio-only and video-only files can be opened without first having to
# disable the audio or video accordingly to prevent an error message.
#
# ===============================================================================
function LibavSource2(string Source, int "VTrack", int "ATrack", 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 "VDecoder", string "ADecoder", int "Prefer_HW", int "FF_LogLevel", \
string "CacheDir", string "FF_Options", bool "AV_Sync", string "Layout", int "Rate") {
VTrack = default(VTrack, -1)
ATrack = default(ATrack, -1)
Threads = default(Threads, 0)
Cache = default(Cache, true)
CacheFile = default(CacheFile, Source + ".lwi")
Seek_Mode = default(Seek_Mode, 0)
Seek_Threshold = default(Seek_Threshold, 10)
DR = default(DR, false)
FPSNum = default(FPSNum, 0)
FPSDen = default(FPSDen, 1)
Repeat = default(Repeat, false)
Dominance = default(Dominance, 0)
Format = default(Format, "")
VDecoder = default(VDecoder, "")
ADecoder = default(ADecoder, "")
Prefer_HW = default(Prefer_HW, 0)
FF_LogLevel = default(FF_LogLevel, 0)
CacheDir = default(CacheDir, "")
FF_Options = default(FF_Options, "")
AV_Sync = default(AV_Sync, false)
VideoEnabled = (VTrack > -2)
AudioEnabled = (ATrack > -2)
VideoNotFound = false
AudioNotFound = false
IsVideo = false
IsAudio = false
LS2 = " LibavSource2 " + chr(10)
VideoError = ""
AudioError = ""
assert(VideoEnabled || AudioEnabled, LS2 + " Both video and audio are disabled " + chr(10))
# -------------------------------------------------------------------------------
AudioEnabled ? Eval("""
try{
Audio = LWLibavAudioSource(Source, stream_index=ATrack, \
cache=Cache, cachefile=CacheFile, av_sync=AV_Sync, layout=Layout, rate=Rate, \
decoder=ADecoder, ff_loglevel=FF_LogLevel, cachedir=CacheDir, ff_options=FF_Options)
IsAudio = true
}catch(err_msg){
AudioError = " LWLibavAudioSource " + chr(10) + " " + err_msg + " " + chr(10)
AudioNotFound = (FindStr(LCase(err_msg), "failed to get the audio track") > 0)
NotAudio = (FindStr(LCase(err_msg), "not an audio track") > 0)
assert(!NotAudio, LS2 + " The specified audio track is not an audio track " + chr(10))
assert(AudioNotFound || NotAudio, AudioError)
} """) : nop()
# -------------------------------------------------------------------------------
VideoEnabled ? Eval("""
try{
Video = LWLibavVideoSource(Source, stream_index=VTrack, threads=Threads, \
cache=Cache, cachefile=CacheFile, seek_mode=Seek_Mode, seek_threshold=Seek_Threshold, dr=DR, \
fpsnum=FPSNum, fpsden=FPSDen, repeat=Repeat, dominance=Dominance, format=Format, decoder=VDecoder, \
prefer_hw=Prefer_HW, ff_loglevel=FF_LogLevel, cachedir=CacheDir, ff_options=FF_Options)
IsVideo = true
}catch(err_msg){
VideoError = " LWLibavVideoSource " + chr(10) + " " + err_msg + " " + chr(10)
VideoNotFound = (FindStr(LCase(err_msg), "failed to get the video track") > 0)
NotVideo = (FindStr(LCase(err_msg), "not a video track") > 0)
assert(!NotVideo, LS2 + " The specified video track is not a video track " + chr(10))
assert(VideoNotFound || NotVideo, VideoError)
} """) : nop()
# -------------------------------------------------------------------------------
assert(!VideoNotFound || AudioEnabled, LS2 + " No video found & audio is disabled " + chr(10))
assert(!AudioNotFound || VideoEnabled, LS2 + " No audio found & video is disabled " + chr(10))
IsAudio = AudioEnabled && IsAudio
IsVideo = VideoEnabled && IsVideo
return IsAudio && IsVideo ? AudioDub(Video, Audio) : IsAudio ? Audio : Video }
# ===============================================================================
Edit: LSMASHSource2 version. Tested even less.
# ===============================================================================
# LSMASHSource2
# ===============================================================================
#
# Similar to the original LSMASHSource2, but audio is enabled by default.
# Both video and audio can be disabled.
# Audio-only and video-only files can be opened without first having to
# disable the audio or video accordingly to prevent an error message.
#
# ===============================================================================
function LSMASHSource2(string Source, int "VTrack", int "ATrack", int "Threads", \
int "Seek_Mode", int "Seek_Threshold", bool "DR", int "FPSNum", int "FPSDen", \
string "Format", string "VDecoder", string "ADecoder", int "Prefer_HW", \
int "FF_LogLevel", string "FF_Options", bool "Skip_Priming", string "Layout", int "Rate") {
VTrack = default(VTrack, -1)
VTrack = (VTrack == -1) ? 0 : VTrack
ATrack = default(ATrack, -1)
ATrack = (ATrack == -1) ? 0 : ATrack
Threads = default(Threads, 0)
Seek_Mode = default(Seek_Mode, 0)
Seek_Threshold = default(Seek_Threshold, 10)
DR = default(DR, false)
FPSNum = default(FPSNum, 0)
FPSDen = default(FPSDen, 1)
Format = default(Format, "")
VDecoder = default(VDecoder, "")
ADecoder = default(ADecoder, "")
Prefer_HW = default(Prefer_HW, 0)
FF_LogLevel = default(FF_LogLevel, 0)
FF_Options = default(FF_Options, "")
Skip_Priming = default(Skip_Priming, true)
VideoEnabled = (VTrack > -2)
AudioEnabled = (ATrack > -2)
VideoNotFound = false
AudioNotFound = false
IsVideo = false
IsAudio = false
LS2 = " LSMASHSource2 " + chr(10)
VideoError = ""
AudioError = ""
assert(VideoEnabled || AudioEnabled, LS2 + " Both video and audio are disabled " + chr(10))
# -------------------------------------------------------------------------------
AudioEnabled ? Eval("""
try{
Audio = LSMASHAudioSource(Source, track=ATrack, skip_priming=Skip_Priming, \
layout=Layout, rate=Rate, decoder=ADecoder, ff_loglevel=FF_LogLevel, ff_options=FF_Options)
IsAudio = true
}catch(err_msg){
AudioError = " LSMASHAudioSource " + chr(10) + " " + err_msg + " " + chr(10)
AudioNotFound = (FindStr(LCase(err_msg), "failed to find audio track") > 0)
NotAudio = (FindStr(LCase(err_msg), "not an audio track") > 0)
assert(!NotAudio, LS2 + " The specified audio track is not an audio track " + chr(10))
assert(AudioNotFound || NotAudio, AudioError)
} """) : nop()
# -------------------------------------------------------------------------------
VideoEnabled ? Eval("""
try{
Video = LSMASHVideoSource(Source, track=VTrack, threads=Threads, seek_mode=Seek_Mode, \
seek_threshold=Seek_Threshold, dr=DR, fpsnum=FPSNum, fpsden=FPSDen, format=Format, \
decoder=VDecoder, prefer_hw=Prefer_HW, ff_loglevel=FF_LogLevel, ff_options=FF_Options)
IsVideo = true
}catch(err_msg){
VideoError = " LSMASHVideoSource " + chr(10) + " " + err_msg + " " + chr(10)
VideoNotFound = (FindStr(LCase(err_msg), "failed to find video track") > 0)
NotVideo = (FindStr(LCase(err_msg), "not a video track") > 0)
assert(!NotVideo, LS2 + " The specified video track is not a video track " + chr(10))
assert(VideoNotFound || NotVideo, VideoError)
} """) : nop()
# -------------------------------------------------------------------------------
assert(!VideoNotFound || AudioEnabled, LS2 + " No video found & audio is disabled " + chr(10))
assert(!AudioNotFound || VideoEnabled, LS2 + " No audio found & video is disabled " + chr(10))
IsAudio = AudioEnabled && IsAudio
IsVideo = VideoEnabled && IsVideo
return IsAudio && IsVideo ? AudioDub(Video, Audio) : IsAudio ? Audio : Video }
# ===============================================================================
flossy_cake
30th April 2024, 15:47
I noticed there is an ff_options argument... is it possible to specify an audio track language with it? Something like...
LWLibavAudioSource(file, ff_options="map=0:a:m:language:eng")
tebasuna51
1st May 2024, 00:30
...is it possible to specify an audio track language with it?
Inside AviSynth the audio can't have a property like language.
Your ffmpeg parameter is for a container like mkv, not for an uncompresed audio file like LWLibavAudioSource output.
flossy_cake
1st May 2024, 18:46
Your ffmpeg parameter is for a container like mkv, not for an uncompresed audio file like LWLibavAudioSource output.
Yep so in this case the first argument "file" points to an mkv file.
tebasuna51
1st May 2024, 19:33
Yep so in this case the first argument "file" points to an mkv file.
No mather the input file the LWLibavAudioSource output is uncompressed audio without a language property, and specify the language is usseless to select the track inside the mkv.
flossy_cake
1st May 2024, 21:44
No mather the input file the LWLibavAudioSource output is uncompressed audio without a language property, and specify the language is usseless to select the track inside the mkv.
I think there is a misunderstanding here - I was trying to tell LWLibavAudioSource to select the audio track to decode based on language instead of track number (stream_index). As far as I can tell the ff_options argument allows us to set some decoder settings which could potentially include language.
The reason I want to do this is because I have a large number of files in a series where the english track number changes from file to file and it's a pain to have to check them all manually one by one to set stream_index to the right number for each one.
I'm currently reducing the workload of this task by using a custom MediaInfo view so that it prints out the english track number of all files at a glance and then manually tagging the file names with [audio_track=n] and then inside my script if(FindStr(sourcefile, "[audio_track=n]" != 0)) setting stream_index based on the result of that.
qyot27
1st May 2024, 22:38
It would have been easier to just point at the documentation (https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works/blob/master/AviSynth/README.md):
+ ff_options (default : "")
Set the decoder options in FFmpeg.
The format is `key=value` separated by " ". (e.g. "drc_scale=0 auto_convert=0")
-map is not a decoder option, so therefore no, it won't work. The examples even show this, drc_scale is an option specific to only certain decoders (like ac3, but not aac, for example), when you call up the options list with ffmpeg -h decoder=<format-name>.
For clarity, I would suggest that ff_options be renamed to ff_decoder_options to make that explicit (especially since it would be theoretically possible to have ff_demuxer_options as well, unless the two are already rolled into ff_options and the documentation just doesn't explain that).
Music Fan
2nd May 2024, 14:03
The reason I want to do this is because I have a large number of files in a series where the english track number changes from file to file and it's a pain to have to check them all manually one by one to set stream_index to the right number for each one.
You could also remux all your files with ffmpeg keeping only the english track*, then re-encode them.
* with this :
-map 0:a:m:language:en: -c:a copy
flossy_cake
3rd May 2024, 17:58
You could also remux all your files with ffmpeg keeping only the english track*, then re-encode them.
* with this :
-map 0:a:m:language:en: -c:a copy
Thanks and yes I know and I was gonna do it in mkvtoolnix as well because I get better media player compatibility than ffmpeg but in the end it was a lot of work and was faster to just tag the files and I was also a bit worried remuxing might affect the audio sync somehow so I just didn't want potential trouble over such a large number of files.
rgr
22nd August 2024, 18:30
Has anyone managed to play an AVI file (from a miniDV camera) using LWLibavVideoSource? VirtualDub crashes right away, and ffmpeg doesn't work either.
name1="Greenwich, London (16.02.2007 12.53).avi"
a=LWLibavAudioSource(name1)
a=AudioDub(LWLibavVideoSource(name1), a)
a
(I had ffms2 in the script before and it worked OK.)
LigH
22nd August 2024, 18:36
Please check a verbose MediaInfo report, especially in which style the audio track is multiplexed. DV video supports two types, one "inside" the video stream, the other in parallel, IIRC.
rgr
23rd August 2024, 14:01
Please check a verbose MediaInfo report, especially in which style the audio track is multiplexed. DV video supports two types, one "inside" the video stream, the other in parallel, IIRC.
General
Format : AVI
Format/Info : Audio Video Interleave
Commercial name : DV
Format profile : OpenDML
Format settings : BitmapInfoHeader / WaveFormatEx
File size : 11.1 GiB
Duration : 52 min 59 s
Overall bit rate mode : Constant
Overall bit rate : 29.9 Mb/s
Frame rate : 25.000 FPS
Recorded date : 2007-02-18 15:42:25.000
TCOD : 400000
TCDO : 31797600000
VMAJ : 4
VMIN : 0
STAT : 79493 0 3.073964 1
DTIM : 29839817 1786375168
Video
ID : 0
Format : DV
Codec ID : dvsd
Codec ID/Hint : Sony
Duration : 52 min 59 s
Bit rate mode : Constant
Bit rate : 24.4 Mb/s
Width : 720 pixels
Height : 576 pixels
Display aspect ratio : 4:3
Frame rate mode : Constant
Frame rate : 25.000 FPS
Standard : PAL
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Interlaced
Scan order : Bottom Field First
Compression mode : Lossy
Bits/(Pixel*Frame) : 2.357
Time code of first frame : 00:52:05:17
Time code source : Subcode time code
Stream size : 10.7 GiB (96%)
Encoding settings : wb mode= / white balance= / fcm=auto focus
Audio
ID : 1
Format : PCM
Format settings : Little / Signed
Codec ID : 1
Duration : 52 min 59 s
Bit rate mode : Constant
Bit rate : 1 024 kb/s
Channel(s) : 2 channels
Sampling rate : 32.0 kHz
Bit depth : 16 bits
Stream size : 388 MiB (3%)
Alignment : Aligned on interleaves
Interleave, duration : 280 ms (7.00 video frames)
Interleave, preload duration : 280 ms
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.