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 > VapourSynth
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 16th December 2014, 20:26   #1  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Basic audio support for VapourSynth

https://github.com/dubhater/vapoursynth-damb

Code:
import vapoursynth as vs

cc = vs.get_core()

#cc.std.LoadPlugin("../libdamb.so")

src = cc.ffms2.Source("7 minutes 50 seconds video.mp4")
src = cc.damb.Read(src, "demuxed audio.wav")

a = src[0:720]
b = src[720:720*2]
c = src[720*2:720*3]
d = src[720*3:720*4]
e = src[720*4:720*5]
f = src[720*5:720*6]
g = src[720*6:]

src = f + d + a + g + c + b + e

src = cc.damb.Write(src, "edited audio.wav")

src.set_output()
I hope someone finds it useful.

For the curious, "damb" means "Dingoes ate my baby" (it's a band). I wanted to call it "ding" (because it deals with audio, right?) but there is already some software with that name.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 16th December 2014, 21:50   #2  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,555
So it attaches the audio samples to each frame?
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 16th December 2014, 22:04   #3  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Quote:
Originally Posted by Myrsloik View Post
So it attaches the audio samples to each frame?
Raw audio samples, yes.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 19th December 2014, 03:29   #4  |  Link
foxyshadis
Angel of Night
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Tangled in the silks
Posts: 9,559
Aww, and you could called the writer FriesAreDone() if you'd called it ding.

How does it deal with framerate/audiorate mismatches, where a sample overhangs the end or starts late? Or is that more of an "if it hurts, don't do that!" kind of thing? Fudging a few samples on 48kHz audio probably isn't going to hurt anyway...
foxyshadis is offline   Reply With Quote
Old 19th December 2014, 07:38   #5  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Quote:
Originally Posted by foxyshadis View Post
Aww, and you could called the writer FriesAreDone() if you'd called it ding.

How does it deal with framerate/audiorate mismatches, where a sample overhangs the end or starts late? Or is that more of an "if it hurts, don't do that!" kind of thing? Fudging a few samples on 48kHz audio probably isn't going to hurt anyway...
It doesn't deal. Write only cares that a frame have audio samples attached. A frame with no audio attached will trigger an error. It will take the audio details (format, sample rate, channel count) from the first frame requested from it and use them to create the output file. It does not make sure that subsequent frames have the same kind of audio. Should it?

Read deals with mismatches in the audio and video lengths by returning an error if the audio is too short. That is, if the audio corresponding to a video frame does not exist at all (past the end of the audio file). Should it attach silence instead? It's okay if the last video frame has a bit fewer audio samples than the rest. If the audio is longer than the video, the extra samples at the end are ignored.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 19th December 2014, 09:20   #6  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: Poland
Posts: 2,843
Silence would be good, but only at the end of the file.
If something happens in the middle than it rather should error.
kolak is offline   Reply With Quote
Old 19th December 2014, 10:46   #7  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
You should add a frame property indicating the (sub-sample) delay or lead of the audio buffer, even if you don’t use it now. This could help handling mismatch between audio and video frame durations.
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 29th December 2014, 11:10   #8  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Here is v2, with a bit nicer behaviour and better documentation: https://github.com/dubhater/vapoursy...eleases/tag/v2

Code:
Read:
* avoid desynchronisation due to accumulated rounding errors.

Write:
* reject clips with more than one type of audio
* detect the output format from the extension
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 6th February 2015, 08:15   #9  |  Link
zerowalker
Registered User
 
Join Date: Jul 2011
Posts: 1,121
So wait, can it read Audio from Video without demuxing? (Guessing not)
If so can it detect more tracks?

Last edited by zerowalker; 6th February 2015 at 08:57.
zerowalker is offline   Reply With Quote
Old 6th February 2015, 09:20   #10  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,915
Quote:
Originally Posted by zerowalker View Post
So wait, can it read Audio from Video without demuxing? (Guessing not)
If so can it detect more tracks?
Not from Video (or container), from a external file with audio previously extracted and decoded:
src = cc.damb.Read(src, "demuxed audio.wav")
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 6th February 2015, 10:14   #11  |  Link
zerowalker
Registered User
 
Join Date: Jul 2011
Posts: 1,121
Ah ok.
But this is the only current way for VapourySynth to get Audio?
No "Avisource" way?

If so that's a bit of a downer, not often i have my tracks demuxed.
zerowalker is offline   Reply With Quote
Old 6th February 2015, 11:18   #12  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Quote:
Originally Posted by zerowalker View Post
Ah ok.
But this is the only current way for VapourySynth to get Audio?
No "Avisource" way?

If so that's a bit of a downer, not often i have my tracks demuxed.
Currently, yes. There is no official audio support in VapourSynth yet, so none of the video source filters read the audio.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 6th February 2015, 11:56   #13  |  Link
zerowalker
Registered User
 
Join Date: Jul 2011
Posts: 1,121
Ah ok too bad, but not a big minus as it's true gain is the Video processing power, hope for Audio though as it speeds things up;P

Thanks
zerowalker is offline   Reply With Quote
Old 6th February 2015, 13:29   #14  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Here is v3. It was supposed to include Dissolve(), but I changed my mind about writing that.

Code:
Read:
   * add support for delay
   * return silence instead of aborting in case of errors (like reading past the end of the audio file)
   * really reject unsupported formats
   * fix detection of the sample type

Read and Write:
   * add support for WAV with WAVEFORMATEX
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 6th February 2015, 13:37   #15  |  Link
zerowalker
Registered User
 
Join Date: Jul 2011
Posts: 1,121
Nice, WAVEFORMATEX.
You can look up 64bit WAV as well if you want and it's not supported, quite a forgotten format which is forcefully used when audio is too long
zerowalker is offline   Reply With Quote
Old 19th February 2015, 22:03   #16  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: Poland
Posts: 2,843
What about aiff? Easy to add?

If I add audio and pipe whole thing to ffmpeg will this pass audio?
kolak is offline   Reply With Quote
Old 19th February 2015, 22:57   #17  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Quote:
Originally Posted by kolak View Post
What about aiff? Easy to add?

If I add audio and pipe whole thing to ffmpeg will this pass audio?
libsndfile supports aiff, so it's probably not much work for me. I'll just have to see how to handle the endianness.

No, audio will not be passed to ffmpeg. The audio is attached to video frames as properties. vspipe will only output the video itself. If your operating system has mkfifo, maybe you can avoid writing the audio to a real file.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 19th February 2015, 23:36   #18  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: Poland
Posts: 2,843
Hmmm... ok.
Flame uses mkfifo on linux to pass audio to ffmpeg.
kolak is offline   Reply With Quote
Old 27th February 2015, 22:30   #19  |  Link
lo1t3yu
Registered User
 
Join Date: Feb 2015
Posts: 18
Can it synchronize audio and faulty video frames (delete mismatched duration)?
lo1t3yu is offline   Reply With Quote
Old 28th February 2015, 11:25   #20  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Quote:
Originally Posted by lo1t3yu View Post
Can it synchronize audio and faulty video frames (delete mismatched duration)?
I have no idea what that means, but probably not.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Reply


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 21:44.


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