Menu

#278 Problem Icy-MetaData:1

0.68
closed-invalid
nobody
None
5
2025-02-19
2019-05-15
No

Problem Icy-MetaData:1

I created an mp3 file named test.mp3 by streaming curl output (webradio)
I stop creating the test.mp3 file after 10 seconds.
Then
I read the file test.mp3 with (mpg123 -vt test.mp3) sees OUTPUT

OUTPUT CURL

curl http://stream.c9.fr/c9.mp3 > test.mp3
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 283k 0 283k 0 0 28056 0 --:--:-- 0:00:10 --:--:-- 23893^C

OUTPUT mpg123

./mpg123 -vt test.mp3
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
version 1.25.10; written and copyright by Michael Hipp and others
free software (LGPL) without any warranty but with best wishes
Decoder: x86-64 (SSE)
Trying output module: test, device: <nil></nil>

Terminal control enabled, press 'h' for listing of keys and functions.

Playing MPEG stream 1 of 1: test.mp3 ...

MPEG 1.0 L III cbr192 44100 j-s

456+000 00:11.91+00:00.00 --- 100=100 192 kb/s 627 B acc 0 clip p+0.000
[0:11] Decoding of test.mp3 finished.

Until no problem the file (test.mp3) is read without problem.

When I add the parameter to curl -H "Icy-MetaData: 1" it means add in the stream the stream (webradio) the metadata like (StreamTitle) the whole thing is generated in a file at the output (file test.mp3 ) see OUTPUT example:

curl -H "Icy-MetaData:1" -v http://stream.c9.fr/c9.mp3 > test.mp3
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 66.70.200.63...

  • TCP_NODELAY set
    0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to stream.c9.fr (66.70.200.63) port 80 (#0)

    GET /c9.mp3 HTTP/1.1
    Host: stream.c9.fr
    User-Agent: curl/7.64.1
    Accept: /
    Icy-MetaData:1

  • HTTP 1.0, assume close after body
    < HTTP/1.0 200 OK
    < Server: Icecast 2.4.2
    < Date: Sat, 11 May 2019 11:28:26 GMT
    < Content-Type: audio/mpeg
    < Cache-Control: no-cache
    < Expires: Mon, 26 Jul 1997 05:00:00 GMT
    < Pragma: no-cache
    < Access-Control-Allow-Origin: *
    < icy-br:192
    < ice-audio-info: channels=2;samplerate=44100;bitrate=192
    < icy-description:C9 Radio - Only Hits! - c9.fr
    < icy-genre:Top40 Hits Club Pop Rock Urban
    < icy-name:C9 Radio - Only Hits! - c9.fr
    < icy-pub:1
    < icy-url:https://www.c9.fr/
    < icy-metaint:16000
    <
    { [1400 bytes data]
    100 254k 0 254k 0 0 28445 0 --:--:-- 0:00:09 --:--:-- 23993^C

What I can not understand is that reading with mpg123 the file test.mp3 is read with errors see OUTPUT mpg123

OUTPUT mpg123

mpg123 -vt test.mp3
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
version 1.14.4; written and copyright by Michael Hipp and others
free software (LGPL/GPL) without any warranty but with best wishes
Decoder: x86-64 (SSE)

Playing MPEG stream 1 of 1: test.mp3 ...

MPEG 1.0, Layer: III, Freq: 44100, mode: Joint-Stereo, modext: 2, BPF : 627
Channels: 2, copyright: No, original: Yes, CRC: No, emphasis: 0.
Bitrate: 192 kbit/s Extension value: 0
Frame# 24 [ 386], Time: 00:00.62 [00:10.08], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x69746c65 at offset 16008.
Note: Trying to resync...
Note: Skipped 65 bytes in input.
Frame# 48 [ 361], Time: 00:01.25 [00:09.43], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0xeafffbb2 at offset 32373.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 72 [ 337], Time: 00:01.88 [00:08.80], RVA: off, Vol: 100(100)[layer3.c:454] error: big_values too large!
[layer3.c:454] error: big_values too large!
Note: Illegal Audio-MPEG-Header 0x9ffffbb2 at offset 48674.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 96 [ 313], Time: 00:02.50 [00:08.17], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0xe9fffbb2 at offset 64349.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 120 [ 289], Time: 00:03.13 [00:07.54], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x79fffbb2 at offset 80650.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 152 [ 257], Time: 00:03.97 [00:06.71], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x0ffffbb2 at offset 96325.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 176 [ 233], Time: 00:04.59 [00:06.08], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x4dfffbb2 at offset 112626.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 200 [ 209], Time: 00:05.22 [00:05.45], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0xb1fffbb2 at offset 128301.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 224 [ 185], Time: 00:05.85 [00:04.83], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x49fffbb2 at offset 144602.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 248 [ 161], Time: 00:06.47 [00:04.20], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x10fffbb0 at offset 160277.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 280 [ 129], Time: 00:07.31 [00:03.36], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x7ffffbb2 at offset 176578.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 304 [ 105], Time: 00:07.94 [00:02.74], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x41fffbb2 at offset 192252.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 328 [ 81], Time: 00:08.56 [00:02.11], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x88fffbb2 at offset 208554.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 352 [ 57], Time: 00:09.19 [00:01.48], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x41fffbb2 at offset 224228.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 376 [ 33], Time: 00:09.82 [00:00.86], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x0cfffbb2 at offset 240530.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 400 [ 9], Time: 00:10.44 [00:00.23], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x4dfffbb2 at offset 256204.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Frame# 409 [ 1], Time: 00:10.68 [00:00.02], RVA: off, Vol: 100(100)
[0:10] Decoding of test.mp3 finished.

if I put the option "Icy-MetaData: 1" I have the same problem with my streaming program of (webradio) the error and in function mpg123_decode_frame example:

err = mpg123_decode_frame(mh, &frame_offset, &audio, &done);

in the mpg123_feed function I do not have any example errors:

mpg123_feed(mh, (const unsigned char *) DataBufferMP3, Counternmemb);

is there not a way to with the option "Icy-MetaData: 1" to play the stream with (mpg123_decode_frame) without errors of messages:

Frame# 24 [ 386], Time: 00:00.62 [00:10.08], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x69746c65 at offset 16008.
Note: Trying to resync...
Note: Skipped 65 bytes in input.

to skip the metadata and read only mp3 streams.

thank you

Related

Bugs: #278

Discussion

  • Thomas Orgis

    Thomas Orgis - 2019-05-15

    Well, what do you expect from mpg123 in this case? You demand the server to interrupt the MPEG stream with ICY metadata blobs and call mpg123 without a hint about these interruptions. To the decoder, it looks like a damaged stream. The ICY metadata can interrupt the MPEG data at any point, without regard to frame headers etc.

    But you are lucky, there is a solution:

    mpg123 --icy-interval 16000
    

    I just noticed that this is not documented in the man page, only in the long help output.

     
  • Didier Castellacci

    I did tests online with mpg123 --icy-interval 16000
    it's ok it works

    How to implement in my program I saw with:

    if (mpg123_param (mh, MPG123_ICY_INTERVAL, 16000, 0) == MPG123_OK)

    when it's less than 16000 (mpg123_param (mh, MPG123_ICY_INTERVAL, 16000, 0) tells me it's ok.
    How to make the interval at 16000 example

    if (mpg123_param (mh, MPG123_ICY_INTERVAL, 16000, 0) == MPG123_OK)
    {
    std :: cout << << displays 16000 "<< std :: endl;
    }

    and display "displays 16000" every 16000.

    thank you

     
  • Thomas Orgis

    Thomas Orgis - 2019-05-16

    I do not quite understand. You call mpg123_param() once before starting the decoding, not all the time. You tell the decoder which ICY interval to expect and it will cut out the metainfo out of the stream accordingly. Changing the parameter in between will be confusing at best.

     
  • Didier Castellacci

    include <curl curl.h=""></curl>

    include <mpg123.h></mpg123.h>

    include <ao ao.h=""></ao>

    include <iostream></iostream>

    include <string></string>

    include <cstring></cstring>

    include <sstream></sstream>

    define BITS 8

    mpg123_handle mh = NULL;
    ao_device
    dev = NULL;

    int octet = 0;
    std::string str = "";
    int CounterBuffer = 0; //Counter

    size_t header_callback(char buffer, size_t size, size_t nitems, void userdata)
    {
    /
    char
    str = NULL;

    str = (char *) malloc(nitems);
    
    for(int i = 0; i < (nitems * size); i++)
    {
     str[i] = buffer[i];
    }
    
    std::cout << "str : " << str << std::endl;
    */
    
    if(std::strstr((char *) buffer, "icy-br") != NULL)
    {
        std::cout << buffer << std::endl;
    }
    
    if(std::strstr((char *) buffer, "ice-audio-info") != NULL)
    {
        std::cout << buffer << std::endl;
    }
    
    if(std::strstr((char *) buffer, "icy-description") != NULL)
    {
        std::cout << buffer << std::endl;
    }
    
    if(std::strstr((char *) buffer, "icy-genre") != NULL)
    {
        std::cout << buffer << std::endl;
    }
    
    if(std::strstr((char *) buffer, "icy-name") != NULL)
    {
        std::cout << buffer << std::endl;
    }
    
    if(std::strstr((char *) buffer, "icy-url") != NULL)
    {
        std::cout << buffer << std::endl;
    }
    
    if(std::strstr((char *) buffer, "icy-metaint") != NULL)
    {
        std::cout << buffer << std::endl;
    }
    
    return nitems * size;
    

    }

    size_t play_stream(void buffer, size_t size, size_t nmemb, void userp)
    {
    int err;
    off_t frame_offset;
    unsigned char *audio;
    size_t done;
    ao_sample_format format;
    int channels, encoding;
    long rate;

    int meta;
    
    unsigned char *DataBufferMetaData = (unsigned char *) malloc(nmemb);
    
    for (int i = 0; i < nmemb; i++)
    {
    
        if(CounterBuffer == 16000)
        {
            DataBufferMetaData[i] = ((const unsigned char *) buffer)[i];
            std::cout << "\r\n1 octet : " << abs((int)DataBufferMetaData[i]) << std::endl;
            std::cout << "\r\ntotal octet : " << abs((int)DataBufferMetaData[i]) * 16 << std::endl;
            octet = 16000 + abs((int)DataBufferMetaData[i]) * 16;
        }
    
        if(CounterBuffer >= 16000 && CounterBuffer <= octet)
        {
    
            DataBufferMetaData[i] = ((const unsigned char *) buffer)[i];
            //str += ((const unsigned char *) buffer)[i];
            str += ((const unsigned char *) DataBufferMetaData)[i];
    
        }
    
        if(CounterBuffer >= 16000 && CounterBuffer == octet)
        {
            std::size_t found = str.find(";");
    
            std::string str2;
            str2 = str.substr(0, found + 1);
            str.clear();
            str = str2;
    
            std::cout << "\r\nlength StreamTitle : " << str.length() << std::endl;
            std::cout << "\r\nStreamTitle : " << str << std::endl;
            std::cout << "\r\nLe Header est termine : " << CounterBuffer << std::endl;
    
    
            CounterBuffer = 0;
            str = "";
            octet = 0;
        }
        else
        {
            CounterBuffer++;
    
        }
    
    
    }
    
    mpg123_feed(mh, (const unsigned char*) buffer, size * nmemb);
    do {
    
        meta = mpg123_meta_check(mh);
        if(meta != 0) std::cout << "\r\nMeta..." << std::endl;
        if(meta & (MPG123_NEW_ID3|MPG123_NEW_ICY))
        {
            std::cout << "ID3 or ICY" << std::endl;
            if(meta & MPG123_NEW_ID3) std::cout << "ID3..." << std::endl;
            if(meta & MPG123_NEW_ICY) std::cout << "ICY..." << std::endl;
    
            mpg123_meta_free(mh); /* Do not waste memory after delivering. */
        }
    
        err = mpg123_decode_frame(mh, &frame_offset, &audio, &done);
        switch(err) {
            case MPG123_NEW_FORMAT:
                mpg123_getformat(mh, &rate, &channels, &encoding);
                format.bits = mpg123_encsize(encoding) * BITS;
                format.rate = rate;
                format.channels = channels;
                format.byte_format = AO_FMT_NATIVE;
                format.matrix = 0;
                dev = ao_open_live(ao_default_driver_id(), &format, NULL);
                break;
            case MPG123_OK:
                ao_play(dev, (char *) audio, done);
                break;
            case MPG123_NEED_MORE:
                break;
            default:
                break;
        }
    } while(done > 0);
    
    return size * nmemb;
    

    }

    int main(int argc, char *argv[])
    {
    if(argc < 2)
    return 0;

    ao_initialize();
    
    mpg123_init();
    mh = mpg123_new(NULL, NULL);
    mpg123_open_feed(mh);
    
    if(mpg123_param(mh, MPG123_ICY_INTERVAL, 16000, 0) == MPG123_OK)
        std::cout << "\r\nICY INTERVAL OK" << std::endl;
    else
        std::cout << "\r\nICY INTERVAL NOT OK" << std::endl;
    
    
    
    CURL *curl = curl_easy_init();
    
    if(curl)
    {
    
        struct curl_slist *headers = NULL;
    
        headers = curl_slist_append(headers, "Icy-MetaData:1");
    
        curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, play_stream);
        curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
    
        if(curl_easy_perform(curl) != CURLE_OK)
            return false;
    
        curl_slist_free_all(headers);
    
        curl_easy_cleanup(curl);
        curl_global_cleanup();
    
    }
    
    mpg123_close(mh);
    mpg123_delete(mh);
    mpg123_exit();
    
    ao_close(dev);
    ao_shutdown();
    
    return 0;
    

    }

    OUTPUT

    ./player http://stream.c9.fr/c9.mp3

    ICY INTERVAL OK
    icy-br:192

    ice-audio-info: channels=2;samplerate=44100;bitrate=192

    icy-description:C9 Radio - Only Hits! - c9.fr

    icy-genre:Top40 Hits Club Pop Rock Urban

    icy-name:C9 Radio - Only Hits! - c9.fr

    icy-url:https://www.c9.fr/

    icy-metaint:16000

    1 octet : 3

    total octet : 48

    length StreamTitle : 36

    StreamTitle : StreamTitle='Rihanna - Unfaithful';

    Le Header est termine : 16048
    Note: Illegal Audio-MPEG-Header 0x6c273b00 at offset 16033.
    Note: Trying to resync...
    Note: Skipped 49 bytes in input.

    1 octet : 0

    total octet : 0

    length StreamTitle : 0

    StreamTitle :

    Le Header est termine : 16000
    Note: Illegal Audio-MPEG-Header 0x0dfffbb2 at offset 32382.
    Note: Trying to resync...
    Note: Skipped 1 bytes in input.

    1 octet : 0

    total octet : 0

    length StreamTitle : 0

    StreamTitle :

    Le Header est termine : 16000
    Note: Illegal Audio-MPEG-Header 0xc9fffbb2 at offset 48057.
    Note: Trying to resync...
    Note: Skipped 1 bytes in input.

    In play_stream I'm doing a test with mpg123_meta_check but nothing is happening
    It can be seen that at OUTPUT ICY Interval is active.

    In play_stream I loop for (int i = 0; i <nmemb; i ++) to compute the streamTitle we can see the streamtitle in the OUTPUT.

    Thank You

     
  • Didier Castellacci

    here is the file

     
  • Thomas Orgis

    Thomas Orgis - 2019-05-18

    I don't have time right now for a debugging session, but can you prepare a small piece of stream
    dump with a few ICY intervals in it so that we can compare any testing? A piece of 100K should
    not be so troublesome copyright-wise, I hope. If you rather not want to attach it here, anyway,
    mail it to maintainer@mpg123.org .

     

    Last edit: Thomas Orgis 2019-05-18
  • Thomas Orgis

    Thomas Orgis - 2019-05-22

    Ah, sorry. After testing with the doc/examples/mpglib.c example program, I realized that you are right. When you use mpg123_open_feed(), libmpg123 does not do the ICY parsing. I implemented this only for the other stream readers.

    I see that the documentation was not explicit about this, but it did not occur to me that one would first open the stream and then set ICY_INTERVAL. If you set the parameter first and then open the stream, you get this:

    [src/libmpg123/readers.c:1129] error: Feed reader cannot do ICY parsing!
    

    The setting of ICY_INTERVAL makes libmpg123 set up different routines for reading on opening the stream. The routines for ICY do not exist in the feeder case.

    The reason is that I only wrote the feeder API as a direct replacement for the old mpglib. I did not expect people to use it by default for future projects. You can achieve your custom stream handling with full support for mpg123 features by using mpg123_replace_reader_handle() to plug in your own I/O.

    Can that work for your case? Alternatively, if you have to stay with the feeder, you'll just have to cut out the ICY block each 16000 bytes yourself here.

     
    • Didier Castellacci

      Alternatively, if you have to stay with the feeder, you'll just have to cut out the ICY block each 16000 bytes yourself here.
      I tried to cut the ICY block every 16,000 bytes. it does not work he always finds the error message
      Frame#    24 [  386], Time: 00:00.62 [00:10.08], RVA:   off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x69746c65 at offset 16008.Note: Trying to resync...Note: Skipped 65 bytes in input.
      I cut the buffer that is to say example:
      unsigned char DataBufferMP3 = (unsigned char ) malloc(nmemb);
      for (int i = 0; i < nmemb; i++){    if(CounterBuffer <= 15999)            DataBufferMP3[i] = ((const unsigned char *) buffer)[i];

      Thank youDidier

      Le mercredi 22 mai 2019 à 07:51:42 UTC+2, Thomas Orgis <sobukus@users.sourceforge.net> a écrit :
      

      Ah, sorry. After testing with the doc/examples/mpglib.c example program, I realized that you are right. When you use mpg123_open_feed(), libmpg123 does not do the ICY parsing. I implemented this only for the other stream readers.

      I see that the documentation was not explicit about this, but it did not occur to me that one would first open the stream and then set ICY_INTERVAL. If you set the parameter first and then open the stream, you get this:
      [src/libmpg123/readers.c:1129] error: Feed reader cannot do ICY parsing!

      The setting of ICY_INTERVAL makes libmpg123 set up different routines for reading on opening the stream. The routines for ICY do not exist in the feeder case.

      The reason is that I only wrote the feeder API as a direct replacement for the old mpglib. I did not expect people to use it by default for future projects. You can achieve your custom stream handling with full support for mpg123 features by using mpg123_replace_reader_handle() to plug in your own I/O.

      Can that work for your case? Alternatively, if you have to stay with the feeder, you'll just have to cut out the ICY block each 16000 bytes yourself here.

      [bugs:#278] Problem Icy-MetaData:1

      Status: open
      Group: 0.68
      Created: Wed May 15, 2019 10:03 AM UTC by Didier Castellacci
      Last Updated: Sat May 18, 2019 09:15 AM UTC

      Owner: nobody
      Problem Icy-MetaData:1

      I created an mp3 file named test.mp3 by streaming curl output (webradio)
      I stop creating the test.mp3 file after 10 seconds.
      Then
      I read the file test.mp3 with (mpg123 -vt test.mp3) sees OUTPUT

      OUTPUT CURL

      curl http://stream.c9.fr/c9.mp3 > test.mp3
      % Total % Received % Xferd Average Speed Time Time Time Current
      Dload Upload Total Spent Left Speed
      100 283k 0 283k 0 0 28056 0 --:--:-- 0:00:10 --:--:-- 23893^C

      OUTPUT mpg123

      ./mpg123 -vt test.mp3
      High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
      version 1.25.10; written and copyright by Michael Hipp and others
      free software (LGPL) without any warranty but with best wishes
      Decoder: x86-64 (SSE)
      Trying output module: test, device: <nil></nil>

      Terminal control enabled, press 'h' for listing of keys and functions.

      Playing MPEG stream 1 of 1: test.mp3 ...

      MPEG 1.0 L III cbr192 44100 j-s

      456+000 00:11.91+00:00.00 --- 100=100 192 kb/s 627 B acc 0 clip p+0.000
      [0:11] Decoding of test.mp3 finished.

      Until no problem the file (test.mp3) is read without problem.

      When I add the parameter to curl -H "Icy-MetaData: 1" it means add in the stream the stream (webradio) the metadata like (StreamTitle) the whole thing is generated in a file at the output (file test.mp3 ) see OUTPUT example:

      curl -H "Icy-MetaData:1" -v http://stream.c9.fr/c9.mp3 > test.mp3
      % Total % Received % Xferd Average Speed Time Time Time Current
      Dload Upload Total Spent Left Speed
      0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 Trying 66.70.200.63...
      TCP_NODELAY set
      0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to stream.c9.fr (66.70.200.63) port 80 (#0)

      GET /c9.mp3 HTTP/1.1
      Host: stream.c9.fr
      User-Agent: curl/7.64.1
      Accept: /
      Icy-MetaData:1

      • HTTP 1.0, assume close after body
        < HTTP/1.0 200 OK
        < Server: Icecast 2.4.2
        < Date: Sat, 11 May 2019 11:28:26 GMT
        < Content-Type: audio/mpeg
        < Cache-Control: no-cache
        < Expires: Mon, 26 Jul 1997 05:00:00 GMT
        < Pragma: no-cache
        < Access-Control-Allow-Origin: *
        < icy-br:192
        < ice-audio-info: channels=2;samplerate=44100;bitrate=192
        < icy-description:C9 Radio - Only Hits! - c9.fr
        < icy-genre:Top40 Hits Club Pop Rock Urban
        < icy-name:C9 Radio - Only Hits! - c9.fr
        < icy-pub:1
        < icy-url:https://www.c9.fr/
        < icy-metaint:16000
        <
        { [1400 bytes data]
        100 254k 0 254k 0 0 28445 0 --:--:-- 0:00:09 --:--:-- 23993^C

      What I can not understand is that reading with mpg123 the file test.mp3 is read with errors see OUTPUT mpg123

      OUTPUT mpg123

      mpg123 -vt test.mp3
      High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
      version 1.14.4; written and copyright by Michael Hipp and others
      free software (LGPL/GPL) without any warranty but with best wishes
      Decoder: x86-64 (SSE)

      Playing MPEG stream 1 of 1: test.mp3 ...

      MPEG 1.0, Layer: III, Freq: 44100, mode: Joint-Stereo, modext: 2, BPF : 627
      Channels: 2, copyright: No, original: Yes, CRC: No, emphasis: 0.
      Bitrate: 192 kbit/s Extension value: 0
      Frame# 24 [ 386], Time: 00:00.62 [00:10.08], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x69746c65 at offset 16008.
      Note: Trying to resync...
      Note: Skipped 65 bytes in input.
      Frame# 48 [ 361], Time: 00:01.25 [00:09.43], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0xeafffbb2 at offset 32373.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 72 [ 337], Time: 00:01.88 [00:08.80], RVA: off, Vol: 100(100)[layer3.c:454] error: big_values too large!
      [layer3.c:454] error: big_values too large!
      Note: Illegal Audio-MPEG-Header 0x9ffffbb2 at offset 48674.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 96 [ 313], Time: 00:02.50 [00:08.17], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0xe9fffbb2 at offset 64349.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 120 [ 289], Time: 00:03.13 [00:07.54], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x79fffbb2 at offset 80650.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 152 [ 257], Time: 00:03.97 [00:06.71], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x0ffffbb2 at offset 96325.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 176 [ 233], Time: 00:04.59 [00:06.08], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x4dfffbb2 at offset 112626.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 200 [ 209], Time: 00:05.22 [00:05.45], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0xb1fffbb2 at offset 128301.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 224 [ 185], Time: 00:05.85 [00:04.83], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x49fffbb2 at offset 144602.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 248 [ 161], Time: 00:06.47 [00:04.20], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x10fffbb0 at offset 160277.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 280 [ 129], Time: 00:07.31 [00:03.36], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x7ffffbb2 at offset 176578.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 304 [ 105], Time: 00:07.94 [00:02.74], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x41fffbb2 at offset 192252.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 328 [ 81], Time: 00:08.56 [00:02.11], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x88fffbb2 at offset 208554.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 352 [ 57], Time: 00:09.19 [00:01.48], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x41fffbb2 at offset 224228.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 376 [ 33], Time: 00:09.82 [00:00.86], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x0cfffbb2 at offset 240530.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 400 [ 9], Time: 00:10.44 [00:00.23], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x4dfffbb2 at offset 256204.
      Note: Trying to resync...
      Note: Skipped 1 bytes in input.
      Frame# 409 [ 1], Time: 00:10.68 [00:00.02], RVA: off, Vol: 100(100)
      [0:10] Decoding of test.mp3 finished.

      if I put the option "Icy-MetaData: 1" I have the same problem with my streaming program of (webradio) the error and in function mpg123_decode_frame example:

      err = mpg123_decode_frame(mh, &frame_offset, &audio, &done);

      in the mpg123_feed function I do not have any example errors:

      mpg123_feed(mh, (const unsigned char *) DataBufferMP3, Counternmemb);

      is there not a way to with the option "Icy-MetaData: 1" to play the stream with (mpg123_decode_frame) without errors of messages:

      Frame# 24 [ 386], Time: 00:00.62 [00:10.08], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x69746c65 at offset 16008.
      Note: Trying to resync...
      Note: Skipped 65 bytes in input.

      to skip the metadata and read only mp3 streams.

      thank you

      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/mpg123/bugs/278/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #278

  • Thomas Orgis

    Thomas Orgis - 2019-05-22

    I have some trouble parsing your last message. It has the whole thread in it without clear quoting. I guess you are trying to use sf.net via mail and it does not interact well with the top-posting in the replies?

    About skipping the ICY data yourself and keep using the feeder API, this is a working program:

    /*
        mpglib: test program for libmpg123, in the style of the legacy mpglib test program
    
        copyright 2007 by the mpg123 project - free software under the terms of the LGPL 2.1
        see COPYING and AUTHORS files in distribution or http://mpg123.org
        initially written by Thomas Orgis
    
        This program does not handle the reads being interrupted by signals. It is
        just an example to illustrate libmpg123 usage.
    */
    
    #include <mpg123.h>
    
    /* unistd.h is not available under MSVC, 
     io.h defines the read and write functions */
    #ifndef _MSC_VER
    #include <unistd.h>
    #else
    #include <io.h>
    #endif
    
    #ifdef _WIN32
    #include <fcntl.h>
    #endif
    
    #include <stdio.h>
    #include <stdlib.h>
    
    #define INBUFF  16384
    #define OUTBUFF 32768 
    
    int main(int argc, char **argv)
    {
        size_t size;
        unsigned char buf[INBUFF];  /* input buffer  */
        unsigned char out[OUTBUFF]; /* output buffer */
        ssize_t len;
        int ret;
        size_t in = 0, outc = 0;
        mpg123_handle *m;
    
    #ifdef _WIN32
    _setmode(_fileno(stdin),_O_BINARY);
    _setmode(_fileno(stdout),_O_BINARY);
    #endif
    
        mpg123_init();
        m = mpg123_new(argc > 1 ? argv[1] : NULL, &ret);
        if(m == NULL)
        {
            fprintf(stderr,"Unable to create mpg123 handle: %s\n", mpg123_plain_strerror(ret));
            return -1;
        }
        mpg123_param(m, MPG123_VERBOSE, 2, 0); /* Brabble a bit about the parsing/decoding. */
        char* icyint = getenv("ICY_INTERVAL");
        long icy_interval = 0;
        if(icyint)
        {
            icy_interval = atol(icyint);
            if(icy_interval < 0)
                icy_interval = 0;
        }
        long next_icy = icy_interval;
        char *icy_meta = NULL;
        int icy_meta_size = 0;
    
        /* Now mpg123 is being prepared for feeding. The main loop will read chunks from stdin and feed them to mpg123;
           then take decoded data as available to write to stdout. */
        mpg123_open_feed(m);
        if(m == NULL) return -1;
    
        fprintf(stderr, "Feed me some MPEG audio to stdin, I will decode to stdout.\n");
        while(1) /* Read and write until everything is through. */
        {
            int handle_icy = 0;
            if(next_icy && next_icy <= INBUFF)
            {
                len = read(0,buf,next_icy);
                handle_icy = 1;
            }
            else
            {
                len = read(0,buf,INBUFF);
                if(len <= 0)
                {
                    fprintf(stderr, "input data end\n");
                    break;
                }
                if(next_icy)
                    next_icy -= len;
            }
            in += len;
            /* Feed input chunk and get first chunk of decoded audio. */
            ret = mpg123_decode(m,buf,len,out,OUTBUFF,&size);
            if(ret == MPG123_NEW_FORMAT)
            {
                long rate;
                int channels, enc;
                mpg123_getformat(m, &rate, &channels, &enc);
                fprintf(stderr, "New format: %li Hz, %i channels, encoding value %i\n", rate, channels, enc);
            }
            write(1,out,size);
            outc += size;
            while(ret != MPG123_ERR && ret != MPG123_NEED_MORE)
            { /* Get all decoded audio that is available now before feeding more input. */
                ret = mpg123_decode(m,NULL,0,out,OUTBUFF,&size);
                write(1,out,size);
                outc += size;
            }
            if(ret == MPG123_ERR){ fprintf(stderr, "some error: %s", mpg123_strerror(m)); break; }
    
            if(!handle_icy)
                continue;
            if(len != next_icy)
            {
                fprintf(stderr, "Missing bytes towards ICY data. Just the end?\n");
                break;
            }
            {
                unsigned char icybyte = 0;
                if(read(0, &icybyte, 1) != 1)
                {
                    fprintf(stderr, "Missing ICY size byte.\n");
                    break;
                }
                int icys = icybyte*16;
                icy_meta_size = icys+1 > icy_meta_size ? icys+1 : icy_meta_size;
                icy_meta = realloc(icy_meta, icy_meta_size);
                if(!icy_meta)
                {
                    fprintf(stderr, "Cannot allocate ICY metadata buffer.\n");
                    break;
                }
                if(read(0, icy_meta, icys) != icys)
                {
                    fprintf(stderr, "Missing ICY data.\n");
                    break;
                }
                icy_meta[icys] = 0;
                /* A real-world program would need to filter control characters. */
                if(icys)
                    fprintf(stderr, "ICY meta: %s\n", icy_meta);
                next_icy = icy_interval;
            }
        }
        fprintf(stderr, "%lu bytes in, %lu bytes out\n", (unsigned long)in, (unsigned long)outc);
    
        free(icy_meta);
        /* Done decoding, now just clean up and leave. */
        mpg123_delete(m);
        mpg123_exit();
        return 0;
    }
    

    It gives this output:

    shell$ ICY_INTERVAL=16000 ./mpglib < stream.mp3 |out123
    Feed me some MPEG audio to stdin, I will decode to stdout.
    Note: Junk at the beginning (0x43512f90)
    New format: 44100 Hz, 2 channels, encoding value 208
    ICY meta: StreamTitle='Shaggy - You (Feat. Alexander Stewart)';
    Missing bytes towards ICY data. Just the end?
    298926 bytes in, 2188800 bytes out
    

    You can omit the pipe to out123 (for listening) and redirect to a file or /dev/null instead. I hope you can work out what goes wrong in your program by comparing the logic.

     

    Last edit: Thomas Orgis 2019-05-22
  • Didier Castellacci

    thank you for finding an alternative.

    int mpg123_replace_reader_handle (mpg123_handle * mh, ssize_t () (void , void , size_t) r_read, off_t () (void , off_t, int) r_lseek, void () (void *) cleanup)

    How I use these settings ("mh" ok I know, "r_read" I do not know, "r_lseek" I do not know, "cleanup" I do not know)
    and where I put it in the code

    Here are the parameters I use in the calling order:

    mpg123_init();
    mh = mpg123_new(NULL, NULL);
    mpg123_open_feed(mh);

    mpg123_param(mh, MPG123_ICY_INTERVAL, 16000, 0)

    mpg123_feed(mh, (const unsigned char*) buffer, size * nmemb);
    mpg123_decode_frame(mh, &frame_offset, &audio, &done);

    Thank you
    Didier

    Alternatively, if you have to stay with the feeder, you'll just have to cut out the ICY block each 16000 bytes yourself here.

    I tried to cut the ICY block every 16,000 bytes. it does not work he always finds the error message

    Frame# 24 [ 386], Time: 00:00.62 [00:10.08], RVA: off, Vol: 100(100)Note: Illegal Audio-MPEG-Header 0x69746c65 at offset 16008.
    Note: Trying to resync...
    Note: Skipped 65 bytes in input.

    I cut the buffer that is to say example:

    unsigned char DataBufferMP3 = (unsigned char ) malloc(nmemb);

    for (int i = 0; i < nmemb; i++)
    {
    if(CounterBuffer <= 15999)
    DataBufferMP3[i] = ((const unsigned char *) buffer)[i];

    Thank you
    Didier

     
  • Didier Castellacci

    /*
    mpglib: test program for libmpg123, in the style of the legacy mpglib test program

    copyright 2007 by the mpg123 project - free software under the terms of the LGPL 2.1
    see COPYING and AUTHORS files in distribution or http://mpg123.org
    initially written by Thomas Orgis
    
    This program does not handle the reads being interrupted by signals. It is
    just an example to illustrate libmpg123 usage.
    

    */

    mpglib is an example without streaming
    we do not see how mpglib manages intervalls without streaming

    Thank you
    Didier

     
  • Thomas Orgis

    Thomas Orgis - 2019-09-28
    • status: open --> closed-invalid
     
  • fred vs

    fred vs - 2025-02-19

    Hello.

    I know, it is a old issue and I did have the same problem of the byte with error illegal entry.
    And that cause a delay/click in sound very boring.
    Even adding: mpg123_param(mh, MPG123_ICY_INTERVAL, 16000, 0)

    Till I read this:

    / Enumeration of the parameters types that it is possible to set/get. */
    enum mpg123_parms
    ....
    MPG123_ICY_INTERVAL, /
    < Stream contains ICY metadata with this interval (integer).
    Make sure to set this before opening a stream.*/

    mpg123_param(mh, MPG123_ICY_INTERVAL, 16000, 0) must be placed BEFORE opening the stream.

    Doing this, the sound is clear and no more error in console.

    I have seen that Didier Castelli did the same error maybe it could help (but I agree a few to late ;-) )

    Fre;D

     

Log in to post a comment.

MongoDB Logo MongoDB