Log in

View Full Version : how to extract the audio track from avi? with FFmpeg GIT


cr0n=0sTT88
15th April 2014, 01:25
Hi, how to extract the audio track from avi? I would like use FFmpeg GIT but I don't know the script language.

:helpful:

:thanks::thanks:

Richard1485
15th April 2014, 15:51
If you want WAV, you could open the AVI in VirtualDub and go to File → Save Wav...

You could also try Avidemux.

cr0n=0sTT88
15th April 2014, 15:52
thank you. but is it possible do it this with FFmpeg git? what is the code for do it this? i don't want re-code. I only want the same format than original.

:thanks:

Richard1485
15th April 2014, 15:56
Sorry. I misread your first post. My mistake! (I don't use FFmpeg, I'm afraid.)

poisondeathray
15th April 2014, 17:58
ffmpeg -i input.avi -vn -c:a copy output.ext

for "ext" you need to put whatever format the audio is (e.g. output.ac3, output.mp3 , etc....)

if you use ffmpeg -i input.avi , it will tell you what format the audio is

cr0n=0sTT88
15th April 2014, 18:08
ffmpeg -i input.avi -vn -c:a copy output.ext

for "ext" you need to put whatever format the audio is (e.g. output.ac3, output.mp3 , etc....)

if you use ffmpeg -i input.avi , it will tell you what format the audio is

thank you! works very fine!
one more thing please!!!:

if i want copy output.ac3 to another video.mkv, what is the code???

cr0n=0sTT88
15th April 2014, 18:11
if I want create a .bat what is the format? only is needed save this text "ffmpeg -i input.avi -vn -c:a copy output.ext" with .bat??

poisondeathray
15th April 2014, 18:31
if i want copy output.ac3 to another video.mkv, what is the code???


If video.mkv has no audio (otherwise you have to specify -map for which specific streams you are referring to)

https://trac.ffmpeg.org/wiki/How%20to%20use%20-map%20option



ffmpeg -i video.mkv -i output.ac3 -c:v copy -c:a copy output2.mkv





if I want create a .bat what is the format? only is needed save this text "ffmpeg -i input.avi -vn -c:a copy output.ext" with .bat??

Did you mean to process 1 file only, or batch process a folder of files?

The basic method of using an excutable .bat file in windows is to copy & paste the ffmpeg command in notepad, save it, change the extension from .txt to .bat . Care must be taken to specify full paths, if the .bat file is not in the same directory as the files to be processed

cr0n=0sTT88
15th April 2014, 18:56
If video.mkv has no audio (otherwise you have to specify -map for which specific streams you are referring to)

https://trac.ffmpeg.org/wiki/How%20to%20use%20-map%20option



ffmpeg -i video.mkv -i output.ac3 -c:v copy -c:a copy output2.mkv







Did you mean to process 1 file only, or batch process a folder of files?

The basic method of using an excutable .bat file in windows is to copy & paste the ffmpeg command in notepad, save it, change the extension from .txt to .bat . Care must be taken to specify full paths, if the .bat file is not in the same directory as the files to be processed


the video have two tracks of audio. this is the mediainfo of the video:

General
Unique ID : 245253259763869580241356251299037951674 (0xB8820F4817787472A09A1B73F691B6BA)
Complete name : D:\Bandeja Entrada\Vídeos\ffmpeg-git-b6ff81d-win64-static\bin\input.mkv
Format : Matroska
Format version : Version 2
File size : 9.07 GiB
Duration : 1h 50mn
Overall bit rate mode : Variable
Overall bit rate : 11.7 Mbps
Encoded date : UTC 2013-03-31 14:26:44
Writing application : mkvmerge v5.4.0 ('Piper') built on Mar 10 2012 13:34:39
Writing library : libebml v1.2.3 + libmatroska v1.3.0

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4.1
Format settings, CABAC : Yes
Format settings, ReFrames : 5 frames
Muxing mode : Header stripping
Codec ID : V_MPEG4/ISO/AVC
Duration : 1h 50mn
Bit rate : 9 474 Kbps
Nominal bit rate : 8 956 Kbps
Width : 1 920 pixels
Height : 816 pixels
Display aspect ratio : 2.35:1
Frame rate mode : Constant
Frame rate : 23.976 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.252
Stream size : 7.34 GiB (81%)
Title : x264 | 8956 Kbps | 23.976 fps | 2.35:1
Writing library : x264 core 120
Encoding settings : cabac=1 / ref=5 / deblock=1:-3:-3 / analyse=0x3:0x113 / me=umh / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=24 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=4 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=4 / b_pyramid=2 / b_adapt=2 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=240 / keyint_min=24 / scenecut=40 / intra_refresh=0 / rc_lookahead=50 / rc=2pass / mbtree=1 / bitrate=8956 / ratetol=1.0 / qcomp=0.60 / qpmin=3 / qpmax=69 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / vbv_maxrate=40000 / vbv_bufsize=30000 / nal_hrd=none / ip_ratio=1.40 / aq=1:1.00
Language : Japanese
Default : Yes
Forced : No
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709

Audio #1
ID : 2
Format : DTS
Format/Info : Digital Theater Systems
Format profile : MA / Core
Muxing mode : Header stripping
Codec ID : A_DTS
Duration : 1h 50mn
Bit rate mode : Variable
Bit rate : 1 558 Kbps / 1 510 Kbps
Channel(s) : 3 channels
Channel positions : Front: L C R
Sampling rate : 48.0 KHz
Bit depth : 24 bits
Compression mode : Lossless / Lossy
Title : [Feature] DTS-HD | 1536 Kbps | vbr | 3 chan
Language : Japanese
Default : Yes
Forced : No

Audio #2
ID : 3
Format : AC-3
Format/Info : Audio Coding 3
Mode extension : CM (complete main)
Format settings, Endianness : Big
Muxing mode : Header stripping
Codec ID : A_AC3
Duration : 1h 50mn
Bit rate mode : Constant
Bit rate : 448 Kbps
Channel(s) : 1 channel
Channel positions : Front: C
Sampling rate : 48.0 KHz
Bit depth : 16 bits
Compression mode : Lossy
Stream size : 355 MiB (4%)
Title : [Commentary - Stephen Prince] AC3 | 448 Kbps | cbr | mono
Language : English
Default : No
Forced : No

Text #1
ID : 4
Format : VobSub
Muxing mode : zlib
Codec ID : S_VOBSUB
Codec ID/Info : The same subtitle format used on DVDs
Language : English
Default : No
Forced : No

Text #2
ID : 5
Format : UTF-8
Codec ID : S_TEXT/UTF8
Codec ID/Info : UTF-8 Plain Text
Language : French
Default : No
Forced : No

Text #3
ID : 6
Format : UTF-8
Codec ID : S_TEXT/UTF8
Codec ID/Info : UTF-8 Plain Text
Language : Portuguese
Default : No
Forced : No

Text #4
ID : 7
Format : UTF-8
Codec ID : S_TEXT/UTF8
Codec ID/Info : UTF-8 Plain Text
Language : Spanish
Default : No
Forced : No

Menu
00:00:00.000 : en:Stick
00:05:55.813 : en:Sides
00:16:19.770 : en:Demonstration
00:20:04.578 : en:Price
00:21:14.731 : en:Plot
00:23:33.954 : en:Names
00:25:52.384 : en:Noon
00:32:45.338 : en:Inspections
00:38:59.253 : en:Costs
00:42:38.138 : en:Unosuke
00:46:31.038 : en:Fired
00:49:35.973 : en:Bargain
00:51:17.657 : en:Information
00:56:05.195 : en:Exchange
00:59:19.264 : en:Mothers
01:03:19.670 : en:Betrayed
01:05:22.209 : en:Bodyguard
01:07:19.785 : en:Gone
01:12:05.112 : en:Retaliation
01:13:49.466 : en:Note
01:18:47.639 : en:Pounding
01:23:24.582 : en:Chest
01:32:26.290 : en:Smoke
01:38:10.175 : en:Duped
01:39:59.618 : en:Training
01:41:24.995 : en:Payback
01:50:51.645 : en:01:50:51.645



this is the mediainfo of the audio file:

General
Complete name : D:\Bandeja Entrada\Vídeos\ffmpeg-git-b6ff81d-win64-static\bin\output.ac3
Format : AC-3
Format/Info : Audio Coding 3
File size : 203 MiB
Duration : 1h 50mn
Overall bit rate mode : Constant
Overall bit rate : 256 Kbps

Audio
Format : AC-3
Format/Info : Audio Coding 3
Mode extension : CM (complete main)
Format settings, Endianness : Big
Duration : 1h 50mn
Bit rate mode : Constant
Bit rate : 256 Kbps
Channel(s) : 2 channels
Channel positions : Front: L R
Sampling rate : 48.0 KHz
Bit depth : 16 bits
Compression mode : Lossy
Stream size : 203 MiB (100%)


I suppose that the audio is the third stream of audio.

Yes, I would like do it this with batch mode. For this I want the script. i need replay this operation with 10 videos; the videos are in one folder. If it's possible do it in bath mode is better for me but it is sufficient the command for insert the audio file into video file :)

thank you!!!!

poisondeathray
15th April 2014, 19:14
so did you want 3 audio tracks then (2 original audio, adding the extracted audio? ) ? You're better off using mkvtoolnix IMO, because ffmpeg can sometimes drop some of the subs and/or chapters - I'm assuming you want to keep everything intact

To batch process, say, all AVI videos in a folder, to stream copy the 1st audio stream (assuming they are all AC3) . (The name of the file.avi will be used for the audio e.g. it will become file.ac3 , file10.avi will have file10.ac3 as the stream copy )

As a batch file


for %%a in ("*.avi") do ffmpeg -i "%%a" -vn -c:a copy "%%~na.ac3"
pause




To do it from the command line instead, just replace "%%" with a single "%" for each instance



for %a in ("*.avi") do ffmpeg -i "%a" -vn -c:a copy "%~na.ac3"

cr0n=0sTT88
15th April 2014, 19:24
so did you want 3 audio tracks then (2 original audio, adding the extracted audio? ) ?

yes, exactly. I have 2 audio tracks in the original video file and I want add another audio track to the video file from the extracted audio.


You're better off using mkvtoolnix IMO, because ffmpeg can sometimes drop some of the subs and/or chapters - I'm assuming you want to keep everything intact


yes, I want to keep everything intact.
Ok, I need use kmvtoonix IMO. if i use ffmpeg is possible get any errors.

So i will try it with this code and if i get any problems I will search information for do it with mkvtoolnix IMO.

Sorry for my english!
thank you for all!!!

cr0n=0sTT88
15th April 2014, 19:37
for %a in ("*.avi") do ffmpeg -i "%a" -vn -c:a copy "%~na.ac3"



sorry, one more thing.

this code is only for extract the audio track of the avi video of all videos of the folder. I try it and works very fine.

but now I need insert this audio tracks into the mkv files.

sorry i'm not understand very well before. you say before that is better do it this only with mkvtool. ok.

do you know what is the code for do it in bath mode withe mkvtool?? :P

sorry for the stupid questions... my english is very basic.
Thanks for your patience!!

poisondeathray
15th April 2014, 19:43
Yes , the ffmpeg command is just to extract the audio

To remux the mkv, you would need mkvmerge.exe, or use the GUI mkvtoolnix . I don' t know the commandline to do this operation for keeping all your subs, audio, chapters but someone else might. If it's just 10 files, you can do it with mkvtoolnix, the GUI (just checkmark the streams you want to keep) - it's not too much work

cr0n=0sTT88
15th April 2014, 19:49
Yes , the ffmpeg command is just to extract the audio

To remux the mkv, you would need mkvmerge.exe, or use the GUI mkvtoolnix . I don' t know the commandline to do this operation for keeping all your subs, audio, chapters but someone else might. If it's just 10 files, you can do it with mkvtoolnix, the GUI (just checkmark the streams you want to keep) - it's not too much work

ok! thank you!!!

one more thing...

if i want encode the extracted audio files to another format what is the code for do it this in bath mode??

if all audio files are in mpeg2 and i want convert to AAC for example, is it possible???

thank you another time!!!

poisondeathray
15th April 2014, 19:53
ok! thank you!!!

one more thing...

if i want encode the extracted audio files to another format what is the code for do it this in bath mode??

if all audio files are in mpeg2 and i want convert to AAC for example, is it possible???

thank you another time!!!

Yes, you just change the commandline
-c:a copy means stream copy audio

-c:a libvo_aacenc -b:a 128k would use libvo_aacenc as the aac encoder , at 128kbps (some ffmpeg builds might be compiled with different aac encoders; e.g .they might use ctaac, or libfdk_aac - you have to check) , and you have to change the output extension (it would be "%~na.aac" instead of "%~na.ac3")

If the input file is not *.AVI , but was *.MPG then change that
e.g for %a in ("*.avi") would become for %a in ("*.mpg")

cr0n=0sTT88
15th April 2014, 20:06
Yes, you just change the commandline
-c:a copy means stream copy audio

-c:a libvo_aacenc -b:a 128k would use libvo_aacenc as the aac encoder , at 128kbps (some ffmpeg builds might be compiled with different aac encoders; e.g .they might use ctaac, or libfdk_aac - you have to check)

If the input file is not *.AVI , but was *.MPG then change that
e.g for %a in ("*.avi") would become for %a in ("*.mpg")


ok, so it this:

for one file (if i want better quality) (is mpeg audio format):

ffmpeg -i input.mpeg -vn -c:a libvo_aacenc -b:a 256k output.aac

and in batch mode (is mpeg audio format):

for %a in ("*.mpeg") do ffmpeg -i "%a" -vn -c:a libvo_aacenc -b:a 256k "%~na.aac"

i try it and seems that works! you are the best!!!
many thanks!!

therube
18th April 2014, 21:27
(if i want better quality)

Any time you transcode, which is what you're doing there, you will loose quality.

The best quality, based upon your given source, is going to extract, directly, what is there.

cr0n=0sTT88
18th April 2014, 21:35
Any time you transcode, which is what you're doing there, you will loose quality.

The best quality, based upon your given source, is going to extract, directly, what is there.

you are right. It is true!

I know this. I only transcode when I need save memory space :)