Prayalankar
Prayalankar

Reputation: 198

Extracted audio from video files is too large

I am trying to extract audio from the video files. I have tried libraries like moviepy, ffmpeg in python. The extracted audio files are too large in size. For an audio file of size 75 MB the audio file is of around 1.1 GB from moviepy. Even with bit rate of 16 kbps and sample rate to 16000 Hz extracted file is coming as 200 MB in size. Any other libraries or the way by which extracted audio files are atleast same size or less than complete video file.

'ffmpeg -i trial_copy.mp4 -ac 1 -ab 16000 -ar 16000 output.wav'

I am using above command in ffmpeg.

Upvotes: 1

Views: 2036

Answers (3)

llogan
llogan

Reputation: 134253

Extracted audio from video files is too large

You are outputting WAV. This is uncompressed, so it will ignore your bitrate (-ab), and will create larger files than the compressed audio in the input. See Wav audio file compression not working.

Any other libraries or the way by which extracted audio files are at least same size or less than complete video file.

You can extract the audio without re-encoding by using stream copy mode (-c copy):

ffmpeg -i input.mp4 -map 0:a -c copy output.m4a

File size will be the same because you are basically just copying and pasting the audio (re-muxing).

Upvotes: 4

furas
furas

Reputation: 143110

ffmpeg should install program ffprobe which can give information about file format used for audio in movie file.

ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "trial_copy.mp4"

for example opus

and then it can be used to copy audio from file without converting format

ffmpeg -v error -i "trial_copy.mp4" -vn -acodec copy "trial_copy.opus"

I use it as bash script called ffextract_audio

#!/bin/bash

# get codec name / audio file extension
# -v error 
#       : without extra info
# -select_streams a:0  
#       : check only audio stream
# -show_entries stream=codec_name  
#       : get codec_name
# -of default=noprint_wrappers=1:nokey=1 
#       : remove key name and wrappers 
# -i "$1"
#       : input file    
EXT=$(ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$1")
BASE=${1%.*}

echo output: $BASE.$EXT 

# extract audio from $1 and save in $2
# -v error 
#       : without extra info
# -i "$1"
#       : input file
# -vn
#       : without video
# -acodec copy
#       : copy audio (doesn't change codec)
# "$1.$EXT"
#       : output file with extra extension
ffmpeg -v error  -i "$1" -vn -acodec copy "$BASE.$EXT"

Using

ffextrac_audio trial_copy.mp4

I can get ie.

trial_copy.opus

Upvotes: 1

Yixin Liu
Yixin Liu

Reputation: 38

Try use it, https://sourceforge.net/projects/gmkvextractgui/

or

ffmpeg -i trial_copy.mp4 -f s16le -ar 16000 output.wav

Upvotes: 0

Related Questions