Jump to content
The Dark Mod Forums

Writing a multi-thredded wrapper around an audio encoder in BASH...


lost_soul

Recommended Posts

Operating under the principle that nothing ever goes fast enough and I have a hex-core CPU, I came up with the following.

 

Problem: The audio encoders (flac, oggenc, opusenc) all use a single core. This means if you want to encode a massive collection of music, it is going much slower than it can.

 

Proposed solution a: We create a database in /tmp called files.lst. Then we run a script that searches the current directory and ALL sub directories for any .wav or .flac files. On each file that is found, fork and do the following:

*check /tmp/files.lst for the name of the audio file and its current status. Status can be either %ip for in progress, %fn for finished, or (unlisted) for pending. This way we don't try to encode the same file twice. If the file status is %ip or %fn, we ignore it, otherwise, we spawn an oggenc process on the file to encode it and we add it to the database in /tmp/files.lst as %ip. When that oggenc is finished, we update the status to %fn.

*We also need a way to limit the number of forks running at a time, otherwise you will get 900 oggenc processes running in a directory because it had 900 wav files.

 

Proposed solution b: We split the input file into chunks based on how many CPU cores are detected (or specified). Then we pass the chunks of audio to separate instances of oggenc and encode them all at the same time. When that is finished, we take the multiple outputs from all the oggenc processes and mash them together into a single audio file representing the encoded version of the original wav file before it was split.

 

Which way is better, and is there already a script to do this sort of thing?

Edited by lost_soul
  • Like 2

--- War does not decide who is right, war decides who is left.

Link to comment
Share on other sites

I always though the second solution was the way to properly implement multi threading. Programs like EZ Audio Converter let you set how many threads to use for encoding/transcoding audio, but what it does is assign each core a separate audio file. So you can do like 8 files at once.

But if you only have 4 files to transcode then having 4 extra cores will do nothing. So I like your way.

I always assumed I'd taste like boot leather.

 

Link to comment
Share on other sites

Couldn't you also just run a do;while loop in there that, say every 5sec queries processes, pipes that to a text file using grep so as to count the number of .ogg encoding threads running, and if there are <X amount it can add until it reaches max, at which point it just queries until spots open up? The X max amount could be set at the script initialization with a processor core count. (I'm a linux scripting noob) :\

 

Of course your solution is the more elegant, proper, solution.

Edited by Lux
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • Ansome

      Query: when was the last time a zombie in a video game was unnerving or scary to you? I'm chipping away at my anniversary submission and I've been trying to gather opinions on the subject. I'm perfectly capable of lighting them well, changing their sfx, and creating effective ambience, but I'm worried that zombies at their core are just too overdone to be an effective payoff to the tension I'm creating.
      · 4 replies
    • nbohr1more

      The Lieutenant 3 is out! Congrats Frost_Salamander! ( raising awareness )
      · 2 replies
    • OrbWeaver

      Has anyone had any luck with textures from Polyhaven? Their OpenEXR normal maps seem too washed out and give incorrect shading in the engine.
      · 5 replies
    • datiswous

      I tried to upscale the TDM logo video. First try:

      briefing_video.mp4 You can test it ingame by making a copy of the core tdm_gui.mtr and place it in your-tdm-root/materials/ , then edit line 249 of that file into the location where you placed the new briefing.mp4 file.
      What I did was I extracted all the image files, then used Upscayl to upscale the images using General photo (Real-Esrgan) upscale setting and then turn it back into a video.
      I might have to crop it a bit, the logo looks smaller on screen (or maybe it's actually better this way?). My video editor turned it into a 16:9 video, which I think overal looks better than 1:1 video of original.
      · 1 reply
    • nbohr1more

      Trying to be productive on my down-time before Capcom releases Akuma and my son is constantly on my PC playing Street Fighter...
      · 1 reply
×
×
  • Create New...