Log in

View Full Version : Audiotrack shorter than video if opened by AVISynth


belonesox
5th April 2015, 13:52
Hello!

I have problem with a lots of my video:
then AVISource of DirectShowSource opens it,
audiotrack is shorter (≈2-3%) than video track.

Sample file: https://cloud.mail.ru/public/79c5f77561b7/avisynth-bug-with-audio-length-demo.zip (280MB)

WTF?

I tried last versions of AVISynth
(AVS 2.6.0 RC 1 [150114], AVS 2.6.0 Alpha 5 [130918]) — same problem.

creaothceann
5th April 2015, 15:05
11,142,708 audio samples returned by AVISource
11,374,848 audio samples returned by DSS
Difference: 232,140 @48000Hz = 4.84s

VirtualDub detected a variable-bitrate MP3 in the .avi file and produced a warning. If you don't want to use a different file format (e.g. .mkv) then you shouldn't use AVISource (better: DSS2).

StainlessS
5th April 2015, 16:22
Dont think DSS2 supports audio at all, so fail to see why that could improve matters.

Suggest Full Processing Audio mode in VD and render to Lossless AVI (or Video Direct Stream Copy)

or

something.bat to re-encode to utvideo or change "utvideo" to "huffyuv" for HuffYUV.

setlocal

REM Where to Find ffmpeg
set FFMPEG="C:\BIN\ffmpeg.exe"

REM Where to get input file, No terminating Backslash, "." = current directory (ie same as dir .bat file)
set INDIR="."


REM Where to place output file, No terminating Backslash. "." would be same as .bat file
set OUTDIR="D:\AVS\AVI"


FOR %%A IN (*.wmv *.mpg *.avi *.flv *.mov *.mp4 *.m4v *.RAM *.RM *.mkv *.TS *.y4m *.yuv) DO (
%FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"

)

Pause


Without re-encode video (copy original ie Direct Stream Copy) to OUTPUT dir in same dir as bat file

setlocal

REM Where to Find ffmpeg
set FFMPEG="C:\BIN\ffmpeg.exe"

REM Where to get input file, No terminating Backslash, "." = current directory
set INDIR="."


REM Where to place output file, No terminating Backslash.
set OUTDIR=".\OUTPUT"


FOR %%A IN (*.wmv *.mpg *.avi *.flv *.mov *.mp4 *.m4v *.RAM *.RM) DO (
%FFMPEG% -i "%INDIR%\%%A" -vcodec copy -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"

)

Pause

Ooops, 2nd bat file changed utvideo to 'copy' (of course need decoder that can eg decode mpg or whatever is put into avi)
The above given input extension list is just what was in already existing re-encode to avi batcher.

EDIT: Can add to OR remove input file extensions. Bat's Will process all files matching input extensions in INDIR.

belonesox
6th April 2015, 10:53
Thanks all for answers!

Actually, the problem is not about these videos, but with my workflow (I use myown framework over AVISynth https://abf.io/belonesox/seminar-assembler which works with videos in a "functional" way and process with it thousands of videos), and I would know — this is well known bug which will not be fixed ("feature")?

Also I cannot understand how to fix constant bitrate audio with ffmpeg.

I have tried «-vcodec libx264 -b:v 48K -acodec libmp3lame -b:a 192K -preset medium »
andn «-vcodec libx264 -b:v 48K -acodec libfdk_aac -b:a 192K -preset medium » and still get video with VBR audio.

burfadel
6th April 2015, 11:15
Maybe because it is using 2-pass average bitrate? Constant bitrate for video and audio is very much a bad thing except if explicitly streaming. The reason for this is in complex video scenes you will get crappy artifacting, and in audio you will get compression artifacts due to a too-constrained bitrate. With MP3 this is completely different to AAC, with AAC you lose audio fidelity. Basically with audio, bits are wasted on silent and low complexity areas.

Is there any specific reason why it must be constant bitrate? Are you using command line or a front end GUI (and if so, which one)?

sneaker_ger
6th April 2015, 17:09
I have tried «-vcodec libx264 -b:v 48K -acodec libmp3lame -b:a 192K -preset medium »
That will result in CBR audio, don't get confused by the VirtualDub error message.

Is there a reason you need to put H.264 into AVI and use AviSource()?

creaothceann
6th April 2015, 18:08
VBR is fine, just don't use it with the .avi file format.

belonesox
7th April 2015, 10:16
Constant bitrate for video and audio is very much a bad thing except if explicitly streaming

Actually I shot lectures, talks and seminars (https://vimeo.com/belonesox/albums) where is no "complex scenes" but mostly always has overlay with presentation screen, and constant bitrate good for preserving readability of screen.



That will result in CBR audio, don't get confused by the VirtualDub error message.

So when why AVISynth cuts audio track?



Is there a reason you need to put H.264 into AVI and use AviSource()?


Yes. Because I use AVISynth in my framework and in my workflow,
all "functional objects" are AVI clips that can be opened by AVISource (AVISource most accurate in frame positioning).
Every AVI clip can be transformed/processed without reencoding.
H264 — good known codec.

For audio, I must use MP3, because it is only codec (except WAV) that understand AVISource (AVISource cannot take AAC from ffmpeg, see old bug http://forum.doom9.org/showthread.php?t=168353 ).

So I need to know — can I make such AVI (with MP3) what AVISource can open without such problems.

Why not?

creaothceann
7th April 2015, 11:30
DSS2 is also quite frame-accurate, as far as I know.

f = "file.mkv"
v = DSS2(f)
a = DirectShowSource(f, video=false)
AudioDub(v, a)

Wilbert
7th April 2015, 22:07
@belonesox,

I don't have an answer to your question, and have no time to look at this issue coming days.

For audio, I must use MP3, because it is only codec (except WAV) that understand AVISource (AVISource cannot take AAC from ffmpeg
This is not true. You get that aac error because that guy is missing an acmac3 codec. It's perfectly fine to mux a mp2/mp3/ac3/dtc/aac into an avi (avimux can mux all those formats). I'm not saying that mp3 is a bad choice in your case, but you are not limited too it.

belonesox
13th April 2015, 12:41
DSS2 is also quite frame-accurate, as far as I know.


DSS2 is unsupported closed source plugin, , as far as I know. So I do not want to build my framework and workflow on it.


You get that aac error because that guy is missing an acmac3 codec


What codec? What guy?

Is it me, who posted the issue http://forum.doom9.org/showthread.php?t=168353

I of course have all codecs, but it you look at http://forum.doom9.org/showthread.php?t=168353 you see, that the problem between ffmpeg and AVISynth, about correct AAC-metainformation.

So, I just summarize.

There is no way to generate "casual AVI video with compressed audio" by fmpeg that can be correctly opened by AVISynth (without reencoding, remuxing and so on).
Because,
* if ffmpeg use MP3 coding — AVIsynth with AVISource cuts 2-3% of audio tail.
* if ffmpeg use AAC coding — AVISynth with AVISource faild to open it because nobody (ffmpeg team and AVS team could not take responsibility for that).
* AVISynth with DirectShowSource not frame accurate
* DSS2 — abandoned closed source.

Kurtnoise
13th April 2015, 12:48
https://github.com/FFMS/ffms2

https://github.com/FFMS/ffms2/blob/master/doc/ffms2-avisynth.md

Wilbert
13th April 2015, 18:27
Sorry, i didn't read your posts very well.
I of course have all codecs, but it you look at http://forum.doom9.org/showthread.php?t=168353 you see, that the problem between ffmpeg and AVISynth, about correct AAC-metainformation.

No, this is a problem between ffmpeg and the aacacm codec (as you can see in that thread (http://forum.doom9.org/showthread.php?p=1639389#post1639389)). AviSynth can't do anything about it.
* if ffmpeg use MP3 coding — AVIsynth with AVISource cuts 2-3% of audio tail.
We need to look at this issue ...

belonesox
15th April 2015, 11:53
https://github.com/FFMS/ffms2

https://github.com/FFMS/ffms2/blob/master/doc/ffms2-avisynth.md

Yes, I know about FFMS, but
* It is very unconvinient because it need long preindexing before opening. It is OK for non-AVI formats (MTS and so), but I found, that recoding to AVI by ffmpeg (-vcodec copy -acodec pcm16) is faster and reliable (all non-AVI media I convert to orthodox AVI for using later in AVISynth without hacks.
* I also have some issues with them.



We need to look at this issue ...

Thank you, please, look at it if you can.

Kurtnoise
15th April 2015, 13:24
your issue is not avisynth but the container you use...it's time to upgrade to a more useful one like mkv or mp4.