Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 15th December 2011, 01:56   #1  |  Link
F1nkster
Registered User
 
Join Date: Sep 2011
Location: King of Prussia, PA
Posts: 19
AviSynth and Yadif mode=1 truncates audio

Using AVISynth 2.60 Alpha 3 with DV Type 2 AVI files on Windows 7 32-bit. Script:

Load_StdCall_Plugin("C:\Program Files\AviSynth 2.5\plugins\yadif.dll")
AviSource(srcvid).AssumeBFF()
Yadif(mode=1)
AssumeFPS("ntsc_double")

I've used FFmpeg, mplayer, and WMP to play the script and see consistent results on all 3.

I get video with correct duration at double framerate (as it should be). However the audio is getting truncated before the end of the video. The audio and video are in sync, it is just that the audio is truncated -- that is, it goes silent before the end of the video. I am losing 0.9 seconds of audio for every 15 minutes of video, so that on a 70 minute video that I have, I am losing a little over 4 seconds at the end. However, the ratio of 0.9 seconds for every 15 minutes holds precisely true, which is to say, if I trim the video to 15 minutes, 0.9 seconds of audio will be missing. At 30 minutes, I lose 1.8 seconds, and so on. And this is happening for every DV AVI file I throw at it.

If I remove Yadif/AssumeFPS or use mode=0, the audio outputs at the correct length. Iow, no issue. However, I am unwilling to give up Yadif(mode=1). I have not tested other deinterlacers (for this problem), nor do I plan to. So I pressed on...

AssumeFPS is necessary to maintain audio sync. Without it, Yadif outputs rounded 59.94 and not 60000/1001. Not noticeable on shorter videos, but audio goes noticeably out of sync on longer videos (say 70 minutes, for example). Sync is spot-on with AssumeFPS. That said...

I tried other import filters (FFVideoSource/FFAudioSource, DSS). Same result (that is, the problem manifests).
Demuxed audio and used WAVSource followed by AudioDub. Same result.
Placed AudioDub after Yadif/AssumeFPS. Same result.
Set AssumeFPS's sync_audio parameter to true. Same result.
Tried ConvertFPS instead of AssumeFPS. Same result.

I finally found a workaround, but not a fix. I add this to the script:

last++BlankClip(last,Round((0.9*last.framecount)/900))

In other words, I add a blank clip at the ratio of 0.9 seconds for every 15 minutes of video. This gives me all my audio and in sync with the video, but with some blank frames at the end. Most of my videos are shorter, so the blank frames are not that noticeable.

I don't know if the issue is with Yadif or with Avisynth or with how the two are interacting. Clearly there is a problem.

If you view Info on the clip in AviSynth, it reports video and audio as the same length. It is only when playing the script back, or dumping audio with ffmpeg (as in "ffmpeg -i test.avs -vn -acodec copy test.wav") that the I observe the problem.

If anyone has seen this, has any insight, or possibly even a fix, please help! I did find another post from 2009 that was less detailed, but I believe it described the same problem. There was no resolution. I am hopeful with the extra detail above, and the right eyes looking at it, the problem can be identified.
F1nkster is offline   Reply With Quote
Old 15th December 2011, 05:08   #2  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
It looks like Yadif might be truncating the audio to match the video.

As a test, replace Yadif(1) with SelectEvery(1, 0,0). This will just return each unprocessed frame twice, so you can test the Audio sync logic of the script without the Yadif plugin, i.e. prove if the problem is in Yadif(1) or something more fundamental.

Also put Info() calls between each statement in turn (one at a time) to see how the Audio and Video duration, frame count and sample count are all adjusted by each statement.

And try moving the AssumeFPS line to before the Yadif(1) line, but make it AssumeFPS("ntsc") of course.
IanB is offline   Reply With Quote
Old 15th December 2011, 18:10   #3  |  Link
F1nkster
Registered User
 
Join Date: Sep 2011
Location: King of Prussia, PA
Posts: 19
Thanks for the reply. So I replaced Yadif(1) with SelectEvery(1,0,0), and got the same result. The audio is truncated by precisely the same amount.

I also used AssumeFPS("ntsc_video") prior to Yadif (and SelectEvery on a separate run), and this output 60000/1001 video, so I will stick with it.

Also, when I use Info at any point in the script, the duration of the video and audio always match. It is only when executing the script, and outputting the audio, that the issue is noticed.

Also, the fact that I demuxed audio, imported with WAVSource, and used AudioDub after Yadif, also reinforces that Yadif is not the root cause.
F1nkster is offline   Reply With Quote
Old 15th December 2011, 22:16   #4  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Quote:
Originally Posted by F1nkster View Post
Thanks for the reply. So I replaced Yadif(1) with SelectEvery(1,0,0), and got the same result. The audio is truncated by precisely the same amount.
So the problem is not in Yadif(1) but is something more fundamental.

Quote:
Also, when I use Info at any point in the script, the duration of the video and audio always match. It is only when executing the script, and outputting the audio, that the issue is noticed.
If you process/play the script with VirtualDub does it also have a problem.

Does VirtualDub's Information popup agree with an Info() display at the very end of the script?

Perhaps you can put up a small screen grab of the Info() display for the last frame.
IanB is offline   Reply With Quote
Old 16th December 2011, 00:39   #5  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
In NTSC we get 1 extra second for every 1000 seconds of original film footage. (1000s/60s)*0.9s=15 minutes
Coincidence?
What happens if you use the following:
1.) AssumeFPS(60)
2.) AssumeFPS(60000, 1001)
?
sneaker_ger is offline   Reply With Quote
Old 16th December 2011, 02:57   #6  |  Link
F1nkster
Registered User
 
Join Date: Sep 2011
Location: King of Prussia, PA
Posts: 19
So IanB's suggestion of running the script through VDubMod got me started on a path that has convinced me the problem is not with AviSynth or Yadif. It appears to be with FFmpeg.

I can use VDubMod to save the WAV file off the avs script and it outputs correctly with no truncation.

I also downloaded a little utility called wavi and played the avs script through that, outputting a wav file. Again, no truncation.

I guess I was giving FFmpeg the benefit of the doubt earlier. Still, I played the script through mplayer and it seemed to cut-off, but now I am wondering if it just wasn't keeping up and getting out of sync.

Anyhow, I tried setting the framerate with FFmpeg using the -r parameter. It made no difference. I cannot get FFmpeg to output correct audio. So much for FFmpeg, at least for encoding the audio.

I can use wavi and pipe it to faac, then mux with an h264 file out of ffmpeg. Or mencoder for that matter. But ffmpeg was so nice because I could run it against the avs script one time and output an h264 and aac file, then mux with MP4Box. Now I have to process the script twice, once for video, once for audio. That sucks.

Thanks for the replies on this!
F1nkster is offline   Reply With Quote
Old 16th December 2011, 05:17   #7  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
The FFMpeg libraries are very widely used as a general purpose input (even Avisynth has FFMpegSource() available), so if it has a problem truncating the audio with Avisynth input, anything that uses it will exhibit the problem.

Hopefully an FFMpeg expert can provide some insight.

Seems the brute force approach of adding 1 or more seconds of video and audio padding with "Last + BlankClip(Last, 30)" might be the easiest approach.
IanB is offline   Reply With Quote
Old 16th December 2011, 06:23   #8  |  Link
TheRyuu
warpsharpened
 
Join Date: Feb 2007
Posts: 787
So to reproduce:

Any input file?
Load video+audio in avisynth.
Throw script at ffmpeg?
TheRyuu is offline   Reply With Quote
Old 16th December 2011, 07:45   #9  |  Link
vampiredom
Registered User
 
Join Date: Aug 2008
Posts: 233
Quote:
Originally Posted by sneaker_ger View Post
In NTSC we get 1 extra second for every 1000 seconds of original film footage. (1000s/60s)*0.9s=15 minutes
Yeah, I was reading the thread and thinking the same kind of thing. I'd like to know if the problem persists without the AssumeFPS() line at all, or perhaps...

Code:
AssumeFPS(60000,1001, sync_audio=true)
** EDIT ** I reread and it looks like you tried that already. Very odd.

Last edited by vampiredom; 16th December 2011 at 09:20.
vampiredom is offline   Reply With Quote
Old 16th December 2011, 13:33   #10  |  Link
F1nkster
Registered User
 
Join Date: Sep 2011
Location: King of Prussia, PA
Posts: 19
In response to TheRyuu, doubling the framerate is another necessary piece to reproducing the problem.

If you just load audio+video, and change nothing, then throw at ffmpeg, it works fine.

But use a bob deinterlacer that doubles the framerate, or even just SelectEvery(1,0,0) as we tested above, then we have the problem.

Removing AssumeFPS does not affect the truncating issue. However, removing it leads to an audio sync issue that is noticeable only on longer clips of say 60 minutes or more (roughly). The truncation issue exists with or without AssumeFPS. It just becomes harder to troubleshoot because you think you're dealing with an audio sync issue, when you are in fact dealing with both an audio sync and a truncation issue at that point. Actually, the truth is that you have a framerate issue that manifests as an audio sync issue. Anyway...

I have only tested DV AVI files. I have some HDV mpeg files that I will be getting to.

Last edited by F1nkster; 16th December 2011 at 13:39.
F1nkster is offline   Reply With Quote
Old 16th December 2011, 13:46   #11  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
What is your ffmpeg command line?
(Any special parameters that might affect the output?)
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 16th December 2011, 18:39   #12  |  Link
F1nkster
Registered User
 
Join Date: Sep 2011
Location: King of Prussia, PA
Posts: 19
The problem can be observed simply by using the following:

ffmpeg -i test.avs -vn -acodec copy test.wav

I also tried inserting -r 59.94, -r 59.9401, and -r 60 at different points (before/after test.avs) and it had no effect.

In actual use, I was using ffmpeg to encode to aac and observing the issue that way as well but it is unnecessary to go through all that.
F1nkster is offline   Reply With Quote
Old 17th December 2011, 09:19   #13  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Yes it seem FFMpeg chops a small amount off the end.

I tried :-
Code:
ColorBars()
Trim(0, -15*60*30) # 15:00.9 @ 29.97fps
Info()
The Info display confirmed 15:00.9 duration for audio and video. A "ffmpeg -i test.avs -vn -acodec copy test.wav" claimed 15:00.9 source duration. But it only wrote 168855Kb of audio, it should have written 168919Kb.

The subsequent test.wav file was only 15:00.56 duration. Which is of course is 168855Kb.
IanB is offline   Reply With Quote
Old 19th December 2011, 15:20   #14  |  Link
F1nkster
Registered User
 
Join Date: Sep 2011
Location: King of Prussia, PA
Posts: 19
IanB, I'm interpreting your post as saying that FFmpeg is truncating audio with/without doubling the framerate. I guess it just becomes more noticeable when doubling the framerate.

Anyhow, I've change my workflow and scripts to use mencoder for video and Nero AAC for audio, preprocessed with AVISynth of course. I just have to encode the streams separately then mux with MP4Box. So be it. Everything is working correctly without having to add a blank clip to the end.
F1nkster is offline   Reply With Quote
Old 20th December 2011, 01:03   #15  |  Link
TheRyuu
warpsharpened
 
Join Date: Feb 2007
Posts: 787
Quote:
Originally Posted by F1nkster View Post
IanB, I'm interpreting your post as saying that FFmpeg is truncating audio with/without doubling the framerate. I guess it just becomes more noticeable when doubling the framerate.

Anyhow, I've change my workflow and scripts to use mencoder for video and Nero AAC for audio, preprocessed with AVISynth of course. I just have to encode the streams separately then mux with MP4Box. So be it. Everything is working correctly without having to add a blank clip to the end.
If you're going to do them both separate anyway why not just use x264 directly.

Also qt aac will likely result in better quality than nero.
TheRyuu is offline   Reply With Quote
Old 20th December 2011, 19:04   #16  |  Link
F1nkster
Registered User
 
Join Date: Sep 2011
Location: King of Prussia, PA
Posts: 19
Thanks for the tips. So many options! I'll check out qt aac.

I've considered just using x264 directly. I'm familiar with mencoder so just went down that road for expedience.

This may be worth a thread unto itself, but is there an advantage to using x264 vs mencoder (or ffmpeg for that matter)?

I've searched on this question and haven't found any definitive answers, just people's preferences. I was left with the impression that the output should be the same since they are all using x264.
F1nkster is offline   Reply With Quote
Old 20th December 2011, 21:59   #17  |  Link
F1nkster
Registered User
 
Join Date: Sep 2011
Location: King of Prussia, PA
Posts: 19
So I did some quick testing with using x264.exe for encoding. In doing so, I discovered that many of the x264 options that I thought I was setting with mencoder were not actually working -- meaning when I looked at mediainfo on the output file, the encode settings that it shows were not what I had set. So perhaps this points to an issue with mencoder. Anyhow I have found it more expedient to just use x264 than to troubleshoot mencoder. Fwiw, I was using a mencoder.conf file to create an x264 profile with options, so maybe I did something wrong there. It's not worth the time figuring it out. x264 wins.
F1nkster is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 13:43.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.