Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

[ Create a new account ]

Which Open Source Video Apps Use SMP Effectively?

Posted by kdawson on Wednesday July 23, @04:54PM
from the on-the-one-core-on-the-other-core dept.
ydrol writes "After building my new Core 2 Quad Q6600 PC, I was ready to unleash video conversion activity the likes of which I had not seen before. However, I was disappointed to discover that a lot of the conversion tools either don't use SMP at all, or don't balance the workload evenly across processors, or require ugly hacks to use SMP (e.g. invoking distributed encoding options). I get the impression that open source projects are a bit slow on the uptake here? Which open source video conversion apps take full native advantage of SMP? (And before you ask, no, I don't want to pick up the code and add SMP support myself, thanks.)"

Related Stories

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • ffmpeg (Score:5, Informative)

    by bconway (63464) on Wednesday July 23, @04:55PM (#24310803) Homepage

    Use the -threads switch.

    • Similarly, mencoder supports threads=# where # is something between 1 and 8.
    • Re:ffmpeg (Score:5, Insightful)

      by Albanach (527650) on Wednesday July 23, @05:03PM (#24310949) Homepage

      Or just convert 2 videos at once, or 4 for a quad core etc. They did suggest they have lots to convert, and it's a pretty easy way to get all available cores working hard.

        • Re:ffmpeg (Score:5, Interesting)

          by Tanktalus (794810) on Wednesday July 23, @06:29PM (#24311977) Journal

          That sounds like a lot of work... I just used make:

          %.mpg: %.avi
          tovid -ntsc -dvd -noask -ffmpeg -in "$<" -out "$(basename $@)"

          all: $(subst .avi,.mpg,$(wildcard */*.avi))

          Then I just ran "make -j4". All four processors working like mad, with a minimal of effort.

          (You may need to change the wildcard for your own scenario.)

    • Re:ffmpeg (Score:5, Informative)

      by ydrol (626558) on Wednesday July 23, @06:26PM (#24311931)
      Darn, I forgot a minor detail in my question. I was really asking about the various front-end apps (dvd::rip, k9copy, acidrip etc), I got the impression that none seem to notice they are running on an SMP platform and pass the necessary switches by default to the backend.

      Some may argue this is a good thing, but for the time being SMP is the way forward for faster processing as MHz has maxed out, in consumer PCS. So when they start buying octo-core CPUs they dont expect it to run at 1/8th speed by default.

      I was also being a bit lazy. I could have checked up on each app in turn, but I asked /. instead.

      • Re:ffmpeg (Score:5, Informative)

        by m0rph3us0 (549631) on Wednesday July 23, @05:47PM (#24311515)

        No it doesn't the only time you want to use multi-threading in a single CPU environment is because asynchronous methods for IO are unavailable or the code would be too difficult to re-architect to use asynchronous IO. If the application is seriously IO bound threads can even make the situation worse by causing random IO patterns.

        Ideally, the number of threads a program uses should be no more than the number of processors available. Otherwise, you are wasting time context switching instead of processing.

  • transocde [transcoding.org]uses separate processes for everything.
  • by DigitAl56K (805623) * on Wednesday July 23, @05:09PM (#24311043)

    don't balance the workload evenly across processors

    Why is balancing the load evenly important, as long as one thread is not bottlenecking the others? Loading a particular core or set of cores might even be beneficial depending on the cache implementation, especially when other applications are also contending for CPU time.

    Sure, a nice even load distribution might be an indicator for good design, but it doesn't have to apply in every case. I don't think software should be designed so you can be pleased with the aesthetics of the charts in task manager.

      • by DigitAl56K (805623) * on Wednesday July 23, @05:34PM (#24311347)

        It's still possible to load all cores 100%.

        A video decoder that I'm working with, for example, currently uses only as many threads as necessary for real-time playback. So for example if one core can do the job only one core is used. If the decoder looks like it might start falling behind more threads are given work to do. Ultimately, if your system is failing to keep up all cores will be fully leveraged.

        However, so long as only some cores are required the others are 100% available to other processes, including their cache (if it's independent). I'm not sure how power management is implemented but perhaps it's even possible for the unused cores to do power saving, leading to longer batter life for laptops/notebooks, etc.

        the idea is to make maximal use of your available resources, right?

        No, the idea is to make the best use of your resources. I'm not trying to say that load balancing is wrong. I'm just saying that processes that don't appear to be balanced are not necessarily poorly designed or operating incorrectly.

  • Handbrake (Score:5, Informative)

    by vfs (220730) on Wednesday July 23, @05:18PM (#24311163) Journal
    Handbrake [handbrake.fr] has always used both of the cores on my system for transcoding.
  • by Lumenary7204 (706407) on Wednesday July 23, @05:21PM (#24311195)

    The problem with MPEG encoding and decoding is that the data itself is not well suited to multi-threaded analysis.

    Multi-threading is most efficient when it is applied to discrete data sets that have little or no dependency on each other.

    For example, suppose I have a table with four columns -- three holding input values (A, B, and C) and one holding an output value (X). If the data in a given row of the table has nothing to do with the data in any other row, multi-threading works efficiently, because none of the threads are waiting for data from any of the other threads. If I want to process multiple rows at once, I simply spawn additional threads.

    On the other hand, for data such as MPEG video, the composition of the next frame is equal to the composition of the current frame, plus some delta transformation - the changed pixels.

    This introduces a dependency which precludes efficient multi-threaded processing, because each succeeding frame depends on the output of the calculations used to generate the prior frame. Even if more than one core is dedicated to processing the video stream, one core would wind up waiting on another, because the output from the first core would be used as the input to the second.

    • keyframes (Score:5, Informative)

      by Anonymous Coward on Wednesday July 23, @05:29PM (#24311297)

      Actually, the MPEG stream resets itself every n frames or so (n is often a number like 8, but can vary depending on the video content). These are called keyframes (K) and the delta frames (called P and I frames) are generated against them. Because of this, it is really easy to apply parallel processing to video encoding.

      • Re:keyframes (Score:5, Informative)

        by DigitAl56K (805623) * on Wednesday July 23, @06:14PM (#24311839)

        Actually, the MPEG stream resets itself every n frames or so (n is often a number like 8, but can vary depending on the video content).

        That is not true for MPEG-4 unless you have specifically constrained the I/IDR interval to an extremely short interval, and doing so severely impacts the efficiency of the encoder because I-frames are extremely expensive compared to other types.

        Keyframes are usually inserted when temporal prediction fails for some percentage of blocks, or using some RD evaluation based on the cost of encoding the frame. Therefore unless the encoder has reached the maximum key interval the I frame position requires that motion estimation is performed, and thus you can't know in advance where to start a new GOP.

        In H.264 due to multiple references you would certainly have issues to contend with since long references might cross I-frame boundaries, which is why there is the distinction of "IDR" frames, and this would certainly not be possible threading at keyframe level.

        Granted, for MPEG1&2 encoders threading at keyframes is a possibility, although still not one I'd personally favor.

    • by Omega996 (106762) on Wednesday July 23, @05:36PM (#24311367)
      theoretically, couldn't an encoder scan the data stream for keyframes, chunk the data from keyframe to the next keyframe, and then queue up the keyframe+delta information for multiple cores? That way, each core has something to do that isn't dependent upon the completion of something else.
      i'd think that n-1 cores/threads/whatever to process the chunked data, and the last core/thread/whatever to handle overhead and i/o scheduling would run pretty nicely on a multi-core machine.
    • You could of course split each frame in slices, and process these in parallel. Or skip the video N frames between each core, with N being the number of frames between MPEG keyframes. Or have core 1 do the luma and core 2 and 3 the chroma channels. Or pipeline the whole thing and have core 1 do the DCT, core 2 the dequant etc. and have core 3 reconstruct the output reference frame while core 1 already starts the next frame.

      Plenty of ways to parallelize decoding, and even more for encoding...

  • avidemux (Score:5, Informative)

    by Unit3 (10444) on Wednesday July 23, @05:46PM (#24311489) Homepage

    I've noticed a lot of talk about commandline options, but not the nice guis that use them. Avidemux is open source, cross-platform, gives you a decent interface, and uses multithreaded libraries like ffmpeg and x264 on the backend to do the encoding, so it generally makes optimal use of your multicore system.

  • by sjf (3790) on Wednesday July 23, @07:51PM (#24312809)

    As other commenters have said, decoding video is not, per se, a trivially parallelized algorithm. Especially for modern codecs with lots of temporal encoding. MJPEG would be easily parallelized, buy you'd have to be dealing with fairly ancient sources...MediaComposer 1 for instance.

    However, there are different classes of "video app" that are good targets for parallelization. Real world video editing for instance: consider multiple streams of video with overlays, rotations, effects etc. Video and audio decoding can happen in parallel, you can pipeline the effects stages so that each effect is handed off to another core. Modern video editing systems do this with aplomb.

    I'm from the commercial end of this so, I can't comment much on open source alternatives. But I will say that a lot of the algorithms in certain products are highly tuned to the particular CPU type.
    And they're smart enough to distribute work across only as many cores as actually exist.

    Finally. Don't forget that optimization is hard. You have to consider the speed of the hard drive, the cost of sharing data between threads and cpu caches and a bunch of other real constraints. Any half decent cpu of the last five years or so can easily decode most video faster than it can be read and written to disk. So long as this is true, you won't get any benefit from parallelization.

    • Beat me to it! (Score:5, Informative)

      by BLKMGK (34057) <morejunk4meNO@SPAMhotmail.com> on Wednesday July 23, @05:05PM (#24310985) Homepage

      x264 via meGUI from Doom9 is what I use to compress HD-DVD and BD movies - also on a quad core. I have some tutorials posted out and about on how I'm doing it. Near as I can tell you cannot dupe the process on Linux due to the crypto - Slysoft's AnyDVD-HD is needed.

      Playback - I use XBMC for Linux. It is also SMP enabled using the ffmpeg cabac patch. the developers of this project have been VERY aggressive at taking cutting edge improvements to the likes of ffmpeg and incorporating them into the code. Since Linux has no video acceleration of H.264 SMP really helps on high bitrate video!

      • Re:Simple... (Score:5, Informative)

        by j00r0m4nc3r (959816) on Wednesday July 23, @05:21PM (#24311199)
        Running multiple instances of the same code concurrently in multiple threads is simple. Even running mutually exclusive parts of the same code concurrently in separate threads is easy. Converting complex serial algorithms to effectively utilize multiple cores is generally not simple. And writing code that can scale and balance across n number of cores/threads is extremely hard. There are all sorts of synchronization issues to deal with, scheduling issues, data transport issues, etc.. and it becomes increasingly hard to debug code the more cores/threads you throw in. I think the stigma is justified.