Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8556279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:18:41+00:00 2026-06-11T15:18:41+00:00

ANSWER https://stackoverflow.com/a/12507520/962890 it was so trivial.. args! but lots of good information received. thanks

  • 0

ANSWER

https://stackoverflow.com/a/12507520/962890

it was so trivial.. args! but lots of good information received. thanks to everyone.

EDIT

link to github: https://github.com/MarkusPfundstein/stream_lame_testing

ORIGINAL POST

i have some questions regarding IPC through pipelines. My goal is to receive MP3 data per TCP/IP stream, pipe it through LAME to decode it to wav, do some math and store it on disk (as a wav). I am using non blocking IO for the whole thing.
What irritates me a bit is that the tcp/ip read is way more fast than the pipe line trough lame. When i send a ~3 MB mp3 the file gets read on the client side in a couple of seconds. In the beginning, i can also write to the stdin of the lame process, than it stops writing, it reads the rest of the mp3 and if its finished i can write to lame again. 4096 bytes take approx 1 second (to write and read from lame). This is pretty slow, because i want to decode my wav min 128kbs.

The OS Is a debian 2.6 kernel on a this micro computer:

https://www.olimex.com/dev/imx233-olinuxino-maxi.html

65 MB RAM
400 MhZ

ulimit -n | grep pipe returns 512 x 8 , means 4096 which is ok. Its a 32 bit system.

The weird thing is that

my_process | lame –decode –mp3input – output.wav

goes very fast.

Here is my fork_lame code (which shall essentialy connect stout of my process to stdin of lame and visa versa)

static char * const k_lame_args[] = {
  "--decode",
  "--mp3input",
  "-",
  "-",
  NULL
};

static int
fork_lame()
{
  int outfd[2];
  int infd[2];
  int npid;
  pipe(outfd); /* Where the parent is going to write to */
  pipe(infd); /* From where parent is going to read */
  npid = fork();
  if (npid == 0) {
    close(STDOUT_FILENO);
    close(STDIN_FILENO);
    dup2(outfd[0], STDIN_FILENO);
    dup2(infd[1], STDOUT_FILENO);
    close(outfd[0]); /* Not required for the child */
    close(outfd[1]);
    close(infd[0]);
    close(infd[1]);
    if (execv("/usr/local/bin/lame", k_lame_args) == -1) {
      perror("execv");
      return 1;
    }
  } else {
    s_lame_pid = npid;
    close(outfd[0]); /* These are being used by the child */
    close(infd[1]);
    s_lame_fds[WRITE] = outfd[1];
    s_lame_fds[READ] = infd[0];
  }
  return 0;
}

This are the read and write functions. Please not that in write_lame_in. when i write to stderr instead of s_lame_fds[WRITE], the output is nearly immedieatly so its definitly the pipe through lame. But why ?

static int
read_lame_out() 
{
  char buffer[READ_SIZE];
  memset(buffer, 0, sizeof(buffer));
  int i;
  int br = read(s_lame_fds[READ], buffer, sizeof(buffer) - 1);
  fprintf(stderr, "read %d bytes from lame out\n", br);
  return br;
}

static int
write_lame_in()
{
  int bytes_written;
  //bytes_written = write(2, s_data_buf, s_data_len);
  bytes_written = write(s_lame_fds[WRITE], s_data_buf, s_data_len);
  if (bytes_written > 0) {
    //fprintf(stderr, "%d bytes written\n", bytes_written);
    s_data_len -= bytes_written;
    fprintf(stderr, "data_len write: %d\n", s_data_len);
    memmove(s_data_buf, s_data_buf + bytes_written, s_data_len);
    if (s_data_len == 0) {
      fprintf(stderr, "finished\n");
    }
  } 

  return bytes_written;
}

static int
read_tcp_socket(struct connection_s *connection)
{
  char buffer[READ_SIZE];
  int bytes_read;
  bytes_read = connection_read(connection, buffer, sizeof(buffer)-1);
  if (bytes_read > 0) {
    //fprintf(stderr, "read %d bytes\n", bytes_read);
    if (s_data_len + bytes_read > sizeof(s_data_buf)) {
      fprintf(stderr, "BUFFER OVERFLOW\n");
      return -1;
    } else {
      memcpy(s_data_buf + s_data_len,
             buffer,
             bytes_read);
      s_data_len += bytes_read;
    }
    fprintf(stderr, "data_len: %d\n", s_data_len);
  }
  return bytes_read;
}

The select stuff is pretty basic select logic. All blocks are non blocking of course.

Anyone any idea? I’d really appreciate any help 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:18:43+00:00Added an answer on June 11, 2026 at 3:18 pm

    Oops! Did you check your LAME output?

    Looking at your code, in particular

    static char * const k_lame_args[] = {
      "--decode",
      "--mp3input",
      "-",
      "-",
      NULL
    };
    

    and

    if (execv("/usr/local/bin/lame", k_lame_args) == -1) {
    

    means you are accidentally omitting the --decode flag as it will be argv[0] for LAME, instead of the first argument (argv[1]). You should use

    static char * const k_lame_args[] = {
      /* argv[0] */  "lame",
      /* argv[1] */  "--decode",
      /* argv[2] */  "--mp3input",
      /* argv[3] */  "-",
      /* argv[4] */  "-",
                     NULL
    };
    

    instead.

    I think you are seeing a slowdown because you’re accidentally recompressing the MP3 audio. (I noticed this just a minute ago, so haven’t checked if LAME does that if you omit the --decode flag, but I believe it does.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would you do a similar function as rsplak's answer here https://stackoverflow.com/a/7079032/1330629 but include
I found this answer to this question https://stackoverflow.com/a/7244888/1473523 , but in my situation am
Based on the answer I received on this question ( https://stackoverflow.com/questions/1911969/... ) I have
I try to use wilcards in Android.mk with help of this answer https://stackoverflow.com/a/8459242/1039175 But
Let me reformulate, as the answer https://stackoverflow.com/questions/951907/where-are-my-visitors-going was absolutely correct, but my question not
I have seen this answer https://stackoverflow.com/a/9243472/563381 And while it works well visual as soon
Using an old answer to search for a file in tcl: https://stackoverflow.com/a/435094/984975 First lets
My question is in relation this this answer. https://stackoverflow.com/a/8773953/1297775 I have read at many
I am using the script from this answer https://stackoverflow.com/a/1681410/22 to insert a launch application
Here is a quote from https://stackoverflow.com/users/893/greg-hewgill answer to Explain Python's slice notation . Python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.