After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 776413 - flacenc: Wrong quality levels in GStreamer, level 9 doesn't exist in libflac
flacenc: Wrong quality levels in GStreamer, level 9 doesn't exist in libflac
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
1.10.x
Other Linux
: Normal normal
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-12-22 21:48 UTC by Christian Stadelmann
Modified: 2018-11-03 15:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix number of quality levels (998 bytes, patch)
2017-01-29 15:17 UTC, Christian Stadelmann
none Details | Review
Fix number of quality levels (with fixed From: field) (1.21 KB, patch)
2017-01-30 11:49 UTC, Christian Stadelmann
none Details | Review

Description Christian Stadelmann 2016-12-22 21:48:50 UTC
According to libflac [1], there are 9 compression levels, 0…8.

GstFlacEncQuality (values for the "quality" property in GstFlacEnc) has 10 compression levels, 0…9.

When trying to encode to FLAC through API with quality set to 9, I'm getting this GError:

GLib.Error: gst-library-error-quark: Die Unterstützungsbibliothek konnte nicht initialisiert werden. (3)

plus this debug message:

gstflacenc.c(872): gst_flac_enc_set_format (): /GstPipeline:pipeline0/GstFlacEnc:flacenc0:
could not initialize encoder (wrong parameters?) 11


Steps to reproduce:
1. run:
$ gst-launch-1.0 filesrc location=test.mp3 ! mpegaudioparse ! mad ! audioconvert ! flacenc quality=8 ! filesink location=test.flac"

which runs fine.

2. run
$ gst-launch-1.0 filesrc location=test.mp3 ! mpegaudioparse ! mad ! audioconvert ! flacenc quality=9 ! filesink location=test.flac"

gives an error message instead:

Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
ERROR: from element /GstPipeline:pipeline0/GstFlacEnc:flacenc0: Could not initialize supporting library.
Additional debug info:
gstflacenc.c(872): gst_flac_enc_set_format (): /GstPipeline:pipeline0/GstFlacEnc:flacenc0:
could not initialize encoder (wrong parameters?) 11
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...


I'm running gstreamer1-plugins-good-1.10.2-1.fc25.x86_64 on Fedora 25.


[1] https://www.xiph.org/flac/api/group__flac__stream__encoder.html#gae49cf32f5256cb47eecd33779493ac85
Comment 1 Sebastian Dröge (slomo) 2016-12-23 10:14:33 UTC
Do you want to provide a patch for this?
Comment 2 Christian Stadelmann 2016-12-23 10:35:27 UTC
(In reply to Sebastian Dröge (slomo) from comment #1)
> Do you want to provide a patch for this?

I'd prefer not to, since I don't have any clue how you want to handle an API/ABI break like this.
Comment 3 Tim-Philipp Müller 2016-12-23 10:55:55 UTC
If it never worked, it's not really an API/ABI break :)

I'm just wondering if this is something that changed in libflac at some point or if we really had this wrong for almost 10 years without anyone noticing
Comment 4 Christian Stadelmann 2016-12-23 11:44:43 UTC
(In reply to Tim-Philipp Müller from comment #3)
> If it never worked, it's not really an API/ABI break :)

Ok, that's right.

> I'm just wondering if this is something that changed in libflac at some
> point or if we really had this wrong for almost 10 years without anyone
> noticing

I was wondering the same and had a look at libflac changelogs which didn't note any changes in compression levels.

Anyway, libFLAC specifies
> A value larger than 8 will be treated as 8.

in https://git.xiph.org/?p=flac.git;f=include/FLAC/stream_encoder.h;hb=HEAD#l811

so GStreamer is doing something differently weird. It seems that

GstFlacEncParams flacenc_params[] in https://cgit.freedesktop.org/gstreamer/gst-plugins-good/tree/ext/flac/gstflacenc.c#n185 differs from Xiph's CompressionLevels compression_levels[] https://git.xiph.org/?p=flac.git;f=src/libFLAC/stream_encoder.c;hb=HEAD#l102
shouldn't they be the same?

Should we request the CompressionLevels struct to be public?

For example: At compression level 7, GStreamer sets max_lpc_order=8 whereas libFLAC sets it to 12. Also, FLAC__bool do_exhaustive_model_search is always False, whereas the GStreamer implementation sets it to TRUE for level 7 to 9. Other parameters differ too.

It looks like the author of GstFlacEnc just invented compression level 9, at least that is what the parameters look like.
Comment 5 Sebastian Dröge (slomo) 2016-12-23 12:53:35 UTC
It would be good if that table could be made public indeed, in one way or another. But for now we should probably update it with what is in latest libFLAC.

Do you want to provide a patch for that?
Comment 6 Christian Stadelmann 2017-01-29 15:17:36 UTC
Created attachment 344486 [details] [review]
Fix number of quality levels

A minimal patch for both stable and master branch. More to come.
Comment 7 Sebastian Dröge (slomo) 2017-01-30 10:42:04 UTC
The "From" (i.e. Author) in your patch seems corrupted, that's just random letters.

But didn't you say that there's also a mismatch between settings for our other quality levels?
Comment 8 Christian Stadelmann 2017-01-30 11:40:27 UTC
(In reply to Sebastian Dröge (slomo) from comment #7)
> The "From" (i.e. Author) in your patch seems corrupted, that's just random
> letters.

Interesting. Haven't seen that before. Looks like another bug in gitg or libgit. I've reported it at https://bugzilla.gnome.org/show_bug.cgi?id=777932
Comment 9 Christian Stadelmann 2017-01-30 11:42:46 UTC
(In reply to Sebastian Dröge (slomo) from comment #7)
> But didn't you say that there's also a mismatch between settings for our
> other quality levels?

Yes, I did. Most notably, the FLAC__stream_encoder_set_compression_level does NOT set the blocksize any more, but sets apodization.
Is it Ok if I
1. introduce a new PROP_APODIZATION value to the enum and a new apodization parameter?
2. and reorder enum entries?
3. change GstFlacEncParams: remove blocksize, add apodization, reorder fields
4. change gst_flac_enc_update_quality to use FLAC__stream_encoder_set_compression_level instead of relying on the flacenc_params array and get rid of flacenc_params array, leaving only default values of each parameter.

Still, I need to dive into GLib a bit to provide the patch, because I do not understand enough of how GParam properties works.
Comment 10 Christian Stadelmann 2017-01-30 11:49:08 UTC
Created attachment 344529 [details] [review]
Fix number of quality levels (with fixed From: field)
Comment 11 Sebastian Dröge (slomo) 2017-01-30 12:09:49 UTC
(In reply to Christian Stadelmann from comment #9)
> (In reply to Sebastian Dröge (slomo) from comment #7)
> > But didn't you say that there's also a mismatch between settings for our
> > other quality levels?
> 
> Yes, I did. Most notably, the FLAC__stream_encoder_set_compression_level
> does NOT set the blocksize any more, but sets apodization.
> Is it Ok if I
> 1. introduce a new PROP_APODIZATION value to the enum and a new apodization
> parameter?
> 2. and reorder enum entries?

Reorder which enum entries?

> 3. change GstFlacEncParams: remove blocksize, add apodization, reorder fields
> 4. change gst_flac_enc_update_quality to use
> FLAC__stream_encoder_set_compression_level instead of relying on the
> flacenc_params array and get rid of flacenc_params array, leaving only
> default values of each parameter.

Sounds like a plan
Comment 12 Christian Stadelmann 2017-01-30 12:53:19 UTC
Is there any simple way to test my code? I am used to gst-launch-1.0, but how do I get it to use the newly compiled flac library?

Why do you `#define` constants instead of making them `const`? Would you mind if I changed this to using `const`?

(In reply to Sebastian Dröge (slomo) from comment #11)
> (In reply to Christian Stadelmann from comment #9)
> > Is it Ok if I
> > 1. introduce a new PROP_APODIZATION value to the enum and a new apodization
> > parameter?
> > 2. and reorder enum entries?
> 
> Reorder which enum entries?

The ones in the anonymous enum starting around line 106.
Comment 13 Sebastian Dröge (slomo) 2017-01-30 13:03:41 UTC
(In reply to Christian Stadelmann from comment #12)
> Is there any simple way to test my code? I am used to gst-launch-1.0, but
> how do I get it to use the newly compiled flac library?

You mean the new libgstflac.so? Either overwrite the existing one from your system, use something like gst-uninstalled or just set GST_PLUGIN_PATH to the location of the new .so. It should override the system path then.

> Why do you `#define` constants instead of making them `const`? Would you
> mind if I changed this to using `const`?

Convention

> (In reply to Sebastian Dröge (slomo) from comment #11)
> > (In reply to Christian Stadelmann from comment #9)
> > > Is it Ok if I
> > > 1. introduce a new PROP_APODIZATION value to the enum and a new apodization
> > > parameter?
> > > 2. and reorder enum entries?
> > 
> > Reorder which enum entries?
> 
> The ones in the anonymous enum starting around line 106.

You mean the PROP_* ones? Why would you like to reorder them? I think it's ok to do so, but doesn't seem very useful other than making the diff bigger and increasing the risk of merge conflicts :)
Comment 14 GStreamer system administrator 2018-11-03 15:15:19 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/issues/335.