I am trying to convert few .wav files to .mp3 format
The desired .mp3 format is :
I tried with FFmpeg with this code :
ffmpeg -i input.wav -vn -ac 2 -b:a 160k output1.mp3
This is the output of this command on one .wav format
I am getting the result but two things are different
Overall bit rate mode and Writing library
Writing library: LAME3.99.5 vs LAME3.100 ( I think this shouldn't
make any problem?)
bit rate mode Constant Vs variable
How to change bit rate mode from variable to Constant? and do I need to convert using the same Writing library?
Thanks!
The output using ffmpeg -i input.wav -vn -ac 2 -b:a 160k output1.mp3 is constant bit rate, however ffmpeg writes a header with the title Xing and Mediainfo infers that to indicate VBR. Disable writing that header if you want Mediainfo to detect Constant bit rate.
ffmpeg -i input.wav -vn -ac 2 -b:a 160k -write_xing 0 output1.mp3
Note that the actual MP3 encoding won't change.
I ended up using sox instead of FFmpeg :
sox -t wav -r 48000 -b 16 -c 2 file.wav -C 160 -t mp3 sock33.mp3
Sample rate of 48 kHz (-r 48000)
two channel (-c 2)
16 bits bit depth (-b 16)
Related
I need to convert a 44KHz stero m4a audio file to 22KHz mono mp3 VBR file, how can I do that with ffmpeg on linux terminal? Thanks.
Gyan's comment is what I want, here is the full command line:
ffmpeg -i in.m4a -ac 1 -ar 22050 -c:a libmp3lame -q:a 9 out.mp3
with the option for VBR encoding. The number after -q:a specifies encoding quality (bitrate), with 0 being the best quality (largest file) and 9 being the worst quality (smallest file).
Here is the document on ffmpeg wiki.
I attempt to create a video slideshow from a number of image files and an audio file in 2 steps:
Create a temporary video file from a sequence of image files
Add an audio file to the temporary video file with a delay of 5 seconds
The audio file is an uncompressed stereo wav file, encoded with a sample rate of 44100 Hz and a bit depth of 32 bits, with a size of 40.1 MB. To preserve the lossless quality of the input audio file I use the option -c:a aac -b:a 192k as per Slideshow Wiki. However, the final output video file has a size of only 4.49 MB.
How can the output video file be about 10 times smaller than the input audio file and still preserve the original lossless quality?
My code:
ffmpeg -f concat -i slide-sequence.txt -c:v libx264 -r 30 -filter_complex format=yuv420p temp.mp4
ffmpeg -i temp.mp4 -i audio.wav -af "adelay=5000|5000" -c:v copy -c:a aac -b:a 192k out.mp4
How can the output video file be about 10 times smaller than the input audio file and still preserve the original lossless quality?
It does not. AAC is a lossy format. It uses encoding methods to make it sound good although it is lossy.
There are formats that are both compressed and lossless, such as FLAC. YouTube supports this, so use:
ffmpeg -i temp.mp4 -i audio.wav -af "adelay=5000|5000" -c:v copy -c:a flac out.mkv
Note the change of the output container format from MP4 to Matroska (.mkv). YouTube supports Matroska.
I have a MP4a file which I am looking to convert to WAV file, containing signed 16-bit PCM samples. I have ffmpeg at my disposal, and looking at previous SOF posts, I have tried:
ffmpeg -y -i input.mp4 -acodec pcm_s16le -f s16le -ac 1 -ar 16000 output.pcm
but, the program I use complains that this converted file has data in unknown format. I was wondering if anyone had any pointers on how to go from m4a to wav with pcm samples.
ffmpeg -i input.mp4 output.wav
This command will output WAV file containing signed 16-bit PCM samples. Your command is outputting raw PCM, not WAV.
You can add -c:a pcm_s16le output option if you prefer, but that's the default encoder for WAV so it can be omitted.
I have a MKV file with gaps in the audio. That is, there are gaps in the MKV audio track timestamps. According to "ffmpeg", the AC3 audio length is 802 seconds, but when exporting the audio to WAV, the resulting file length is 801'53 seconds. That is, the "exported" audio is shorter.
Triaging the issue with
ffmpeg -i INPUT.mkv -af ashowinfo -map 0:2 -y -frames:a XXXX -f alaw /dev/null
I can confirm that the length difference is consistent with gaps in the timestamps of the original audio frames. There are a handful of missing audio frames. I guess those are replaced by silence in the player.
The command I use to export the audio is:
ffmpeg -i INPUT.mkv -map 0:1 -ac 2 OUTPUT.wav
My question is: How can I instruct FFMPEG to preserve the gaps in the original audio, zero (silence) filled?. The WAV file duration should be the same than the original AC3 audio.
Given my current workflow, I would rather prefer to not keep the original timestamps in the output file but generate a WAV with (tiny) silences instead. I could consider keeping timestamps if there is no other choice, but this could be quite a pain in my workflow.
Advice? Help?
Thanks a lot in advance!
Use
ffmpeg -i INPUT.mkv -map 0:1 -af aresample=async=1 -ac 2 OUTPUT.wav
The aresample filter will insert silent samples within the gaps.
We want to convert 320kbps mp3 file to 128kbps mp3 so currently we are using below ffmpeg command but its not working.
ffmpeg -i input.mp3 -codec:a libmp3lame -qscale:a 5 output.mp3
Result:-the output bitrate same as input mp3.
And we are following the FFmpeg Encoding guideline for that here is the link :- https://trac.ffmpeg.org/wiki/Encode/MP3
so please suggest any solution.
I tried your shown command (tested on Windows / commandline) :
ffmpeg -i input.mp3 -codec:a libmp3lame -qscale:a 5 output.mp3
Result : It works for me. However the -qscale:a 5 makes FFmpeg decide on an average bitrate for you. With one (320k) MP3 file I got it giving a close convert of 134kbps. This is expected since :
lame option Average kbit/s Bitrate range kbit/s ffmpeg option
-V 5 130 120-150 -q:a 5
Solution :
Instead of making the internal mp3 frames hold different bitrates (that vary to acommodate the "current" perceived audio, eg: think "silent" parts using smaller rate of bits/bytes compared to "busy" audio parts), so just set a constant bitrate of 128kbps as you need.
I would just set it to constant 128kbps manually and explicitly with :
ffmpeg -i input.mp3 -codec:a libmp3lame -b:a 128k output.mp3
I use this shellscript in order to not visit this stackoverflow-page over and over again :)
#!/bin/bash
[[ ! -n $1 ]] && {
echo "Usage: mp3convert <input.mp3> <output.mp3> <bitrate:56/96/128/256> <channels> <samplerate>"
exit 0
}
set -x # print next command
ffmpeg -i "$1" -codec:a libmp3lame -b:a "$3"k -ac "$4" -ar $5 "$2"
Make sure your version of FFmpeg has libmp3lame enabled. The selected answer didn't work for me, but this did:
ffmpeg -v debug -i "input.mp3" -c:a libmp3lame \
-b:a 128k -ac 2 -ar 44100 -vn "output.mp3"
-ac 2 - output has 2 (stereo) audio channels
-ar 44100 - sample rate of 44100Hz, which is ideal for high quality music.
Although, in 2022 I wouldn't recommend converting to 128kbps since storage space is much more cheap and abundant nowadays.
I think -b:a 192k strikes the best balance between compression and quality for most people (unless you're an audiophile with $1000 headphones, and even then you'd be better off using FLAC anyways).