Log in

View Full Version : AudioDub -- importing an AVS file for audio


BlueToast
5th December 2012, 21:05
Before my harddrive got trashed due to a click of death, I managed to put together a simple script that worked successfully. This script combined multiple parts (with their audio) into one AVS file. I am doing this again, but with new material (different project). I can't get this to work:

OneFitsAll.avs
v1 = Import("G:\Conference\Part1.mp4.avs")
a1 = Import("G:\Conference\Part1.mp4_track_1_english.avs")
v1 = v1.AudioDub(a1)

v2 = Import("G:\Conference\Part2.mp4.avs")
a2 = Import("G:\Conference\Part2.mp4_track_1_english.avs")
v2 = v2.AudioDub(a2)

v3 = Import("G:\Conference\Part3.mp4.avs")
a3 = Import("G:\Conference\Part3.mp4_track_1_english.avs")
v3 = v3.AudioDub(a3)

v4 = Import("G:\Conference\Part4.mp4.avs")
a4 = Import("G:\Conference\Part4.mp4_track_1_english.avs")
v4 = v4.AudioDub(a4)

v5 = Import("G:\Conference\Part5.mp4.avs")
a5 = Import("G:\Conference\Part5.mp4_track_1_english.avs")
v5 = v5.AudioDub(a5)

final = v1 + v2 + v3 + v4 + v5

Part1.mp4.avs (the others are identical)
LoadPlugin("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll")
FFVideoSource("G:\Conference\Part1.mp4", threads=1)
#deinterlace
#crop
#resize
#denoise


Part1.mp4_track_1_english.avs (the others are identical)
LoadPlugin("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll")
FFAudioSource("G:\Conference\Part1.mp4", track=1, cachefile="G:\Conference\Part1.mp4.ffindex")
# detected channels: 2 channels
# detected channel positions: 2/0/0

I know there is a way to 'import' the Part#.mp4_track_1_english.avs in OneFitsAll.avs before the v#.AudioDub(a#) because I did it before my harddrive was trashed, I just don't know how I did it. :(

Gavino
5th December 2012, 21:32
Open the audio before the video, ie
a1 = Import("G:\Conference\Part1.mp4_track_1_english.avs")
v1 = Import("G:\Conference\Part1.mp4.avs")
v1 = v1.AudioDub(a1)
... etc ...
Reason is that FFVideoSource will only index video tracks, whereas FFAudioSource indexes both audio and video.

Also, to avoid potential audio sync problems, you should use ++ to join:
final = v1 ++ v2 ++ v3 ++ v4 ++ v5

You also need to add
return final
as the last line of your script.

BlueToast
6th December 2012, 01:11
Ah, ok. Could you also tell me the difference between using '+' and '++'?

Guest
6th December 2012, 01:22
Refer to Avisynth documentation:

+ the same as the function UnalignedSplice
++ the same as the function AlignedSplice

StainlessS
6th December 2012, 01:25
+ joins up all audio without spaces (between the audio), ++ does a sort of Trim() between each separate clip, keeping audio aligned with
the same video it belongs to. You would probably want to (nearly always) use "++", unless you have reason not to.

BlueToast
6th December 2012, 05:08
Thanks a million guys!

EDIT: For some reason this still doesn't work. :( I did the ++ instead of +, and moved the a# = Import("") lines before the v# = Import("") lines. MPlayer isn't playing the AVS file.

EDIT2: It works when I remove everything except for the following
a1 = Import("G:\Conference\Part1.mp4_track_1_english.avs")
v1 = Import("G:\Conference\Part1.mp4.avs")
v1 = v1.AudioDub(a1)

final = v1
return final
hmm

Here is the full OneFitsAll.avs script as it is right now:
a1 = Import("G:\Conference\Part1.mp4_track_1_english.avs")
v1 = Import("G:\Conference\Part1.mp4.avs")
v1 = v1.AudioDub(a1)

a2 = Import("G:\Conference\Part2.mp4_track_1_english.avs")
v2 = Import("G:\Conference\Part2.mp4.avs")
v2 = v2.AudioDub(a2)

a3 = Import("G:\Conference\Part3.mp4_track_1_english.avs")
v3 = Import("G:\Conference\Part3.mp4.avs")
v3 = v3.AudioDub(a3)

a4 = Import("G:\Conference\Part4.mp4_track_1_english.avs")
v4 = Import("G:\Conference\Part4.mp4.avs")
v4 = v4.AudioDub(a4)

a5 = Import("G:\Conference\Part5.mp4_track_1_english.avs")
v5 = Import("G:\Conference\Part5.mp4.avs")
v5 = v5.AudioDub(a5)

final = v1 ++ v2 ++ v3 ++ v4 ++ v5
return final

Gavino
6th December 2012, 09:52
MPlayer isn't playing the AVS file.
Do you see any error message?

If the individual avs files are as you posted, it should work.
Note that it takes a few seconds to build each index file, so you may need to wait a short while to see any results.

fvisagie
6th December 2012, 17:53
If it helps any, you could also consider explicitly indexing clips as an additional step, i.e.

FFIndex(source=source, cachefile=source+".ffindex", indexmask=-1, dumpmask=0, errorhandling=3, overwrite=false)
Audio = FFAudioSource(source=source, track=-1, cache=true, cachefile=source+".ffindex", adjustdelay=-1)
Video = FFVideoSource(source=source, track=-1, cache=true, cachefile=source+".ffindex", seekmode=1, rffmode=0, width=-1, height=-1, colorspace="YV12")

This way it does not matter in which sequence you load audio and video.

The setting in blue also skips the indexing next time around, provided the index file exists and is intact.

BlueToast
6th December 2012, 19:30
C:/Program Files (x86)/SMPlayer/mplayer/mplayer.exe -noquiet -nofs -nomouseinput -sub-fuzziness 1 -identify -slave -vo direct3d, -ao dsound -nokeepaspect -priority abovenormal -framedrop -nodr -double -wid 197474 -monitorpixelaspect 1 -ass -embeddedfonts -ass-line-spacing 0 -ass-font-scale 1 -ass-styles C:/Users/Qwerty/.smplayer/styles.ass -fontconfig -font Arial -subfont-autoscale 0 -subfont-osd-scale 20 -subfont-text-scale 20 -subcp ISO-8859-1 -subpos 100 -volume 99 -nocache -osdlevel 0 -vf-add screenshot -slices -channels 2 -af scaletempo,equalizer=0:0:0:0:0:0:0:0:0:0 -softvol -softvol-max 110 G:/Conference/OneFitsAll.avs

MPlayer Sherpya-SVN-r30369-4.2.5 (C) 2000-2009 MPlayer Team
Setting process priority: abovenormal

Playing G:/Conference/OneFitsAll.avs.
Seek failed


Exiting... (End of file)
ID_EXIT=EOF

Pardon my dumbness, but would the index thing look like this in OneFitsAll.avs?
FFIndex(source=source, cachefile=source+".ffindex", indexmask=-1, dumpmask=0, errorhandling=3, overwrite=false)
Audio = FFAudioSource(source=source, track=-1, cache=true, cachefile=source+".ffindex", adjustdelay=-1)
Video = FFVideoSource(source=source, track=-1, cache=true, cachefile=source+".ffindex", seekmode=1, rffmode=0, width=-1, height=-1, colorspace="YV12")

a1 = Import("G:\Conference\Part1.mp4_track_1_english.avs")
v1 = Import("G:\Conference\Part1.mp4.avs")
v1 = v1.AudioDub(a1)

a2 = Import("G:\Conference\Part2.mp4_track_1_english.avs")
v2 = Import("G:\Conference\Part2.mp4.avs")
v2 = v2.AudioDub(a2)

a3 = Import("G:\Conference\Part3.mp4_track_1_english.avs")
v3 = Import("G:\Conference\Part3.mp4.avs")
v3 = v3.AudioDub(a3)

a4 = Import("G:\Conference\Part4.mp4_track_1_english.avs")
v4 = Import("G:\Conference\Part4.mp4.avs")
v4 = v4.AudioDub(a4)

a5 = Import("G:\Conference\Part5.mp4_track_1_english.avs")
v5 = Import("G:\Conference\Part5.mp4.avs")
v5 = v5.AudioDub(a5)

final = v1 ++ v2 ++ v3 ++ v4 ++ v5
return final

fvisagie
7th December 2012, 07:34
Pardon my dumbness, but would the index thing look like this in OneFitsAll.avs?

According to the FFmpegSource2 documentation (my emphasis)

FFVideoSource
...
Opens video. Will invoke indexing of all video tracks (but no audio tracks) if no valid index file is found.

My emphasis:

FFAudioSource
...
Opens audio. Invokes indexing of all tracks if no valid index file is found, or if the requested track isn't present in the index.

So we can see that for input containing both audio and video, it's better to call FFAudioSource() before FFVideoSource(), as Gavino pointed out.

However,

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.

So, by always calling FFindex() before accessing either video or audio from a particular file, we can avoid uncertainty about the order in which they should be (or have been) done.

How this applies to your question, is that you could choose to apply FFindex() before every call that loads audio or video. In other words, you would probably put it inside every Part...avs.

E.g. Part1.mp4.avs would then look like this

LoadPlugin("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll")
source = "G:\Conference\Part1.mp4"
FFIndex(source=source, cachefile=source+".ffindex", indexmask=-1, dumpmask=0, errorhandling=3, overwrite=false)
FFVideoSource(source=source, track=-1, cache=true, cachefile=source+".ffindex", seekmode=1, rffmode=0, width=-1, height=-1, threads=1)
#deinterlace
#crop
#resize
#denoise

and Part1.mp4_track_1_english.avs would look like this

LoadPlugin("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll")
source = "G:\Conference\Part1.mp4"
FFIndex(source=source, cachefile=source+".ffindex", indexmask=-1, dumpmask=0, errorhandling=3, overwrite=false)
FFAudioSource(source=source, track=1, cache=true, cachefile=source+".ffindex", adjustdelay=-1)
# detected channels: 2 channels
# detected channel positions: 2/0/0

This way, whichever of the audio or video parts gets called first, indexing will occur correctly. Also, both audio and video parts will be sharing the same index file which saves time on re-indexing, and lastly the index file is retained between sessions, which also saves time.

There are certainly more efficient ways of doing this, but let's take things one step at a time :).

PS. As Gavino pointed out, every .avs referenced from your OneFitsAll.avs should be playable by MPlayer in its own right. Therefore, while everything isn't working yet, before adding FFIndex() you may first want to check that individual files are playable, that OneFitsAll.avs strings them together correctly, and then you can set out potentially improving things.

BlueToast
7th December 2012, 17:35
There are certainly more efficient ways of doing this, but let's take things one step at a time :).

PS. As Gavino pointed out, every .avs referenced from your OneFitsAll.avs should be playable by MPlayer in its own right. Therefore, while everything isn't working yet, before adding FFIndex() you may first want to check that individual files are playable, that OneFitsAll.avs strings them together correctly, and then you can set out potentially improving things.I tried to play each PartX.avs in MPlayer, and it worked both before and after.

I also commented out the AudioDub and a1=Import("") lines from the OneFitsAll.avs, and tried to run OneFitsAll.avs in MPlayer before and after making changes to the PartX.avs files -- I received the same MPlayer log file before and after making changes to the PartX.avs files, and was unable to get any video. :( I think the problem is lying in OneFitsAll.avs somehow.

C:/Program Files (x86)/SMPlayer/mplayer/mplayer.exe -noquiet -nofs -nomouseinput -sub-fuzziness 1 -identify -slave -vo direct3d, -ao dsound -nokeepaspect -priority abovenormal -framedrop -nodr -double -wid 262814 -monitorpixelaspect 1 -ass -embeddedfonts -ass-line-spacing 0 -ass-font-scale 1 -ass-styles C:/Users/Qwerty/.smplayer/styles.ass -fontconfig -font Arial -subfont-autoscale 0 -subfont-osd-scale 20 -subfont-text-scale 20 -subcp ISO-8859-1 -subpos 100 -volume 99 -nocache -osdlevel 0 -vf-add screenshot -slices -channels 2 -af scaletempo,equalizer=0:0:0:0:0:0:0:0:0:0 -softvol -softvol-max 110 G:/Conference/OneFitsAll.avs

MPlayer Sherpya-SVN-r30369-4.2.5 (C) 2000-2009 MPlayer Team
Setting process priority: abovenormal

Playing G:/Conference/OneFitsAll.avs.
Seek failed


Exiting... (End of file)
ID_EXIT=EOF

So strange, I know I was able to pull this off on another video very simply. : o

fvisagie
7th December 2012, 20:04
Before struggling with the scripts any further (perhaps needlessly), see if you can rule out any strangeness with MPlayer. Perhaps you can compare results with Windows Media Player, VLC, Media Player Classic etc.

BlueToast
10th December 2012, 02:38
Before struggling with the scripts any further (perhaps needlessly), see if you can rule out any strangeness with MPlayer. Perhaps you can compare results with Windows Media Player, VLC, Media Player Classic etc.Ok, this weekend I found some time to process some of the videos I have taken with my Canon t3i DSLR. The camera saves these as .MOV in h264 with the ffh264 codec, and uses 2-channel 48kHz PCM for audio.

I had zero problems when using this script:
v1 = Import("G:\20121019-1846\DCIM\VIDEO\Thanksgiving (20121122)\MVI_3019.MOV.avs")
a1 = Import("G:\20121019-1846\DCIM\VIDEO\Thanksgiving (20121122)\MVI_3019.MOV_track_1_english.avs")
v1 = v1.AudioDub(a1)

v2 = Import("G:\20121019-1846\DCIM\VIDEO\Thanksgiving (20121122)\MVI_3119.MOV.avs")
a2 = Import("G:\20121019-1846\DCIM\VIDEO\Thanksgiving (20121122)\MVI_3119.MOV_track_1_english.avs")
v2 = v2.AudioDub(a2)

final = v1 ++ v2
return final

That is literally all I had to do. It was simple, it's just that for some reason it isn't working with the project that pertains to this thread.

I should probably identify where I got my MP4 files from; I downloaded the 720p quality versions from my Livestream account (paid Basic subscription) from the archiving feature of Livestream. I didn't use Video DownloadHelper -- Livestream provides a download link for the account holder for direct download.

Here's the odd thing -- if I modify OneFitsAll.avs to have only ONE pair of video and audio (i.e. delete all except for v1 & a1 lines in the script) and modify the "final =" line (before "return final") to be "final = v1" instead of "final = v1 ++ v2 ++ ...", it works. Individually they also work (i.e. when running just the Part1.mp4.avs file).

I just also checked all five MP4 video files, and according to MPlayer they are all of the same settings, encoder, resolution, etc:

? Part1.mp4
General
File
G:/Conference/Part1.mp4
Size
255556 KB (249 MB)
Length
00:20:21
Demuxer
lavfpref

Video
Resolution
1280 x 720
Aspect ratio
1.77778
Format
H264
Bitrate
1382 kbps
Frames per second
60.000
Selected codec
ffh264

Initial Audio Stream
Format
MP4A
Bitrate
319 kbps
Rate
48000 Hz
Channels
2
Selected codec
ffaac

Audio Streams
#
Language
Name
ID
0
eng
<empty>
0


? Part2.mp4
General
File
G:/Conference/Part2.mp4
Size
753375 KB (735 MB)
Length
01:20:08
Demuxer
lavfpref

Video
Resolution
1280 x 720
Aspect ratio
1.77778
Format
H264
Bitrate
952 kbps
Frames per second
60.000
Selected codec
ffh264

Initial Audio Stream
Format
MP4A
Bitrate
319 kbps
Rate
48000 Hz
Channels
2
Selected codec
ffaac

Audio Streams
#
Language
Name
ID
0
eng
<empty>
0


? Part3.mp4
General
File
G:/Conference/Part3.mp4
Size
20202 KB (19 MB)
Length
00:01:20
Demuxer
lavfpref

Video
Resolution
1280 x 720
Aspect ratio
1.77778
Format
H264
Bitrate
1717 kbps
Frames per second
60.000
Selected codec
ffh264

Initial Audio Stream
Format
MP4A
Bitrate
319 kbps
Rate
48000 Hz
Channels
2
Selected codec
ffaac

Audio Streams
#
Language
Name
ID
0
eng
<empty>
0


? Part4.mp4
General
File
G:/Conference/Part4.mp4
Size
48855 KB (47 MB)
Length
00:03:47
Demuxer
lavfpref

Video
Resolution
1280 x 720
Aspect ratio
1.77778
Format
H264
Bitrate
1428 kbps
Frames per second
60.000
Selected codec
ffh264

Initial Audio Stream
Format
MP4A
Bitrate
319 kbps
Rate
48000 Hz
Channels
2
Selected codec
ffaac

Audio Streams
#
Language
Name
ID
0
eng
<empty>
0


? Part5.mp4
General
File
G:/Conference/Part5.mp4
Size
55334 KB (54 MB)
Length
00:03:48
Demuxer
lavfpref

Video
Resolution
1280 x 720
Aspect ratio
1.77778
Format
H264
Bitrate
1648 kbps
Frames per second
60.000
Selected codec
ffh264

Initial Audio Stream
Format
MP4A
Bitrate
320 kbps
Rate
48000 Hz
Channels
2
Selected codec
ffaac

Audio Streams
#
Language
Name
ID
0
eng
<empty>
0


I don't know how to proceed. :\ I could re-encode (nasty) each one of them to be based on x264/RAWAVC with a very high bitrate. In the end I will be using a video bitrate of around 2048 and a 3-pass x264/RAWAVC encode --> muxed into MP4 or MKV.