Skip to content

Conversation

@Almoped
Copy link
Contributor

@Almoped Almoped commented Oct 23, 2025

Playing .m4a files with FFmpeg can use something like this to read ReplayGain tags.
FFmpeg also reads RG tags in other files like .ogg or .flac, should those decoders be unavailable.

@radioactiveman
Copy link
Member

@jlindgren90: Can you explain please why some plugins read the RG tags in play() and others in read_tag()? What is better and would it make sense to implement both for ffaudio?

@jlindgren90
Copy link
Member

Either way is fine. I would suggest doing it in read_tag for new code, if the information is available at that point.

What each plugin does is perhaps mostly for historical reasons at this point. I think for some formats (e.g. Vorbis) there is a concern that multiple segments may be included in a stream and have different tags, but I'm not sure how common that is in practice.

@radioactiveman
Copy link
Member

The read_tag approach could be implemented as shown below.

@Almoped: Do you want to test this more carefully? I only used a single FLAC file as sample.

@jlindgren90: Looking good for you?

diff --git a/src/ffaudio/ffaudio-core.cc b/src/ffaudio/ffaudio-core.cc
index 253eed6c5..d21c480c4 100644
--- a/src/ffaudio/ffaudio-core.cc
+++ b/src/ffaudio/ffaudio-core.cc
@@ -416,6 +416,10 @@ static const struct {
     {Tuple::String, Tuple::Genre, {"genre", "WM/Genre", nullptr}},
     {Tuple::String, Tuple::Comment, {"comment", nullptr}},
     {Tuple::String, Tuple::Composer, {"composer", nullptr}},
+    {Tuple::String, Tuple::AlbumGain, {"replaygain_album_gain", nullptr}},
+    {Tuple::String, Tuple::AlbumPeak, {"replaygain_album_peak", nullptr}},
+    {Tuple::String, Tuple::TrackGain, {"replaygain_track_gain", nullptr}},
+    {Tuple::String, Tuple::TrackPeak, {"replaygain_track_peak", nullptr}},
     {Tuple::Int, Tuple::Year, {"year", "WM/Year", "date", nullptr}},
     {Tuple::Int, Tuple::Track, {"track", "WM/TrackNumber", nullptr}},
     {Tuple::Int, Tuple::Disc, {"disc", "WM/PartOfSet", nullptr}},
@@ -432,7 +436,11 @@ static void read_metadata_dict (Tuple & tuple, AVDictionary * dict)
 
         if (entry && entry->value)
         {
-            if (meta.ttype == Tuple::String)
+            if (meta.field == Tuple::AlbumGain || meta.field == Tuple::TrackGain)
+                tuple.set_gain (meta.field, Tuple::GainDivisor, entry->value);
+            else if (meta.field == Tuple::AlbumPeak || meta.field == Tuple::TrackPeak)
+                tuple.set_gain (meta.field, Tuple::PeakDivisor, entry->value);
+            else if (meta.ttype == Tuple::String)
                 tuple.set_str (meta.field, entry->value);
             else if (meta.ttype == Tuple::Int)
                 tuple.set_int (meta.field, atoi (entry->value));

radioactiveman added a commit that referenced this pull request Nov 3, 2025
This is helpful for M4A, Ogg, Opus and FLAC files
because libaudtag only supports APE and ID3 tags.

See also: #191
@radioactiveman
Copy link
Member

Pushed now as ae51bc8, closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants