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

    • nbohr1more

      The FAQ wiki is almost a proper FAQ now. Probably need to spin-off a bunch of the "remedies" for playing older TDM versions into their own article.
      · 1 reply
    • nbohr1more

      Was checking out old translation packs and decided to fire up TDM 1.07. Rightful Property with sub-20 FPS areas yay! ( same areas run at 180FPS with cranked eye candy on 2.12 )
      · 3 replies
    • taffernicus

      i am so euphoric to see new FMs keep coming out and I am keen to try it out in my leisure time, then suddenly my PC is spouting a couple of S.M.A.R.T errors...
      tbf i cannot afford myself to miss my network emulator image file&progress, important ebooks, hyper-v checkpoint & hyper-v export and the precious thief & TDM gamesaves. Don't fall yourself into & lay your hands on crappy SSD
       
      · 7 replies
    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 7 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
×
×
  • Create New...