Log in

View Full Version : Odd and random bug with Avisynth (2.58, 2.60, AVS+)


resle
27th January 2018, 08:26
Running software-generated scripts, that look like this...


function CreateTrack(float duration, float afps)
{
duration = Round(duration)
return ResampleAudio(ConvertToMono(BlankClip(duration, fps=afps)),44100)
}


function GetAudio(string file, float duration, float afps)
{
duration = Round(duration)
result = BlankClip(duration, fps=afps)
result = AudioDub(result, DirectShowSource(file))
return ResampleAudio(ConvertToMono(result),44100)
}


function Attach(clip channel, int point, float whole, string file, float duration, float afps)
{
channel = channel.Trim(0, point) + GetAudio(file, duration, afps)
temp = CreateTrack(whole, afps)
return AudioDub(temp, channel)
}


video = ImageSource("S:\temp\render\%05d.png", 0, 3721, 24, true)
audio = CreateTrack(3720, 24)

music = CreateTrack(3720, 24)
fx = CreateTrack(3720, 24)
speech = CreateTrack(3720, 24)

speech = Attach(speech,Round(120),3720,"d:\\000.WAV",48,24)
speech = Attach(speech,Round(216),3720,"d:\\001.WAV",72,24)
speech = Attach(speech,Round(336),3720,"d:\\002.WAV",72,24)

audio = MixAudio(audio, speech, 0.00, 1.00)
audio = MixAudio(audio, fx, 0.50, 0.50)
audio = MixAudio(audio, music, 0.50, 0.50)

return AudioDub(video, audio)


...and passing the output to FFMpeg for x264/aac encoding.

These scripts are generated by custom-made animation software, thousands of them, but all looking like the above.

The problem:
randomly, some of the audio files will be truncated.
If I encode the same video again, the same audio file might or might not be fine. It's entirely random.

WAV files are pcm/mono/44k
FFMpeg 64bit latest build
AVIsynth version: I tried 2.58, 2.60, AVS+ ... same issue
OS - Windows 10 64bit

Any hint? Anyone stumbled on the same problem in the past?

Thanks

jmartinr
27th January 2018, 16:00
You're using directshowsource for the audio. That's often not the most reliable way to do that. Try a different source filter. FFmpegSource or something like that.

resle
28th January 2018, 04:54
You're using directshowsource for the audio. That's often not the most reliable way to do that. Try a different source filter. FFmpegSource or something like that.

Thanks a lot jmartinr!. It seems this solved the problem for good - moreover as an unexpected bonus, it appears the audio quality has perceivably improved.

Doom9 forums saves the day once again :)

manolito
28th January 2018, 16:08
To me this sounds like the real culprit must have been not DirectShowSource per se, but that the Microsoft DS audio source filter was to blame.

I would be curious what happens if you installed the latest LAV Filters and then make sure (with the help of the DirectShow Filter tweaking tool) that the LAV source filters are really get used. I have never experienced problems with this configuration, and I prefer it over FFmpegSource for audio because it does not require indexing which makes it much faster.


Cheers
manolito

resle
29th January 2018, 01:24
To me this sounds like the real culprit must have been not DirectShowSource per se, but that the Microsoft DS audio source filter was to blame.

I would be curious what happens if you installed the latest LAV Filters and then make sure (with the help of the DirectShow Filter tweaking tool) that the LAV source filters are really get used. I have never experienced problems with this configuration, and I prefer it over FFmpegSource for audio because it does not require indexing which makes it much faster.


Cheers
manolito

Manolito, I had the LAV filters from K-Lite 13.7.7, and tweaked already, so I would tend to exclude that.

I ended up using LSMASHSource rather than FFmpegSource, but both gave me the same results in terms of speed. Actually both LSMASH and FFmpeg seem to be slightly faster than Directshow (a couple frames per second, nothing big).

What's the thing with Indexing? I am not well educated on the subject.

manolito
29th January 2018, 14:28
moreover as an unexpected bonus, it appears the audio quality has perceivably improved.

This is what really puzzles me. DirectShowSource does have problems while seeking because it is not frame accurate. But degraded audio quality? Never heard of this.

Maybe it is something with Win10 or your filter settings?


For indexing this is from the ffms2 manual:
## Indexing and You

Before FFMS2 can open a file, it must be indexed first so that keyframe/sample positions are known and seeking is easily accomplished.
This is done automatically when using `FFVideoSource()` or `FFAudioSource()`,
but if you want to you can invoke the indexing yourself by calling `FFIndex()`, or by running `ffmsindex.exe`.
By default the index is written to a file so it can be reused the next time you open the same file, but this behavior can be turned off if desired.

If you wonder why FFMS2 takes so long opening files, the indexing is the answer.
If you want a progress report on the indexing, you can use the supplied `ffmsindex.exe` commandline program.


Cheers
manolito

resle
30th January 2018, 04:02
This is what really puzzles me. DirectShowSource does have problems while seeking because it is not frame accurate. But degraded audio quality? Never heard of this.


No, it wasn't "degraded audio quality": it was audio files ending abruptly, and randomly so. Sometimes it would encode correctly, sometimes some of the audio files would be truncated.