Merge mp3 files without recode and make cue sheet pointing to individual tracks? - linux

I have a lot audiobooks, each one is usually split into 20-60 files. It's not comfortable to navigate with audio players if I want to group them into some sets by genre (with [Album artist] ID3 tag set to "Various Artists").
Is there free windows or linux tool or set of tools, whose could do the following?
Merge the audiobook files to one mp3 without recoding
Carefully build correct CUE sheet with original ID3 tags pointing to former chapters inside new solid mp3 file.

You can easily join mp3 by simple concatenating them.
cat file1.mp3 file2.mp3 file3.mp3 file4.mp3 file5.mp3 > file-all.mp3
Tags can be extracted with ffprobe:
ffprobe file1.mp3
Cue sheets is text files, you can read about its format here:
https://en.wikipedia.org/wiki/Cue_sheet_(computing)
Since here questions related to programming, I will not post complete solution.

Don't use MP3, use Matroska (MKV). It supports all of these chapters and what not.
FFmpeg and mkvmerge are tools you can use for this. Use -c:a copy and the audio won't be re-encoded. (MKV support MP3 as a codec.)

Related

Incorrect values for song length (duration) in Mp3tag after ffmpeg FLAC to MP3 conversion

The problem
As per this post, I use the following command to convert a flac file to mp3 while keeping all metadata:
ffmpeg -i input.flac -ab 320k -map_metadata 0 -id3v2_version 3 output.mp3
When inspecting the converted mp3 file by right-clicking it, going to properties and then details, everything looks in order. The value for "Length" is correct.
When inspecting the converted mp3 file with Mp3tag, the value for "Length" is different. From my testing, the "Length" value is consistently about 28% of what it is supposed to be.
Normally, this isn't an issue. Most music players I use, read the correct length value, same as Windows. However, I've recently discovered that Spotify Mobile for some reason ignores the length value that can be seen in the Windows panel and uses the one that can be seen in Mp3tag.
I want to figure out what command I should use so that after the flac file has been converted to mp3, Mp3tag shows the correct length, and there by, Spotify Mobile reads the correct length as well.
What I have tried
1.
After converting the file to Mp3, I've tried reencoding the mp3 file into a... mp3 file using the following command:
ffmpeg -i original.mp3 -c:v copy -c:a mp3 -vn -ar 44100 -ac 2 -b:a 320k copy.mp3
As can be seen in the image above, this fixes the issue and the length is showing correctly in Mp3tag and in Spotify Mobile.
Issues with this: Reencoding reduces quality and I don't know how to combine the previous flac conversion command and this one into one line.
2.
I tried https://cloudconvert.com/flac-to-mp3 and it worked. The length is displayed correctly in Mp3tag. (What commands did they use on the server???)
Issues with this: I don't want to rely on a cloud service for conversion, I have a lot of files to convert and I'd prefer it to be done locally.
Some demo files
Here is a folder with a flac file, a bad mp3 file (wrong length) and a good mp3 file. It looks like if you preview the music in google drive, it also plays the wrong length for the bad mp3 (39s not 2m19s), while vlc, groove player, spotify (desktop not mobile) all play the correct full length (2m19s) for the bad mp3 file.
Folder: here's the link
It seems I had an outdated version of ffmpeg... (ffmpeg version git-2020-05-23-26b4509) I updated to the latest version and the issue went away. Learned my lesson the hard way.
Would still appreciate an explanation on why this was happening. I'm curious. Why were there two values for length?

Creating Batch Spectrograms Using FFMPEG?

So I am wanting to create spectrograms using the FFMPEG for thousands of FLAC files in batch.
I am using the following for just one file.
ffmpeg -i audio-in.wav -lavfi showspectrumpic image-out.png
However, I would like to do this for all the files in a certain folder (\Desktop\FLACfiles) and don't want to keep changing the file name and the image output name.
I would like to somehow create a batch script in Windows 10 that automatically creates a spectrogram based on the filename.
I was trying to make it work but I don't have much experience via command line or programming in general. Not sure how to do achieve this.
Simply put, would like to use commands from a working directory containing FLAC files and create a spectrogram for each file matching the filename.
This worked for me using mp3 files but it wasn't fast. Someone may have a better solution. Try this as a bat file.
for %%a in ("*.mp3") do ffmpeg -i "%%a" -lavfi showspectrumpic "%%~na .png"

Joining MP3's via commandline with background track

I'm already taking advatage of two command line utilities. I'm using ffmpeg to convert m4a to mp3, and then I'm combining a few mp3's into one large one using mp3wrap. The resulting file is something like this:
BackgroundMusic.mp3 > Audio1.mp3 > Audio2.mp3
I need something more like
Audio1.mp3 > Audio2.mp3
|_____________________|
|
BackgroundMusic.mp3
To where the background music runs continuously in the background. Would be nice to be able to change the volume of each track too.
Does anyone know a command line program like mp3wrap but can also add in a background track?
I will not be able to use a GUI program such as Audacity, as all of this will be automated on the server.
Thanks!
You can do this with FFmpeg alone.
ffmpeg -i input_audio1 -i input_audio2 -i input_background_audio -filter_complex "
aevalsrc=0:d=10[s1];
[0:a]volume=volume=0.1[volume0];
[1:a]volume=volume=0.1[volume1];
[2:a]volume=volume=0.1[volume2];
[s1][volume1]concat=n=2:v=0:a=1[ac1];
[volume0][ac1]amix=inputs=2[amixed1];
[amixed1][volume2]amix=inputs=2:duration=first" output_audio
You need to use filter_complex to chain all the filters that you are going to use for adjusting the volumes, silent spaces, concat, etc. filters.
As the first step you can concatenate two audio files that you need to play one after the other. To do that I have first created and silent audio using aevalsrc filter with the same duration as the first audio clip. Then use concat filter to concatenate silent audio and the second audio.
To adjust the audio I have used volume filter. You can adjust the volume values accordingly. To mix the audios you can use amix filter. You can specify duration attribute to get the first input which is [amixed1] duration. With that option you can stop the whole audio with the duration of audio1+audio2 without play it for the full duration of background audio duration.
Hope this helps!

iPhone App Dev - Edited mp3 files are not working in App

In my application there are mp3 files located in the bundle (nothing from the web). Some of the mp3 files are original files and some I had edited using simple sound editing software (the ones where you insert a file, cut a slice of it and save it as a new and shorter mp3 file).
I'm using the AVAudioPlayer [initWithData] method.
All the original files (the ones that I hadn't edited and inserted to the bundle as is) are working perfectly and all the ones that were edited are not working at all.
I used 2 different editing software and the outcome is the same.
Anyone had ever encountered that or have any idea what may I done wrong?
Thanks,
Ohad
Converting the mp3 to caf worked for me
as specified here.
see the following:
How do I convert an audio file to the preferred format for iPhone OS?
The preferred full-quality audio format for iPhone OS is 16-bit, little-endian, linear PCM packaged as a CAF file. To convert an audio file to this format, use the afconvert tool at the command line in Mac OS X, as shown in Listing 5.
Listing 5 Converting an audio file to the preferred format for iPhone OS
/usr/bin/afconvert -f caff -d LEI16 {INPUT} {OUTPUT}
To see all the options available for the afconvert tool, enter afconvert -h at the command line.

How can I mass rename many audio files?

I need to rename many audio files, so that their file names show artist and song name. File formats are mp3 and flac. Is there a way to do it quickly? Or maybe there is a program for this?
I've used MP3Tag for this in the past. You can batch rename via sprintf()-ish format strings that pull various bits from ID3 tags.
Some recommended tag editors:
en.wikipedia.org/wiki/Tag_editor
I just used the Java-based Entagged, which is really simple and smart, so I can recommend it:
Entagged

Resources