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 18th July 2020, 23:29   #1  |  Link
skywalker
Registered User
 
Join Date: Sep 2017
Posts: 37
How to extract the original audio from the video?

Hello brothers, how are you?

I have a problem and I need your help. I use MeGUI to encode my modified videos with the AviSynth scripts.

Before when I opened the videos in MeGUI it automatically extracted the original audios from the videos. Now the MeGUI doesn't do that most.

So, I wanted to use the original audio of the video in the LPCM format because it has more quality than when I convert the MeGUI to AC3.

So I would like to know from you, if there is anything I am doing wrong in my AviSynth script that is no longer extracting the original audio in LPCM?

How can I solve this? I am very grateful if anyone can help me with this.

xD
skywalker is offline   Reply With Quote
Old 18th July 2020, 23:56   #2  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Metropolitan City of Milan, Italy
Posts: 1,669
Quote:
Originally Posted by skywalker View Post
So I would like to know from you, if there is anything I am doing wrong in my AviSynth script that is no longer extracting the original audio in LPCM?
I guess we should know it by some kind of wizardry or by sending you a trojan like Sub7, taking a look at the script in your desktop, and then reply to help you back xD

No, seriously, post your script and we'll be able to help you.


For the records, since you wanna just encode the audio in PCM using Avisynth, I guess you're gonna be fine if you use AVS in ffmpeg like so:

Code:
FFMpegSource2("your_super_uber_video.avi", atrack=-1)
and then:

Code:
ffmpeg.exe -i "AVS Script.avs" -c:a pcm_s24le -ar 48000 -f wav "audio.wav"
or, if you're a fan of loudness correction and you wanna follow EBU standards of -24LUFS...

Code:
ffmpeg.exe -i "AVS Script.avs" -c:a pcm_s24le -ar 48000 -af loudnorm=I=-24:LRA=5:tp=-2 -f wav "audio.wav"

As to MeGUI... well... if you can, you should really try to switch to the command line and use BATs to encode with your favorite encoder directly...


Side Note: Am I crazy? Why am I indexing the video when he just wants the audio? Well, Avisynth won't react well if you're indexing audio only and will complain about a missing video. Sure, you could just create a fake blank video with BlankClip() and use AudioDub() to merge your fake video and your audio, but I don't really wanna mess up with it 'cause the length would have to be the same and it's 1AM on a Saturday night... (Not that I have to go anywhere since there's a global pandemic, but still...)


Cheers,
Frank

Last edited by FranceBB; 19th July 2020 at 00:05.
FranceBB is offline   Reply With Quote
Old 19th July 2020, 00:37   #3  |  Link
qyot27
...?
 
qyot27's Avatar
 
Join Date: Nov 2005
Location: Florida
Posts: 1,287
Actually, in this case I'd cut out the AviSynth steps and just demux the audio using FFmpeg. -acodec copy, since if the audio in the original file is *not* already LPCM, decoding it to LPCM is just going to waste space (and if it's already in some compressed format and there aren't any operations to the video that would cause desync, you can just remux the original audio with the filtered video). You really only need to touch the audio if you *must* use a particular format to ensure it conforms to [insert X standard here], or if you're doing stuff like splices that would affect the A/V sync.
qyot27 is offline   Reply With Quote
Old 19th July 2020, 05:49   #4  |  Link
skywalker
Registered User
 
Join Date: Sep 2017
Posts: 37
Quote:
Originally Posted by FranceBB View Post
I guess we should know it by some kind of wizardry or by sending you a trojan like Sub7, taking a look at the script in your desktop, and then reply to help you back xD

No, seriously, post your script and we'll be able to help you.
Oh, don't do this to me, please. Haha

Sorry. I don't really understand much, I'm new to it. So this is my script:

Code:
FFVideoSource ("video.avi").ConvertToYV12(interlaced=true).ColorMatrix (Mode="Rec.709->Rec.601")

TFM()
QTGMC(Preset="Placebo")
Vinverse ()

SMDegrain (tr = 2,thsad = 400, lsb=true, chroma=true)

Spline64Resize (1440, 1080, 1, 11, -8, -9)
I just need to extract the original audio from the video to do the muxer later.

Thanks!
skywalker is offline   Reply With Quote
Old 19th July 2020, 05:51   #5  |  Link
skywalker
Registered User
 
Join Date: Sep 2017
Posts: 37
Quote:
Originally Posted by qyot27 View Post
Actually, in this case I'd cut out the AviSynth steps and just demux the audio using FFmpeg. -acodec copy, since if the audio in the original file is *not* already LPCM, decoding it to LPCM is just going to waste space (and if it's already in some compressed format and there aren't any operations to the video that would cause desync, you can just remux the original audio with the filtered video). You really only need to touch the audio if you *must* use a particular format to ensure it conforms to [insert X standard here], or if you're doing stuff like splices that would affect the A/V sync.
Yes, the original audio of the video is LPCM yes. I just want to extract it to do the muxer with the video. =)
skywalker is offline   Reply With Quote
Old 19th July 2020, 09:15   #6  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Metropolitan City of Milan, Italy
Posts: 1,669
Quote:
Originally Posted by skywalker View Post
Yes, the original audio of the video is LPCM yes. I just want to extract it to do the muxer with the video. =)
Well, then, as qyot said, there's no need to use Avisynth. Just make a BAT file and call ffmpeg like so:

Code:
ffmpeg.exe -i "source.avi" -acodec copy "audio.wav"
Where "source.avi" is literally your source file.
This will literally demux your PCM audio file from your container and mux it alone in a .wav.

The other script I suggested before (namely using Avisynth to feed ffmpeg) will not work in your case 'cause you're using FFVideoSource instead of FFMpegSource2 which means that you're effectively indexing the video but not the audio.
You can also use something like:

Code:
video=FFVideoSource("video.avi")
audio=FFAudioSource("video.avi")
AudioDub(video, audio)
to get your audio inside Avisynth and then use the command I posted before. If you do index the audio as well, it will probably also work in meGUI (although I don't really like GUIs like that...).


Now, on to your script:

Quote:
Originally Posted by skywalker View Post
Code:
FFVideoSource ("video.avi").ConvertToYV12(interlaced=true).ColorMatrix (Mode="Rec.709->Rec.601")

TFM()
QTGMC(Preset="Placebo")
Vinverse ()

SMDegrain (tr = 2,thsad = 400, lsb=true, chroma=true)

Spline64Resize (1440, 1080, 1, 11, -8, -9)
I'm actually noticing a few other "weird" thing inside your script.
First of all, why are you using TFM as default, alone, before QTGMC?
Secondly, although I don't use SMDegrain, I immediately spotted "lsb=true" which means that you're telling the filter to be working in 16bit stacked with MSB and LSB stacked one on top of the other (also called Double Height), however your source is definitely planar (and probably even 8bit), so why?
Lastly, why are you cropping and resizing to FULL HD anamorphic NTSC? Like, the last time I saw a 1440x1080 was when I capped a .ts file from a terrestrial (Digital TV) NTSC channel... What are you trying to achieve...? And last but not least, can we really use colormatrix on interlaced materials? O_o


If I may, I would do the following:

Code:
#Indexing
video=FFVideoSource("video.avi")
audio=FFAudioSource("video.avi")
AudioDub(video, audio)

#Converting to 4:2:0 planar
ConvertToYV12(interlaced=true)

#Bobbing
QTGMC(Preset="Placebo")

#Matrix Conversion
ColorMatrix (Mode="Rec.709->Rec.601")

#DeCombing
Vinverse()

#From 8bit Planar to 16bit stacked
Dither_convert_8_to_16()

#Filtering with 16bit stacked precision
SMDegrain (tr = 2,thsad = 400, lsb_in=true, lsb_out=true, chroma=true)

#From 16bit stacked to 16bit planar
ConvertFromStacked()

#Dithering down to 8bit planar
ConvertBits(bits=8, dither=1)
You may also wanna consider Matrix from HDRCore instead of ColorMatrix as it works with 16bit precision, but honestly, why are you making a FULL HD with BT601? Even if you set the flag correctly in x264 or whatever, it will almost definitely be ignored and interpreted as BT709 by the vast majority of players who take a resolution-based approach rather than a flag based one...
FranceBB is offline   Reply With Quote
Old 19th July 2020, 10:09   #7  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,237
The command line to extract your pcm audio is:

"C:\Portable\megui\tools\ffmpeg\ffmpeg.exe" -i "un_pcm.avi" -map 0:1 -acodec copy "un_pcm.avi_1.wav"

or

"C:\Portable\megui\tools\ffmpeg\ffmpeg.exe" -i "un_pcm.avi" -vn -acodec copy "un_pcm.avi_1.wav"

But the best option is use MeGUI:

Input tab -> Audio encoding Track 1 -> Audio Input -> your avi

Encoder sttings -> Flac -> Config ->
Preferred Decoder: LWLibavAudioSource
Rest off options unchecked or 'Keep Original...'
Smallest file, slow encode

And you can mux the flac in mkv with less size (~50%) but the same quality of your LPCM

or

"C:\Portable\megui\tools\ffmpeg\ffmpeg.exe" -i "un_pcm.avi" -vn -acodec flac "un_pcm.avi_1.flac"
__________________
BeHappy, AviSynth audio transcoder.

Last edited by tebasuna51; 19th July 2020 at 11:15. Reason: add info
tebasuna51 is offline   Reply With Quote
Old 19th July 2020, 10:29   #8  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,237
Quote:
Originally Posted by FranceBB View Post
Code:
video=FFVideoSource("video.avi")
audio=FFAudioSource("video.avi")
AudioDub(video, audio)
Remember:

Quote:
FFAudioSource will have to remake any index implicitly created by FFVideoSource and therefore code like

AudioDub( FFVideoSource(X), FFAudioSource(X) )
will require two indexing passes. Apart from the time consumed this is harmless. To work around it open the audio first:
A = FFAudioSource(X)
V = FFVideoSource(X)
AudioDub(V, A)
(FFmpegSource2 does this for you with a single function call) or use FFIndex, like so:
FFIndex(X)
AudioDub( FFVideoSource(X), FFAudioSource(X) ).
BTW manage audio and video with the same script is only usefull to play directly the .avs
To recode video and audio and after remux is better separated avs's.
__________________
BeHappy, AviSynth audio transcoder.

Last edited by tebasuna51; 19th July 2020 at 11:08. Reason: add info
tebasuna51 is offline   Reply With Quote
Old 19th July 2020, 16:21   #9  |  Link
skywalker
Registered User
 
Join Date: Sep 2017
Posts: 37
Hey brothers, thank you so much.
Let's divide it all into parts now, so:

Code:
ffmpeg.exe -i "source.avi" -acodec copy "audio.wav"
This worked, I manage to extract the orignal audio from my video, so thank u very much. =)

Now in my script:

Code:
First of all, why are you using TFM as default, alone, before QTGMC?
It may sound crazy, but I don't know that deeply. I only use it because it deinterlaces my video very well, so I use it.

Code:
Secondly, although I don't use SMDegrain, I immediately spotted "lsb=true" which means that you're telling the filter to be working in 16bit
stacked with MSB and LSB stacked one on top of the other (also called Double Height), however your source is definitely planar (and probably even
8bit), so why?
I still don't understand much about the properties of SMDegrain, but I use "lsb=true" because "lsb=false", SMDegrain does not seem to work, "tr" does
not work with this in false. That is the reason for choosing it in true.

Code:
Lastly, why are you cropping and resizing to FULL HD anamorphic NTSC? Like, the last time I saw a 1440x1080 was when I capped a .ts file from
a terrestrial (Digital TV) NTSC channel... What are you trying to achieve...? And last but not least, can we really use colormatrix on interlaced materials?
O_o
I cut to remove the bad edges and leave the video well trimmed. Then I resize it to 1440, 1080 to maintain the aspect ratio I like, without distortion of
the image. And at the end I add "AddBorders (240,0,240,0)" to make the video with the aspect ratio 1920x1080 to watch on TV.

I use to upscale non-anime videos, music video clips that I like.

That's all I understand so far, I'm sorry if something seems to be wrong, I'm still learning about everything and I would like to learn even more, which
you guys teach me a lot here, so thank you so much for all your help and for donating some of the time of you to clear my doubts.

This script so far seem to work well for me, it gives me a very good sharpness, which I like a lot, without the video looking like blurry goo. I like to keep
the details fine, making a light, discreet cleaning without losing quality or details.

So I am very happy with all your help, it has helped me a lot. And there are still many things I would like to do how to example (I have videos that I need to cut the begginning of this or the end of, but I don't know how to cut the audio to synchronize, keeping the original audio, without having to convert it.), but I know it takes time, and
sometimes I'm ashamed to come here for help, because I'm not good enough yet to be able to collaborate with anything that can help you yet.

Thank you qyot24, thank you FranceBB, thnak you tebasuna51, I will try to test each of your tips. Thank you.

So that's basically it. Sorry for the big text. Haha!

Last edited by skywalker; 19th July 2020 at 16:47.
skywalker is offline   Reply With Quote
Reply

Tags
audio, audio extract, lpcm, original audio, pcm

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 03:47.


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