03. November 2015 · Comments Off on Concatenating Audio Files in Windows with FFmpeg · Categories: Audio, Command-line Tools, Multimedia · Tags: batch files, ffmpeg
Last updated on 09/23/2021

This guide demonstrates how to automate concatenating two or more audio files of the same format using FFmpeg while preserving the metadata in the merged file. A tested example batch file is provided to help illustrate. This guide is related to a previous post for concatenating audio files also with a batch file, but with using a different set of command-line tools for joining them.

clapper board

What is FFmpeg?

FFmpeg is an open-source and cross-platform command-line set of SW programs for recording, converting and streaming audio and video. First developed under Linux, compiled versions are available for most operating systems and platforms. It has since become one of the best-known and most widely used products of its type. FFmpeg is compatible with a large number of SW applications and it’s used in many popular SW products such as VLC Media Player, YouTube, and Handbrake. Although FFmpeg includes over 100 codecs and a mind-boggling number of possible combined command-line options, it’s not that difficult to use.

To demonstrate how easy it can be, FFmpeg.org provides this example command for converting input.mp4 to output.avi on its homepage:

$ ffmpeg -i input.mp4 output.avi

While the above example is simple, FFmpeg commands can also be more complex.

Main FFmpeg Tools

The FFmpeg version used for this guide is a Windows complied version availiable from CODEX FFMPEG. Simply download the latest 32 or 64-bit static build from the builds page here and extract it to a folder (builds are compressed in 7z format). The version used was git-dee7440 (2015-11-01).

The FFmpeg package contains the following three main executable tools in the bin folder:

  • ffmpeg.exe – a command-line encoder and media converter
  • ffmprobe.exe – a command-line tool to analyze and display media information
  • ffplay.exe – a simple media player

Note that there are a number of commands that are common between the three tools. Only ffmpeg.exe and ffmprobe.exe are used in this guide.

FFmpeg Help Files

FFmpeg provides three levels of help files: basic, long, and full. To view the commands available in the help files, click the ff-prompt.bat file in the root directory to open a command window or open your own in the bin folder and type in one of the following commands:

ffmpeg -h -- print basic options
ffmpeg -h long -- print more options
ffmpeg -h full -- print all options (including all format and codec specific options, very long

Here are links to the basic help file: ffmpeg_help and the full help file: ffmpeg_help_full. When printed to text, the help file sizes are: 5kB for the basic, 25kB for the full, and 487kB for the long help files. The long help file contains about 7,000 lines, which provides a hint as to how many commands are available.

Batch File

Batch file link: tasks_FFmpeg.bat

The link for the batch file used for this guide is provided above. Be sure to remove the txt extension before using it. The batch file is setup to work by the drag and drop method only.

To concatenate the audio files and write the metadata to the merged file, the batch file steps through the following:

  1. Delete any previous metadata text files, listfiles, or json data files.
  2. Write metadata for each audio file to a separate metadata text file
  3. Write the filenames of the audio files to confiles.txt (see below format), a listfile FFmpeg uses to identify the audio files to concatenate
  4. Concatenate the audio files and write the metadata from the first audio file’s metadata.txt file to the joined audio file.

For FFmpeg to use a listfile (confiles.txt), the filenames must be written to the confiles.txt file on separate lines using the following format.

file 'filename1.ext'
file 'filename2.ext'

The provided batch script should work for most audio formats of the same type provided they were encoded using the same codec (although they can be different containers). It was tested with opus, mp3, and aac files on a PC running Windows XP.

The batch script also provides options to separately print out audio file metadata, basic data, or stream and container (format) data to screen or to a file in json format (human readable form), with options to change the format in the script.

Command-Line Description

The main FFmpeg commands for extracting the metadata and concatenating the audio files are explained below. Although the ffprobe command was also used, it’s fairly simple to understand and should be self-explanatory by examining the code and the help files. The filenames used below are not actually in the batch script but have been simplified for explaination purposes.

The below command extracts and writes the metadata to a text file:

ffmpeg -i infile.ext -f ffmetadata metadatafile1.txt
  • ffmpeg – calls ffmpeg
  • -i infile.ext – specifies infile.ext as an input file
  • -f ffmetadata metadatafile1.txt  – formats the metadata to file metadatafile1.txt

The metadata1.txt file is formatted as below:

;FFMETADATA1
album=Name of Album
artist=Artist Name
genre=Music Genre Name
title=Title Name
track=Track #
date=Date
encoder=Encoder Used

The next command is used to process mp3 files only. It concatenates the mp3 files and writes the metadatafile1.txt contents in id3 format of the first mp3 file to the merged mp3 file:

ffmpeg -f concat -i confiles.txt -i metadatafile1.txt -map_metadata 1 -id3v2_version 3 -write_id3v1 1 -c copy filename1_merged.mp3
  • ffmpeg – calls ffmpeg
  • -f concat -i confiles.txt – use concat demuxer to concatenate the mp3 files listed in confiles.txt (treats confiiles.txt as a single file and specifies it as input file 0)
  • -i metadatafile1.txt – specify metadatafile1.txt as input file 1
  • -map_metadata 1 – map input file 1 as the source for metadata (metadatafile1.txt)
  • -id3v2_version 3 – select ID3v2 version 3 to write
  • -write_id3v1 1 – enable ID3v1 writing
  • -c copy filename1_merged.mp3 – stream copy to filename1_merged.mp3 (-c copy = stream copy)

The next command listed processes audio files other than mp3. It functions the same as the previous command but writes standard metadata (if present) from the first audio file to the merged file:

ffmpeg -f concat -i confiles.txt -i metadatafile1.txt -map_metadata 1 -c copy filename1_merged.ext
  • ffmpeg – calls ffmpeg
  • -f concat -i confiles.txt – use concat demuxer to concatenate the files listed in confiles.txt (treats confiiles.txt as a single file and specifies it as input file 0)
  • -i metadatafile1.txt – specify metadatafile1.txt as input file 1
  • -map_metadata 1 – map input file 1 as the source for metadata (metadatafile1.txt)
  • -c copy filename1_merged.mp3 – stream copy to filename1_merged.ext (-c copy = stream copy)

Additional Help – Online Command-line Generators

There are a number of online FFmpeg command-line generators that can help construct various audio and video FFmpeg commands. A few of them are listed below:

FFmpeg Command Generator

References:

Useful FFmpeg Commands

Concatenating media files

FFprobeTips

FFmpeg & FFprobe Cheatsheet

FFmpeg Windows Binaries:

CodexFFMpeg

BtbN / FFmpeg-Builds

 

Print Friendly, PDF & Email
Share
14. March 2015 · Comments Off on Automate mp3 File Concatenation with Windows Command-line Tools · Categories: Audio, Command-line Tools, Windows · Tags: batch files
Last updated on 12/12/2022

Although it requires a bit more technical effort than GUI-based applications, merging mp3 files with the command-line allows for a faster and more complete merging process and more flexibility and customization options. This guide demonstrates how to use a batch file and free Windows command-line tools to concatenate two or more mp3 files, preserve the ID3 metadata, and repair and verify the integrity of the combined file. The information in this guide was tested on system running XP SP3 32-bit and should be similar for other Windows versions.

merging mp3s

Command-line vs GUI tools

Command-line tools generally provide more options than GUI-based tools and that’s especially true for tools working with complex SW such as media files, which can be created with many different types of codecs, containers, and formats. Most GUI-based tools use command-line tools on the back-end, but GUIs are rarely able to incorporate all the possible combinations of complex commands and options of those tools into their designs. It’s difficult to design GUI’s that can accomplish difficult tasks and still be easy to use. Because GUI-based application designs are often driven primarily for ease-of-use and wide appeal, functionality and complexity are necessarily reduced in order to accomplish those goals. Command-line tools are the opposite, they are more difficult to learn and to use, but are generally able to accomplish a wider and more sophisticated range of tasks.

Command-line

Advantages – faster execution, specialized tasks can be accomplished by executing a single script, flexibility/customization (adding tools, changing options, etc.), free, uses less system resources

Disadvantages– requires coding or understanding code, takes more time and effort to configure, less intuitive

GUI-based

Advantages – quicker learning curve, more intuitive visually and for multitasking, more complete viewing and listing of information, easier switching between commands

Disadvantages – slower execution (additional programs are often required  for processing ID3 tags or to repair VBR headers), requires more system resources (video, drivers, mouse, etc.), limited options for advanced tasks (especially for free versions), limited availability of easy-to-use but highly configurable applicaions

Command-line Tools for this Guide

The command-line tools used in this guide are:

MP3Wrap (ver 0.5) – Wraps two or more mp3 files into a single file. The command-line executable is mp3wrap.exe.

ID3 mass tagger (ver 0.78) – Copies the ID3 tag to the merged file. This is the download link for the older freeware version, which is the version used in this guide. A newer version (1.21.25) is available here for both 32-bit and 64-bit systems, but it non-free shareware. It includes a GUI and a command-line version.

MP3Val (ver 0.1.8) – Validates and fixes MPEG stream, frame, and header errors. Includes both GUI and command-line versions. The command-line executable is mp3val.exe.

Because MP3Wrap strips and replaces the ID3 tags with its own information, ID3 is used to copy the tags from one of the files. MP3Val repairs any errors in the pre-merged files copied into the merged file or produced during the merging process.

Command-line Examples:

Command-line syntax useage for this guide and in the batch script:

Merge Files

The batch file provides an option to use either the Windows command-line or MP3wrap to merge the files.

The command to merge mp3 files with Windows command-line:

copy /b file1.mp3+file2.mp3+file3.mp3 outputfile.mp3

/b = binary file

Command to merge mp3 files with MP3wrap:

mp3wrap outputfile.mp3 file1.mp3 file2.mp3 file3.mp3

additional commands for MP3Wrap (ver 0.5): mp3wrap_cmd_help:

Copy Tags

The command-line syntax to copy the ID3 tags from input file1 to the output file with ID3:

id3.exe -D file1.mp3 outputfile.mp3

-D = duplicate tags from filename

additional commands for ID3 (ver 0.78): id3_078_help

Fix and Validate

Command-line syntax to fix and validate the output file with MP3Val:

mp3val outputfile.mp3 -f -nb -si

-f = try to fix errors

-nb = delete .bak files (suitable with -f)

-si = suppress INFO messages

additional commands for MP3Val (ver 0.1.8): mp3val_cmd_help

Merging mp3 Files: Process

Steps

If using the provided batch file (see below), two steps are required.

1. Prepare the mp3 files

Ensure that the mp3 files to be merged have the same frequency, bitrate, and MPEG coding and layering. Otherwise, the output file may contain non-apparent errors, even if no errors were displayed during the merging process.

2. Drag and drop the mp3 files onto the batch file to merge

Drag and drop the mp3 files all at once and in the order to be processed by the batch script. Rename/renumber the files as necessary to obtain the right order.

Batch File Processing Steps:

  1. Display the order of the mp3 files to be processed
  2. Ask the user to select between merging the files with the Windows command-line or MP3Wrap
  3. Merge the mp3 files into a temp file, “temp_MP3WRAP.mp3”
  4. Transfer the ID3 tags from the first mp3 file to the temp file with ID3
  5. Fix and validate the temp file with MP3Val
  6. Rename the temp file to the first mp3 file and append “_merged” to the file name
  7. Exit

Example Batch File:

Ensure that the file extension is changed to “bat” before using.

mergeMP3_cects.bat

References:

blogferret.com – id3.exe – ideal tool for tagging and renaming MP3 files

alexenglish.info – Concatenating MP3 Files in Linux

cephas.net – Merge multiples MP3 files into one

ghacks.net – ID3 Mass Tagger

Print Friendly, PDF & Email
Share
13. September 2014 · Comments Off on Retrieve and Embed Cover Art into Audio Files · Categories: Audio, TechBits · Tags: Audio
Last updated on 09/19/2019

bluenotegreen notemusic folder

Note (11/2017): DiscoverArt no longer appears to be available. Instead, use the Album Art Downloader option below.

Useful information from Tinyapps.org that shows how to retrieve and embed cover art into audio files with MP3Tag and the command-line application DisCoverArt. The original Tinyapps blog post is reproduced in its entirety below:

Batch download and embed album cover art #

If you have a huge MP3 collection and just want to batch download and embed cover art without verifying each cover individually (and iTunes’ “Get Album Artwork” is insufficient):

  1. Download and install Mp3tag
  2. Download DisCoverArt and unzip contents to the Mp3tag program directory (e.g., C:\Program Files (x86)\Mp3tag)
  3. Open an elevated command prompt and cd to the Mp3tag program directory
  4. Run regsvr32 custommsgbox.dll and click OK when the success dialog appears
  5. Open Mp3tag
  6. File > Add directory… > navigate to your music folder > Select Folder
  7. Create a new tool:
    1. Tools > Options > Tools
    2. Click the New (yellow star) button
    3. Name: DisCoverArt Google 300×300 Artist+Title NoQuotes
    4. Path: Browse to the Mp3tag program directory and select DisCoverArt.exe
    5. Parameter: “%artist%” “%title%” -discomusic.com 0 1 300 300 jpg 1 1
    6. Check “for all selected files” > OK > OK
  8. Create a new action:
    1. Actions > Actions (you need to select at least one song in the main interface for this menu item to be available)
    2. Click the New (yellow star) button
    3. Name of action group: Save Coverart
    4. Click OK > click the New button again
    5. Select action type: Import Cover From File > OK
    6. Format string for image filename: %artist% – %title%.jpg
    7. Import cover as: Front Cover
    8. Check “Delete existing cover art” > OK > OK > Close
  9. Right click on column header > Customize columns… > check “Cover” > click “Move up” until it is at or near the top of the list
  10. Click the Cover column to sort
  11. Select all files without an entry in the Cover column (the author recommends selecting no more than 300 at a time to avoid problems)
  12. Right click on highlighted files and click Tools > DisCoverArt Google 300×300 Artist+Title NoQuotes
  13. Wait for all console windows to close
  14. Actions > Actions (Quick) > “Import cover from file” > OK
  15. Format string for image filename: %artist% – %title%.jpg
  16. Import cover as: Front Cover
  17. Check “Delete existing cover art” > OK > OK
  18. Close Mp3tag
  19. Getting the artwork to show up in iTunes:
    1. Open iTunes and click “Albums”
    2. Edit > Select All > Right click > click “Uncheck Selection” (album covers will appear)
    3. Edit > Select All > Right click > “Check Selection”

Another option is to download cover art with Album Art Downloader and embed it with Mp3tag:

  1. Download and run Album Art Downloader
  2. Select File -> New -> File Browser…
  3. Enter path to music directory under “Search for audio files in:”
  4. Click Search
  5. Click “Select all albums with missing artwork”
  6. Click “Get Artwork for Selection…”
  7. Click “Automatically download and save results for the remaining queued searches”
  8. Click “Download and save results automatically”
  9. Click “Start”
  10. When the process is complete, embed the album art with Mp3tag by starting with step 14 above. The only change is in step 15, where you’ll need to use Folder.jpg as the format string.

 

Source: Tinyapps.org

 

Print Friendly, PDF & Email
Share
advertise
">Bear

Bad Behavior has blocked 1917 access attempts in the last 7 days.

Private help