Audio Video Editing in Linux

This document describes various Audio video editing tools like ffmpeg, vlc in Linux . To handle youtube content refer to Youtube-dl .

Getting info about the media

Sometimes all you need to know is what’s inside the media container. While there are several tools that can do this, my preferred one is MediaInfo↗ . MediaInfo shows all the information inside a media container, for each of the different streams, as well as the metadata for the input file. This gives you everything you might want to know—and probably a bunch of stuff you didn’t.

Running the below command spits out a list of information about the input file in a human-readable form.

mediainfo inputFile.mkv

This is just scratching the surface of what FFmpeg can do. Luckily the documentation↗ for FFmpeg and the project’s other tools is very good and worth checking out. It’ll teach you all about the many different tricks this dog can do.

If you are after a tool with a graphical interface for converting multimedia, Handbrake↗ is an exceptionally good one available on Linux, Mac OS X, and Windows. Handbrake uses FFmpeg (among other tools) under the hood.

Source: https://opensource.com/article/17/6/ffmpeg-convert-media-file-formats↗

To view the number of frames in a file

When working with very high frame rate videos, to view the number of frames in a file:

ffprobe -select_streams v -show_streams input.avi | grep nb_frames
nb_frames=159697

https://superuser.com/questions/84631/how-do-i-get-the-number-of-frames-in-a-video-on-the-linux-command-line↗

To reduce the size of mp4 file

To test a process using a sample of file instead of an entire file, use the below time based option.

Use the following command:

ffmpeg -ss 0 -t 30 -i file.mp3 file.wav

-ss 0 - Start at 0 seconds -t 30 - Capture 30 seconds (from 0, so 0:00 - 0:30). file.mp3 - Input file file.wav - output file

If you want 1 minute of audio, use -t 60.

https://stackoverflow.com/questions/7945747/how-can-you-only-extract-30-seconds-of-audio-using-ffmpeg↗

Option 1:

Using H.265 format instead of H.264 can push the compression lever further by increasing the CRF value — add, say, 4 or 6, since a reasonable range for H.265 may be 24 to 30.

ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4

https://unix.stackexchange.com/questions/28803/how-can-i-reduce-a-videos-size-with-ffmpeg↗

Option 2:

Using the same technique as above, but with H.264 format itself:

Calculate the bitrate you need by dividing your target size (in bits) by the video length (in seconds). For example for a target size of 1 GB (one gigabyte, which is 8 gigabits) and 10 000 seconds of video (2 h 46 min 40 s), use a bitrate of 800 000 bit/s (800 kbit/s):

ffmpeg -i input.mp4 -b 800k output.mp4

Additional options that might be worth considering is setting the Constant Rate Factor, which lowers the average bit rate, but retains better quality. Vary the CRF between around 18 and 24 — the lower, the higher the bitrate.

ffmpeg -i input.mp4 -vcodec libx264 -crf 20 output.mp4

To merge 3 video files

The below command can be used, when no transcode is involved

vlc.exe file1.mp4 file2.mp4 file3.mp4 --sout
"#gather:std{access=file,dst=aadhiraiexperiment.mp4}" --sout-keep

To merge 3 audio files, use the below command(no transcode involved)

vlc.exe audio1.mp3 audio2.mp3 audio3.mp3 --sout
"#gather:std{access=file,dst=merged.mp3}" --sout-keep

To remove audio from a file, the option -an tells “no audio” use below command

ffmpeg -i video.mp4 -codec copy -an onlyvideo.mp4

To add audio from an audio file audio.mp3 to video only file onlyvideo.mp4 use below command

ffmpeg -i onlyvideo.mp4 -i audio.mp3 -shortest -c:v copy -c:a aac -b:a
256k finalvideo.mp4

In the above command, If your audio stream is longer than the video file, or vice-versa, the -shortest option have ffmpeg to stop the conversion when the shorter of the two ends.

-c copy copies the audio and video streams. This means that the process will be fast and the quality will be the same. But when adding, say, WAV audio to an existing video file, it’d be better to compress that audio first. For example:

Here, we only copy the video stream (-c:v copy), and re-encode the audio stream with the ffmpeg built-in AAC encoder (-c:a aac) at 256 kBit/s.

https://superuser.com/questions/590201/add-audio-to-video-using-ffmpeg↗

https://superuser.com/questions/277642/how-to-merge-audio-and-video-file-in-ffmpeg↗

A quick guide to using FFmpeg to convert media files by Tim Nugent - 05 Jun 2017

There are many open source tools out there for editing, tweaking, and converting multimedia into exactly what you need. Tools likeAudacity↗ orHandbrake↗ are fantastic, but sometimes you just want to change a file from one format into another quickly. Enter FFmpeg.

ffmpeg

FFmpeg is a collection of different projects for handling multimedia files. It’s often used behind the scenes in many other media-related projects. Despite its name, it has nothing to do with Moving Picture Experts Group↗ or the myriad multimedia formats it has created.

In this article I’ll be using FFmpeg through the command-line tool ffmpeg, which is only a single, small piece of the FFmpeg project. It’s available on many different operating systems and is included in some operating systems by default. It can be downloaded from theFFmpeg website↗ or through most package managers.

FFmpeg is a powerful tool that can do almost anything you can imagine with multimedia files. In this article, we are interested in using it to convert files, so we won’t be taking a deep dive into its entire feature set. Before we look at using FFmpeg, first we need to take a quick look at what a media file exactly is.

Overview on Media files

At a very high-level view, a media file is broken up into a container and its streams. The streams include the actual AV components, such as a movie’s audio or video, and are encoded using a particular media encoding, or codec↗ . Each codec has its own properties, strengths, and weaknesses. For example, theFLAC codec↗ is good for high-quality lossless audio, whereasVorbis↗ is designed to compete with MP3 in file size while offering better audio quality. This means a FLAC-formatted file will be much larger than a Vorbis audio stream but should sound better. Neither is inherently better than the other, as each is trying to do different things.

The container is the wrapper for the streams. It presents a single interface that media players and tools can interact with. Some containers are highly advanced and allow for any sort of stream, including multiple video and audio streams inside a single container. The streams in a container don’t have to be just audio or video though. Different containers will allow for different streams, e.g., subtitles, chapter information, or other metadata. It all depends on what the container is set to allow.

This is an abstract representation of media files and skips over a lot of the differences between containers. Many require certain streams and metadata or put restrictions on the codecs or contents allowed. This explanation is enough to get you through this article. To learn more, click on the links above.

Be aware that video and audio encoding can take a very long time to run. You should be prepared to settle in for a while when you use FFmpeg.

Basic conversion

The thing that trips up most people when it comes to converting audio and video is selecting the correct formats and containers. Luckily, FFmpeg is pretty clever with its default settings. Usually it automatically selects the correct codecs and container without any complex configuration.

For example, say you have an MP3 file and want it converted into an OGG file:

ffmpeg -i input.mp3 output.ogg

This command takes an MP3 file called input.mp3 and converts it into an OGG file called output.ogg. From FFmpeg’s point of view, this means converting the MP3 audio stream into a Vorbis audio stream and wrapping this stream into an OGG container. You didn’t have to specify stream or container types, because FFmpeg figured it out for you.

This also works with videos:

ffmpeg -i input.mp4 output.webm

Because WebM↗ is a well-defined format, FFmpeg automatically knows what video and audio it can support and will convert the streams to be a valid WebM↗ file.

Depending on your container of choice, this won’t always work. For instance, containers like Matroska↗ are designed to handle almost any stream you care to put in them, whether they’re valid or not. This means the command:

ffmpeg -i input.mp4 output.mkv

may result in a file with the same codecs as input.mp4 had, which may or may not be what you want.

Selecting your codecs

So what do you do when you want to use a container like Matroska (which can handle almost any stream) but still influence which codecs are in the output? FFmpeg to the rescue! You can select the codecs needed by using the -c flag.

This flag lets you set the different codec to use for each stream. For example, to set the audio stream to be Vorbis, you would use the following command:

ffmpeg -i input.mp3 -c:a libvorbis output.ogg

The same can be done to change the video as well as the audio stream:

ffmpeg -i input.mp4 -c:v vp9 -c:a libvorbis output.mkv

This will make a Matroska container with aVP9video stream and a Vorbis audio stream, essentially the same as the WebM we made earlier.

The command ffmpeg -codecs will print every codec FFmpeg knows about. The output of this command will change depending on the version of FFmpeg you have installed.

Changing a single stream

More often than you’d like, the file you have is partially correct with only a single stream in the wrong format. It can be very time consuming to re-encode the correct stream. FFmpeg can help with this situation:

ffmpeg -i input.webm -c:v copy -c:a flac output.mkv

This command copies the video stream from input.webm into output.mkv and encodes the Vorbis audio stream into a FLAC. The -c flag is really powerful.

Changing a container

The prior example can be applied to both the audio and video streams, allowing you to convert from one container format to another without having to do any additional stream encoding:

ffmpeg -i input.webm -c:av copy output.mkv

Influencing the quality

Now that we have a handle on the codecs, the next question is: How do we set the quality of each stream?

The simplest method is to change the bitrate, which may or may not result in a different quality. Humans’ ability to see and hear isn’t as clean and clear cut as we’d like to think. Sometimes changing bitrates makes a huge difference to the subjective quality. Other times it might do nothing but change the file size. Sometimes it’s very difficult to tell what will happen without trying it out.

To set the bitrate of each stream, you use the -b flag, which works in a similar fashion to the -c flag, except instead of codec options you set a bitrate.

For example, to change the bitrate of the video, you would use it like this:

ffmpeg -i input.webm -c:a copy -c:v vp9 -b:v 1M output.mkv

This will copy the audio (-c:a copy) from input.webm and convert the video to a VP9 codec (-c:v vp9) with a bit rate of 1M/s (-b:v), all bundled up in a Matroska container (output.mkv).

Another way we can impact quality is to adjust the frame rate of the video using the -r option:

ffmpeg -i input.webm -c:a copy -c:v vp9 -r 30 output.mkv

This creates a new Matroska with the audio stream copied over and the video stream’s frame rate forced to 30 frames per second, instead of using the frame rate from the input (-r 30).

You can also adjust the dimensions of your video using FFmpeg. The simplest way is to use a predetermined video size:

ffmpeg -i input.mkv -c:a copy -s hd720 output.mkv

This modifies the video to 1280x720 in the output, but you can set the width and height manually if you want:

ffmpeg -i input.mkv -c:a copy -s 1280x720 output.mkv

This produces the exact same output as the earlier command. If you want to set custom sizes in FFmpeg, please remember that the width parameter (1280) comes before height (720).

Adjusting frame rate and bitrate are two crude but effective techniques for affecting media quality. Setting these values very high cannot improve the quality of an existing source if its quality is already low.

Changing these settings is most effective for quickly reducing a high-quality stream to make a smaller file size. Adjusting the size of your video can’t improve the quality, but can make it fit better onto a tablet instead of your TV. Changing the size of a 640x480 video to 4K will not improve it.

Changing the quality of your files is a very subjective matter, which means there is no one way that will work every time. The best method is to make some changes and test whether it looks or sounds better to you.

Modifying the streams

Often you have a file that is almost perfect, and you just need to trim a few parts off. This can be done more easily with a tool that shows you what you’re changing, but if you know exactly where you want it trimmed, it is very easy to do it in FFmpeg:

ffmpeg -i input.mkv -c:av copy -ss 00:01:00 -t 10 output.mkv

This will copy the video and audio streams (-c:av copy) but will trim the video. The -t option sets the cut duration to be 10 seconds and the -ss option sets the start point of the video for trimming, in this case at one minute (00:01:00). You can be more precise than just hours, minutes, and seconds, going down to milliseconds if needed.

Extracting the audio

Sometimes you don’t really care about the video, you just want the audio. Luckily this is very straightforward in FFmpeg with the -vn flag:

ffmpeg -i input.mkv -vn audio_only.ogg

This command extracts only the audio from the input, encodes it as Vorbis, and saves it into audio_only.ogg. Now you have an isolated audio stream. You can also use the -an and -sn flags in the same manner to strip out audio and subtitle streams.

Making a GIF out of it

Recently, animated GIFs (with a hard g because I am not a monster) have made a comeback. Personally I think GIF is the worst format you could choose for video. It has terrible compression quality and size; has very hard limits around colors, frame rates, and container metadata; and can’t support audio. Still, it’s quite popular. So, how can you make a video clip into an animated GIF?

Using the -an flag, similar to what we did above, is better than creating an animated GIF if you’d like to make a video without audio, but there are plenty of places that support GIFs that won’t support a different video format. For all of those:

ffmpeg -i input.mkv output.gif

This command creates a GIF of the same dimensions as the input file. This is often a bad idea, as GIFs don’t compress well relative to other video formats (in my experience a GIF will be around eight times larger than the source video). It may be helpful to use the -s option to resize your GIF to something a bit smaller, especially if the input source is quite large, such as HD video.

Other tools

While FFmpeg is the go-to tool for most AV tasks, it isn’t perfect for everything. There are some tools that, used in conjunction with FFmpeg, can make everything a little bit easier.

To record audio from other applications

sudo apt-get install pulseaudio-utils lame mpg123

And run:

pacmd list-sinks | grep -e 'name:' -e 'index' -e 'Speakers'

The output could be like this:

index: 1

name: <alsa_output.pci-0000_00_1b.0.analog-stereo>

analog-output-speaker: Speakers (priority 10000, latency offset 0 usec, available: unknown)

index: 23

name: <alsa_output.pci-0000_00_03.0.hdmi-surround71>

After you found the name, you can run the following command to record the output to an mp3 file:

parec -d alsa_output.pci-0000_00_1b.0.analog-stereo.monitor | lame -r
-V0 - out.mp3
prabu@homepc-lm:~$ pacmd list-sinks | grep -e 'name:' -e 'index' -e

index: 0

name: <alsa_output.pci-0000_00_1b.0.analog-stereo>

prabu@homepc-lm:~$ parec -d alsa_output.pci-0000_00_1b.0.analog-stereo.monitor| lame -r -V0 -out.mp3

https://superuser.com/questions/1570333/how-can-i-record-audio-output-from-command-line-in-linux↗

To extract audio or Rip an AudioCD

sudo apt install cdparanoia

cdparanoia -A

sudo apt install abcde

abcde -o vorbis

abcde -o vorbis 68-

Tried vlc and deadbeaf applications. Vlc can extract one track at a time. However the above utiliity abcde can extract multiple or all tracks with sufficient configuration information.

Making mp3 songs loudness consistent

Viewing the REPLAYGAIN informaion

The following command shows the REPLAYGAIN data as stored in a mp3 file. If the file doesn’t have this data, the result will be empty.

prabu@homepc2 ~> ffprobe -v quiet -show_format /data/audio/tamil/dasavathaaram/Mukundha_Muku.mp3 |grep GAIN
TAG:REPLAYGAIN_TRACK_GAIN=-7.21 dB
TAG:REPLAYGAIN_TRACK_PEAK=1.000000
TAG:REPLAYGAIN_ALBUM_GAIN=-7.37 dB
TAG:REPLAYGAIN_ALBUM_PEAK=1.000000

The following command is more detailed information on what a file header contains. For most cases related to REPLAYGAIN, the above command is sufficient.

prabu@homepc2 ~ [1|1]> ffmpeg -i '/data/audio/tamil/duet/Mettuppodu Mettuppodu.mp3' -filter:a volumedetect -f null /dev/null
ffmpeg version 8.0.1 Copyright (c) 2000-2025 the FFmpeg developers
  built with gcc 15.2.0 (Alpine 15.2.0)
  configuration: --prefix=/usr --disable-librtmp --disable-lzma --disable-static --disable-stripping --enable-avfilter --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopenmpt --enable-libopus --enable-libplacebo --enable-libpulse --enable-librav1e --enable-librist --enable-libshaderc --enable-libsoxr --enable-libsrt --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-lto=auto --enable-lv2 --enable-openssl --enable-pic --enable-pthreads --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-vulkan --optflags=-O3 --enable-libsvtav1 --enable-libvpl
  libavutil      60.  8.100 / 60.  8.100
  libavcodec     62. 11.100 / 62. 11.100
  libavformat    62.  3.100 / 62.  3.100
  libavdevice    62.  1.100 / 62.  1.100
  libavfilter    11.  4.100 / 11.  4.100
  libswscale      9.  1.100 /  9.  1.100
  libswresample   6.  1.100 /  6.  1.100
Incorrect BOM value
Error reading lyrics, skipped
Input #0, mp3, from '/data/audio/tamil/duet/Mettuppodu Mettuppodu.mp3':
  Metadata:
    TIT3            : MassTamilan
    TRSN            : MassTamilan
    TEXT            : Vairamuthu - MassTamilan
    performer       : A.R.Rahman - MassTamilan
    TSRC            : MassTamilan
    TRSO            : MassTamilan
    publisher       : MassTamilan
    grouping        : MassTamilan
    REPLAYGAIN_TRACK_GAIN: 2.00 dB
    REPLAYGAIN_TRACK_PEAK: 1.000000
    REPLAYGAIN_ALBUM_GAIN: -0.58 dB
    REPLAYGAIN_ALBUM_PEAK: 1.000000
    title           : Mettuppodu Mettuppodu
    artist          : S. P. Balasubrahmanyam, P. Susheela
    album_artist    : Various Artists
    album           : Duet
    TOPE            : A.R.Rahman
    track           : 09/13
    genre           : Tamil
    composer        : A.R.Rahman
    date            : 1994
  Duration: 00:08:14.33, start: 0.025056, bitrate: 264 kb/s
  Stream #0:0: Audio: mp3 (mp3float), 44100 Hz, stereo, fltp, 263 kb/s, start 0.025057
    Metadata:
      encoder         : Lavc58.13
    Side data:
      replaygain: track gain - 2.000000, track peak - 0.000023, album gain - -0.580000, album peak - 0.000023,
  Stream #0:1: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 500x500 [SAR 72:72 DAR 1:1], 90k tbr, 90k tbn, start 0.025056 (attached pic)
    Metadata:
      comment         : Cover (front)
[Parsed_volumedetect_0 @ 0x7f13996d21c0] n_samples: 0
Stream mapping:
  Stream #0:1 -> #0:0 (mjpeg (native) -> wrapped_avframe (native))
  Stream #0:0 -> #0:1 (mp3 (mp3float) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to '/dev/null':
  Metadata:
    TIT3            : MassTamilan
    TRSN            : MassTamilan
    TEXT            : Vairamuthu - MassTamilan
    performer       : A.R.Rahman - MassTamilan
    TSRC            : MassTamilan
    TRSO            : MassTamilan
    publisher       : MassTamilan
    grouping        : MassTamilan
    REPLAYGAIN_TRACK_GAIN: 2.00 dB
    REPLAYGAIN_TRACK_PEAK: 1.000000
    REPLAYGAIN_ALBUM_GAIN: -0.58 dB
    REPLAYGAIN_ALBUM_PEAK: 1.000000
    title           : Mettuppodu Mettuppodu
    artist          : S. P. Balasubrahmanyam, P. Susheela
    album_artist    : Various Artists
    album           : Duet
    TOPE            : A.R.Rahman
    track           : 09/13
    genre           : Tamil
    composer        : A.R.Rahman
    date            : 1994
    encoder         : Lavf62.3.100
  Stream #0:0: Video: wrapped_avframe, yuvj420p(pc, bt470bg/unknown/unknown, progressive), 500x500 [SAR 72:72 DAR 1:1], q=2-31, 200 kb/s, 90k fps, 90k tbn (attached pic)
    Metadata:
      encoder         : Lavc62.11.100 wrapped_avframe
      comment         : Cover (front)
  Stream #0:1: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc62.11.100 pcm_s16le
    Side data:
      replaygain: track gain - 2.000000, track peak - 0.000023, album gain - -0.580000, album peak - 0.000023,
[Parsed_volumedetect_0 @ 0x7f13996d2780] n_samples: 43599872=N/A speed=2.2e-05x elapsed=0:00:00.50
[Parsed_volumedetect_0 @ 0x7f13996d2780] mean_volume: -20.1 dB
[Parsed_volumedetect_0 @ 0x7f13996d2780] max_volume: 0.0 dB
[Parsed_volumedetect_0 @ 0x7f13996d2780] histogram_0db: 846
[Parsed_volumedetect_0 @ 0x7f13996d2780] histogram_1db: 5830
[Parsed_volumedetect_0 @ 0x7f13996d2780] histogram_2db: 8462
[Parsed_volumedetect_0 @ 0x7f13996d2780] histogram_3db: 14234
[Parsed_volumedetect_0 @ 0x7f13996d2780] histogram_4db: 23660
[out#0/null @ 0x7f139d15a7c0] video:0KiB audio:85156KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: unknown
frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.00 bitrate=N/A speed=2.02e-05x elapsed=0:00:00.54
prabu@homepc2 ~> ffmpeg -i '/data/audio/tamil/duet/Mettuppodu Mettuppodu.mp3' -filter:a volumedetect -f null /dev/null
ffmpeg version 8.0.1 Copyright (c) 2000-2025 the FFmpeg developers
  built with gcc 15.2.0 (Alpine 15.2.0)
  configuration: --prefix=/usr --disable-librtmp --disable-lzma --disable-static --disable-stripping --enable-avfilter --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopenmpt --enable-libopus --enable-libplacebo --enable-libpulse --enable-librav1e --enable-librist --enable-libshaderc --enable-libsoxr --enable-libsrt --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-lto=auto --enable-lv2 --enable-openssl --enable-pic --enable-pthreads --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-vulkan --optflags=-O3 --enable-libsvtav1 --enable-libvpl
  libavutil      60.  8.100 / 60.  8.100
  libavcodec     62. 11.100 / 62. 11.100
  libavformat    62.  3.100 / 62.  3.100
  libavdevice    62.  1.100 / 62.  1.100
  libavfilter    11.  4.100 / 11.  4.100
  libswscale      9.  1.100 /  9.  1.100
  libswresample   6.  1.100 /  6.  1.100
Incorrect BOM value
Error reading lyrics, skipped
Input #0, mp3, from '/data/audio/tamil/duet/Mettuppodu Mettuppodu.mp3':
  Metadata:
    TIT3            : MassTamilan
    TRSN            : MassTamilan
    TEXT            : Vairamuthu - MassTamilan
    performer       : A.R.Rahman - MassTamilan
    TSRC            : MassTamilan
    TRSO            : MassTamilan
    publisher       : MassTamilan
    grouping        : MassTamilan
    REPLAYGAIN_TRACK_GAIN: 2.00 dB
    REPLAYGAIN_TRACK_PEAK: 1.000000
    REPLAYGAIN_ALBUM_GAIN: -0.58 dB
    REPLAYGAIN_ALBUM_PEAK: 1.000000
    title           : Mettuppodu Mettuppodu
    artist          : S. P. Balasubrahmanyam, P. Susheela
    album_artist    : Various Artists
    album           : Duet
    TOPE            : A.R.Rahman
    track           : 09/13
    genre           : Tamil
    composer        : A.R.Rahman
    date            : 1994
  Duration: 00:08:14.33, start: 0.025056, bitrate: 264 kb/s
  Stream #0:0: Audio: mp3 (mp3float), 44100 Hz, stereo, fltp, 263 kb/s, start 0.025057
    Metadata:
      encoder         : Lavc58.13
    Side data:
      replaygain: track gain - 2.000000, track peak - 0.000023, album gain - -0.580000, album peak - 0.000023,
  Stream #0:1: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 500x500 [SAR 72:72 DAR 1:1], 90k tbr, 90k tbn, start 0.025056 (attached pic)
    Metadata:
      comment         : Cover (front)
[Parsed_volumedetect_0 @ 0x7ff9a12891c0] n_samples: 0
Stream mapping:
  Stream #0:1 -> #0:0 (mjpeg (native) -> wrapped_avframe (native))
  Stream #0:0 -> #0:1 (mp3 (mp3float) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to '/dev/null':
  Metadata:
    TIT3            : MassTamilan
    TRSN            : MassTamilan
    TEXT            : Vairamuthu - MassTamilan
    performer       : A.R.Rahman - MassTamilan
    TSRC            : MassTamilan
    TRSO            : MassTamilan
    publisher       : MassTamilan
    grouping        : MassTamilan
    REPLAYGAIN_TRACK_GAIN: 2.00 dB
    REPLAYGAIN_TRACK_PEAK: 1.000000
    REPLAYGAIN_ALBUM_GAIN: -0.58 dB
    REPLAYGAIN_ALBUM_PEAK: 1.000000
    title           : Mettuppodu Mettuppodu
    artist          : S. P. Balasubrahmanyam, P. Susheela
    album_artist    : Various Artists
    album           : Duet
    TOPE            : A.R.Rahman
    track           : 09/13
    genre           : Tamil
    composer        : A.R.Rahman
    date            : 1994
    encoder         : Lavf62.3.100
  Stream #0:0: Video: wrapped_avframe, yuvj420p(pc, bt470bg/unknown/unknown, progressive), 500x500 [SAR 72:72 DAR 1:1], q=2-31, 200 kb/s, 90k fps, 90k tbn (attached pic)
    Metadata:
      encoder         : Lavc62.11.100 wrapped_avframe
      comment         : Cover (front)
  Stream #0:1: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc62.11.100 pcm_s16le
    Side data:
      replaygain: track gain - 2.000000, track peak - 0.000023, album gain - -0.580000, album peak - 0.000023,
[Parsed_volumedetect_0 @ 0x7ff9a1289780] n_samples: 43599872=N/A speed=2.2e-05x elapsed=0:00:00.50
[Parsed_volumedetect_0 @ 0x7ff9a1289780] mean_volume: -20.1 dB
[Parsed_volumedetect_0 @ 0x7ff9a1289780] max_volume: 0.0 dB
[Parsed_volumedetect_0 @ 0x7ff9a1289780] histogram_0db: 846
[Parsed_volumedetect_0 @ 0x7ff9a1289780] histogram_1db: 5830
[Parsed_volumedetect_0 @ 0x7ff9a1289780] histogram_2db: 8462
[Parsed_volumedetect_0 @ 0x7ff9a1289780] histogram_3db: 14234
[Parsed_volumedetect_0 @ 0x7ff9a1289780] histogram_4db: 23660
[out#0/null @ 0x7ff9a603e7c0] video:0KiB audio:85156KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: unknown
frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.00 bitrate=N/A speed=2.08e-05x elapsed=0:00:00.52

Adding REPLAYGAIN data to large number of files

To identify and view the list of music files without REPLAYGAIN settings.

find /data/audio/tamil -name "*.mp3" | while read -r file; do
    if ! ffprobe -v quiet -show_format "$file" | grep -q "REPLAYGAIN_TRACK_GAIN"; then
        echo "Needs Fix: $file"
    fi
done

Using rsgain utility in easy mode is the easiest method to add tags to have consistent loudness level. Here loudness is set at 14, to match spotify level.

rsgain custom -l -14 -s i -I 3 -S -a -m $(nproc) /data/audio/tamil/dasavathaaram/*.mp3

rsgain easy -S -l -14 /data/audio/tamil

rsgain custom -s d "/data/audio/tamil/anthimandarai/Sakiyaa-II-MassTamilan.com.mp3"
rsgain custom -l -14 -s i -I 3 -a "/data/audio/tamil/anthimandarai/Sakiyaa-II-MassTamilan.mp3"

While making changes, certain mistakes crept into a number of music file headers. The following script was used to fix mistakes in REPLAYGAIN settings for such files

!/bin/sh
find /data/audio/tamil -name "*.mp3" | while read -r file; do
    if ! ffprobe -v quiet -show_format "$file" | grep -q "REPLAYGAIN_TRACK_GAIN"; then
        echo "Repairing: $file"

        # 1. Strip corruption by re-packing
        if ffmpeg -v quiet -i "$file" -map 0 -map_metadata 0 -c copy "$file.tmp.mp3" -y; then
            # 2. Overwrite the original
            mv "$file.tmp.mp3" "$file"

            # 3. Apply the tags
            rsgain custom -l -14 -s i -I 3 -a "$file" > /dev/null
            echo "Done."
        else
            echo "Failed to repair $file"
            rm -f "$file.tmp.mp3"
        fi
    fi
done

© Prabu Anand K 2020-2026