Technical Tips for Everyday Computing
Where do I paste the code that I find on the internet
Source: Ron de Bruin Excel Automation
42+ Text-Editing Keyboard Shortcuts That Work Almost Everywhere
Source: How-to Geek
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.
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.
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:
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 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 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:
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.
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
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
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
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:
Command-line utilities are useful for expanding the capabilities of batch files. There are many more available, but the below list can be used as a starting point.
Name | Description | Source | Size Uncompressed (kB) | More info/License |
---|---|---|---|---|
BusyBox | A single binary with many common Unix tools. Often used in embedded Linux systems. Fewer options than originals due to size optimization | Ron Yorston | 647k | GNU General Public License |
BYTE* / FREEWARE Tools | Over twenty-five mostly system admin tools | BYTE* FREEWARE Tools | Most under 20k | Open-Source GNU GPL |
CyLog Software Command-Line Utilities | Ten utilities for string manipulation, searching, user input, and more | CyLog Software | 26-232k | Free (Proprietary License) |
DSToolBox | Twelve utilities | DreamCycle Studios | 40-158k | Freeware |
F2KO Software | Over 40 utilities | CMD Tools | Various | Freeware |
Gammadyne's Free DOS Utilities | Sixteen various utilities including timers, file management tools, and a DOS shell | Gammadyne's Free DOS Utilities | 76-421k | Freeware |
GnuWin | Over 160 separately downloadable native Win32 open source utilities for Windows 2k-Win7 | GnuWin | Various | GNU General Public License |
Gow (Gnu On Windows) | Over 100 useful open source UNIX applications compiled as native win32 binaries | Brent Matzelle | 1-1795k | Open Source MIT License |
Gtools | Several command-line and GUI Windows Administrative Tools | gtools current version | 19- 520k | Open Source |
Hexatomium | About a dozen utilities | Windows Apps by FS1 | 12-320k | Free for personal use |
Horst Schaeffer's Software Pages | Several various utilities | CMD 32/64 bit | 4-35k | Freeware |
IntelliAdmin | About 10 useful command line utilities. Note that not every utility listed is a command line tool | Free Utilities | Various | Freeware |
Nircmd | A small command-line utility that can perform many different tasks | NirSoft | 43k | Freeware. 32 and 64 bit versions also available |
Ritchie Lawrence | A somewhat outdated (2005), but still useful list of command-line utilities | Ritchie Lawrence | Various | Mostly Freeware |
Rob nan der Woude's Scripting Pages | Descriptions and download links for a many utilities. Probably the most up-to-date and comprehensive listing of its kind | Batch Utilities | Various | Almost entirely Freeware |
RubyPdf Software Download Center | Specialized PDF Tools | Rubypdf Technologies | Up to a few MB | Mostly Freeware |
Small command line utilities | Over 150 system utilities. Archive package or separately. Page also has small GUI tools and NET utilities. | LTRData | 6-100k. Most under 20k | Freeware |
SwissFileKnife | Combines many functions into a single, portable executable | StahlWorks Technologies | 1,576k | BSD License. Binaries and source code available. Versions for Mac and Linux. |
SystemTools Utilities | A dozen utilities focusing on user account and networking tasks | SystemTools Software | Most under 50k | Freeware |
Util32 | Twenty 32-bit useful command-line utilities | Persoft | 23-180k | Freeware |
Uwe Sieber's Homepage | File, drive, USB and misc tools | Uwe Sieber's Homepage | Various | Freeware |
Bad Behavior has blocked 1004 access attempts in the last 7 days.
conditions