How to convert an MP3 file to an Ogg Opus file? - converters

Is there a converter that can convert MP3 files to Ogg Opus?
Can you recommend one that can do it?
So far I've tried Adobe Audition, Xilisoft Audio Converter Pro, WinAVI Video Converter, and Aimersoft Video Converter Pro. None of them was useful.

The easiest option is a command like this
ffmpeg -i input.mp3 -c:a libopus output.opus
But there is a selection of parameters you can tweak, all documented here.
E.g. I use the following command to compress audiobooks/podcasts (the resulting ~32 kbps OPUS files sound indistinguishable from 192 kbps MP3):
ffmpeg -i input.mp3 -c:a libopus -b:a 32k -vbr on -compression_level 10 -frame_duration 60 -application voip output.opus
-b:a 32k sets bitrate to 32 kbps (or about 35 kbps in case of VBR), it can be reasonable to use 128k to compress music given a lossless (or a 320k MP3) original or 64k to compress music given a 192k MP3 original
-vbr on turns variable bitrate mode on (may increase quality at cost of a using some additional kbits for some seconds)
-compression_level 10 commands to favour quality over compression speed
-frame_duration 60 increases quality at cost of 40 additional milliseconds of latency
-application voip asks to do the best possible to save speech intelligibility, use -application audio for music
You can convert a set of many files this way in bash:
for f in *.mp3; do ffmpeg -i "$f" -c:a libopus "${f%.*}.opus"; done

Convert MP3 files in all subfolders recursively and utilizing all CPU
NOTE: FFmpeg multithread -thread n argument is ignored when encoding OPUS files.
Preparing
Install GNU parallel, FFmpeg, and MP3 with Opus codecs
sudo apt install -y parallel ffmpeg libmp3lame libopus
Usage
Recursive and using all CPUs:
find -iname "*.mp3" -type f Find all MP3 files in whole directory
parallel -I% --max-args 1 Prepare parallel to use % char as argument for file path saving
-c:a opus Set OPUS as encoder
-strict -2 Enable FFmpeg to work with OPUS encoder
-b:a 128K -vbr on Set OPUS at 128 KB/s (VBR) that is enough to store stereo music
-map_metadata 0 Copy tags from MP3 to OPUS file
-compression_level 10 Favour quality over compression speed
-y Overwrite OPUS file if already exists
touch -r % %.opus Use MP3 file's times instead of newly created files
rm -vf % Remove MP3 file
find -iname "*.mp3" -type f | parallel -I% --max-args 1 \
"ffmpeg -i % -strict -2 -c:a opus -b:a 128K -vbr on -map_metadata 0 -compression_level 10 -y %.opus;touch -r % %.opus;rm -vf %"
NOTE: Don't use -frame_duration argument for mixing audio purposes

Try ffmpeg with -acodec libopus

Related

Ffmpeg makes audio longer when changing bitrate

I've been using ffmpeg convert audio from one format to another and to change audio's bitrate. When I try to convert aac audio to mp3 audio using the command:
ffmpeg -i SomeAudio.aac -c:a mp3 -b:a 128k SomeOutputPath.mp3
everything works correctly and output audio is of the same length as the input audio (6 minutes, 15 seconds).
However, when I try converting it to aac audio using a similar command:
ffmpeg -i SomeAudio.aac -c:a aac -b:a 128k SomeOutputPath.aac
it makes the output audio longer (around 10 minutes). I have tried specifying output length but that still makes the video longer, it just cuts of part of the audio:
ffmpeg -i SomeAudio.aac -c:a aac -b:a 128k -t 00:06:15 SomeOutputPath.aac
Here is a link to the screenshot:
My suspicion is that message "Estimating duration from bitrate, this may be innacurate" (the one in the screenshot) is the root of my problem but I just haven't been able to find any useful information about it on the web.
Thanks a lot for any help in advance :)
The duration shown for raw AAC is a guess because it does not contain duration info. You can find the actual duration with:
ffmpeg -i input.aac -f null -
Or a faster, "close enough" method:
ffmpeg -i input.aac -c copy -f null -
Workaround is to remux to M4A:
ffmpeg -i input.aac -c copy output.m4a

Recording streams audio with ffmpeg for Cloud Speech-to-Text

Goodnight
I am trying to record audio with the following features:
codec: flac
sampling rate: 16000hz
I am testing with the following line of code:
ffmpeg -t 15 -i http://198.15.86.218:9436/stream -codec:a flac -b:a 16k example.flac
But when reviewing the output file, I get the following:
codec: flac
sampling rate: 44000hz
I could guide the correct use of ffmpeg options.
-b:a is to set the bitrate*. For sampling rate, you have to use -ar.
Use
ffmpeg -t 15 -i http://198.15.86.218:9436/stream -codec:a flac -ar 16k example.flac
*for a lossless codec, bitrate setting is irrelevant.
"Free Lossless Audio Codec" Flac is lossless and hence output bit-rate cannot be controlled precisely. -b:a 16k is actually trying to set output bit-rate of audio to 16k bits per second.
While in your case you need it to be sampled at 16000 Hz. So the correct option would be to use -ar [audio rate]
ffmpeg -t 15 -i http://198.15.86.218:9436/stream -c:a flac -ar 16000 example.flac
If you want to control the output bit-rate with FLAC encoder then you can use the option -compression_level 0-15 with 5 being default. You can get mode details on controlling other parameters of FLAC ffmpeg encoder here.

Wav audio file compression not working

Is it possible to compress a wav audio file without reducing the sampling rate?
I have an audio file with 256 bit rate and sampling rate - 8000Hz. I would just like to reduce the bit rate to 128/64 kbs
I tried converting to mp3 and back to wav,
ffmpeg -i input.wav 1.mp3
ffmpeg -i "1.mp3" -acodec pcm_s16le -ar 4000 out.wav
but this reduced sampling rate as well.
ffmpeg -i "1.mp3" -acodec pcm_s16le -ab 128 out.wav has default 256 bit rate
PCM (WAV) is uncompressed, so -b:a/-ab is ignored.
The bitrate of WAV is directly affected by the sample rate, channel layout, and bits per sample.
Calculating PCM/WAV bitrate
Assuming 8000 samples per second, stereo channel layout, 16 bits per sample:
sample rate × number of channels × bits per sample = bitrate
8000 × 2 × 16 = 256000 bits/s, or 256 kb/s
Getting channels, sample rate, bit depth
You can just view the output of ffmpeg -i input.wav or use ffprobe for a more concise output:
$ ffprobe -loglevel error -select_streams a -show_entries stream=sample_rate,channels,bits_per_sample -of default=nw=1 input.wav
sample_rate=8000
channels=2
bits_per_sample=16
Changing the bitrate
Bitrate should not be a consideration when using WAV. If bitrate is a problem then WAV is the wrong choice for you. That being said, you can change the bitrate by changing:
The sample rate (-ar)
The number of channels (-ac)
The bit depth. For PCM/WAV the bit depth is the number listed in the encoder name: -c:a pcm_s24le, -c:a pcm_s16le, -c:a pcm_u8, etc. See ffmpeg -encoders.
Examples for 128 kb/s (this will probably sound bad):
ffmpeg -i input.wav -ar 8000 -ac 1 -c:a pcm_s16le output.wav
ffmpeg -i input.wav -ar 8000 -ac 2 -c:a pcm_s8 output.wav
Another option is to use a lossless compressed format. The quality will be the same as WAV but the file size can be significantly smaller. Example for FLAC:
$ ffmpeg -i audio.wav audio.flac
$ ls -alh audio.wav audio.flac
6.1M audio.flac
11M audio.wac
I usually do this using Audacity
1) import the wav file to audacity
2) Then File>Export
3) Choose "Constant" and then from the Quality drop-down select your required bit-rate
I haven't tried that with ffmpeg, but the command should be:
ffmpeg -i input.wav -ab 64000 output.wav

Getting the original video quality while converting in ffmpeg

In my site, having upload video(only mp4 videos) functionality and then to combine. For the combining i used Mp4Box, If we want combine all the mp4 video, those videos have to same dimesions,bitrate,codecs,samplerate,etc, So while uploading the mp4 videos itself we set the constant dimension and other details like
ffmpeg -i test.mp4 -r 25 -s 640x360 -ar 48000 -acodec copy -f mp4 -vcodec libx264 -vpre default -async 1 -strict -2 -qscale 10 test.mp4
After using this command the video quality will loss fro the original video, Kindly suggest any solution?
Add
-qp 0
§ Lossless H.264

Lossless ffmpeg conversion/encoding

I'm looking for the best in quality when converting videos.
I only want to use lossless audio and video encoders and a good container.
How do I enable lossless x264 vcodec for ffmpeg?
I currently use ffmpeg -i "inputvideo" -s 1280x720 -ar 48000 -threads 4 -vcodec libx264 -acodec copy -dsur_mode 2 -ac 6 "outputvideo720p.mkv"
I plan on using flac for the acodec by am unsure because I don't want to use quality if it switches to 16-bit instead of 24-bit
You can use x264 in lossless manner I think. As in here and here use these flags for ffmpeg:
ffmpeg -i input.avi -c:v libx264 -qp 0 output.mkv
In case you couldn't load libx264, remove ffmpeg and install from source with x264 enabled. Here is how to.

Resources