Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Software Graphics

Which Open Source Video Apps Use SMP Effectively? 262

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.)"
This discussion has been archived. No new comments can be posted.

Which Open Source Video Apps Use SMP Effectively?

Comments Filter:
  • ffmpeg (Score:5, Informative)

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

    Use the -threads switch.

    • Agreed. ffmpeg worked quite nicely for me during my DVD-ripping heyday. Although, it seems that it would rip audio and video in separate threads. While an improvement over the traditional, linear way of doing things, I would still see 1 CPU maxed out (video encoding), while the CPU encoding audio was only at about 1/3 capacity.
    • Re:ffmpeg (Score:5, Informative)

      by morgan_greywolf ( 835522 ) * on Wednesday July 23, 2008 @03:58PM (#24310873) Homepage Journal
      Similarly, mencoder supports threads=# where # is something between 1 and 8.
      • Re: (Score:2, Insightful)

        by Z00L00K ( 682162 )
        And it may or may not be useful to actually rune more than one thread per kernel. It depends on the encoder and application how many threads you shall run, so the best is to test with 1, 2 and 4 threads per kernel.
        • Re: (Score:3, Informative)

          by sp332 ( 781207 )

          And it may or may not be useful to actually rune more than one thread per kernel. It depends on the encoder and application how many threads you shall run, so the best is to test with 1, 2 and 4 threads per kernel.

          Isn't that per-core, not per-kernel?

    • Re:ffmpeg (Score:5, Insightful)

      by Albanach ( 527650 ) on Wednesday July 23, 2008 @04: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: (Score:3, Informative)

        by i.r.id10t ( 595143 )

        Yup, with separate disks to work on to remove (mostly) the disk i/o contention, just let each process run happily away.

      • by init100 ( 915886 )

        That's exactly what I do. I also wrote a scheduler in Python that starts new jobs when the previous ones are completed. It keeps the number of running encoding processes equal to the number of processors/cores.

        To get the optimal scheduling order, it figures out the length of each input file (using midentify from the mplayer/mencoder distribution), and then sorts the jobs so that the longest jobs will be processed first (it assumes that processing time is roughly proportional to input file length (in seconds

        • Re:ffmpeg (Score:5, Interesting)

          by Tanktalus ( 794810 ) on Wednesday July 23, 2008 @05: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: (Score:3, Insightful)

            by TheLink ( 130905 )
            Ah but figuring out "make" might require too much wetware CPU time for most people ;).

            "Why is it not working? Oops messed up tabs and spaces", etc.
    • Re: (Score:2, Interesting)

      by fm6 ( 162816 )

      So why is threading off by default? In a CPU-intensive application like this, multithreading always makes sense, even on a single-core system.

      • Re:ffmpeg (Score:5, Informative)

        by m0rph3us0 ( 549631 ) on Wednesday July 23, 2008 @04: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.

        • 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.

          An exception to this kind of rule should really be made for graphical user interfaces. In the case of GUI applications, time wasted in context switching is less important than keeping the UI responsive and the user happy.

          Any kind of heavy lifting (IO-blocking or otherwise) should really be done on a different thread than the one that is responsible for handling the user interface. This allows the user interface to stay responsive, providing the user with feedback (progress bar, time estimate, reassurance th

          • Re: (Score:2, Insightful)

            by sick_soul ( 794596 )

            Just want to inform you that threads nor any other
            multiprogramming mechanisms are necessary for
            responsive user interfaces,
            and that IO multiplexing in particular does not require
            threads at all.

            You can solve both with threads, but you don't have to.
            And in most common cases it is much better not to;
            it seems that threads continue to be one of the most
            misused and misunderstood of the programming concepts.

            • Re: (Score:3, Insightful)

              by slimjim8094 ( 941042 )

              Perhaps. But threads are far more versatile - if they're done well.

              So our video app has a sound-processing thread, a video processing thread, and a UI thread. If it's implemented well (don't read or write twice, have a common buffer), it'll run with the same or near performance as a one-threaded program on a one-processor/core system.

              But on a multicore/processor system no extra work is needed to take advantage of the cores. If we have three cores, it'll run automatically across cores for a massive performan

              • Re: (Score:3, Interesting)

                by QuoteMstr ( 55051 )

                Yes, you can use threads well. But with less effort (taking into account synchronization and debugging), you can make the asynchronous tasks independent programs instead of threads. Your video and sound processing threads sound like perfect candidates for being made into independent programs.

                A task being an independent program affords several advantages. For example, it's easier to test an independent program, especially in a test harness. An independent program can be run by itself. And it's very clear wha

      • Threading is sometimes broken on the OS, or sometimes it varies between revisions.

        FreeBSD for instance has been in the middle of changes to the threading system and there was a bug in the 6.x branch which wasn't in either 7.x or current. Defaulting to off if you're not sure how well threading is going to be handled is probably better than defaulting to something that could be broken.

        Anybody who knows that they need threading and decides to turn it on is likely to know whether or not threading is broken. Or

    • Re:ffmpeg (Score:5, Informative)

      by ydrol ( 626558 ) on Wednesday July 23, 2008 @05: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: (Score:3, Informative)

        by elgaard ( 81259 )

        I have not tried it. But e.g. k9copy uses mencoder.
        So if you just put something like "x264ops=threads=auto" in you mencoder.conf file it might work also from k9copy.
        k9copy also have a settings menu where you can tune options to mencoder for various codecs.

  • by morgan_greywolf ( 835522 ) * on Wednesday July 23, 2008 @03:55PM (#24310813) Homepage Journal
    transocde [transcoding.org]uses separate processes for everything.
  • x264 (Score:3, Insightful)

    by Anonymous Coward on Wednesday July 23, 2008 @03:58PM (#24310869)

    x264 use slices and scales pretty well across multiple cores. I use it on windows via megui, but you could easily use it in Linux as well. You could use mencoder to pipe out raw video to a fifo and use x264 to do the actual conversion, for instance.

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

      by BLKMGK ( 34057 ) <morejunk4me.hotmail@com> on Wednesday July 23, 2008 @04:05PM (#24310985) Homepage Journal

      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!

  • VisualHub... (Score:4, Informative)

    by e4g4 ( 533831 ) on Wednesday July 23, 2008 @03:59PM (#24310881)
    ...makes excellent use of multiple cores. It is however Mac-only. Interestingly, what it does is split a file into chunks and spawns multiple ffmpeg processes to do the conversion. Which is to say, perhaps you can do some (relatively simple) scripting with ffmpeg that will do the job.
  • x264 and avisynth (Score:3, Informative)

    by PhrostyMcByte ( 589271 ) <phrosty@gmail.com> on Wednesday July 23, 2008 @04:01PM (#24310913) Homepage
    x264 and avisynth can make pretty decent use of threads. check out meGUI.
    • by figleaf ( 672550 )

      Yeah x264 is great. There is a slight quality degradation (albeit you have to look really hard to visually determine the difference) if you use multiple threads.
      I once used a batch file to encode several gigs of my family vacation MJPEG videos to H.264 using x264 in a single background thread over a period of 10 days.
      With some heavy-duty post processing (for noise removal etc) it encoded about a 1 GB source/day. There was no perf. degradation with my other apps (games, email etc.) on account of the video en

    • by Henriok ( 6762 )

      ffmpegX for OSX uses x264 and it's transcoding like mad on my eight core Mac Pro. A 2h Video_TS film conversion to iPhone-ready double pass h264/MPEG4.. in less 20 minutes. Using 720-760% CPU, i.e. just the right ammount for me that uses the machine for other tasks as well.

  • by DigitAl56K ( 805623 ) * on Wednesday July 23, 2008 @04: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.

    • Re: (Score:2, Insightful)

      by Scottie-Z ( 30248 )

      Because, ideally, all four cores should be running at 100% -- the idea is to make maximal use of your available resources, right?

      • by DigitAl56K ( 805623 ) * on Wednesday July 23, 2008 @04: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, 2008 @04:18PM (#24311163) Journal
    Handbrake [handbrake.fr] has always used both of the cores on my system for transcoding.
    • Re:Handbrake (Score:5, Informative)

      by catmistake ( 814204 ) on Wednesday July 23, 2008 @04:57PM (#24311647) Journal

      that's because Handbrake uses ffmpeg

  • by Lumenary7204 ( 706407 ) on Wednesday July 23, 2008 @04: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.

    • Re: (Score:3, Informative)

      Note that the above example is about the video component only of a single MPEG audio/video stream.

      There is no reason that an encoder/decoder can't process audio in one thread and video in another, thereby using more than one core (which has already been discussed in other posts relating to this article).

    • keyframes (Score:5, Informative)

      by Anonymous Coward on Wednesday July 23, 2008 @04: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, 2008 @05: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.

      • How did you get a +5 Informative when you're wrong?

        First off, which MPEG spec has a K-frame? An I-frame is not a delta frame, it's more like your "keyframe." P and B are the delta frames.

        Secondly, there's very little to parallelize if you're working with open Groups of Pictures (GOP), that is to say every GOP references into the next GOP. If you have closed GOPs, then you can do this a little better by putting the next GOP on another core/CPU.

        But will you gain a significant speedup? The problem is not just

      • Re: (Score:3, Informative)

        by srw ( 38421 ) *

        Slight correction: in MPEG, the keyframes are called I-Frames. The delta frames are B and P frames. Most MPEG2 encoders that I have used default to a 15 frame GOP.

    • by Omega996 ( 106762 ) on Wednesday July 23, 2008 @04: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.
      • Re: (Score:2, Informative)

        by foxyshadis ( 1056614 )
        Several implementations of this exist: For x264, there's x264farm (which includes network encoding as well).
    • MPEG uses keyframes, right? So you'll still have a full frame in there every few frames. When I play back a MP4 I encoded, I wind up with something like a full frame every second or two (with the intermediate frames being the transformations you mentioned). So you can split at those frames. That's not infinitely parallel, but if we split it up by minute-sized segments, we'd have 90-150 segments (based on movie length), which is plenty for any prosumer computer for the foreseeable future, and even plenty
    • Re: (Score:2, Informative)

      by Zygfryd ( 856098 )

      http://en.wikipedia.org/wiki/Group_of_pictures [wikipedia.org]

      You can encode GOPs independently. I think the only dependency between GOP encoding processes is bit allocation, which probably works well enough if you simply assign each process an equal share of the total bit budget.

      • Re: (Score:3, Insightful)

        by init100 ( 915886 )

        I think the only dependency between GOP encoding processes is bit allocation, which probably works well enough if you simply assign each process an equal share of the total bit budget.

        Is this even needed if you use multi-pass encoding? At least for XviD, IIRC the first pass is used to accumulate statistics used to allocate the proper bit budget to each frame. Then the individual processes should be able to use the statistics file from the first pass to get the bit allocation for their current GOP in the second pass.

      • Re: (Score:3, Insightful)

        by benwaggoner ( 513209 )

        You can encode GOPs independently. I think the only dependency between GOP encoding processes is bit allocation, which probably works well enough if you simply assign each process an equal share of the total bit budget.

        That's a pretty painful constraint for anything other than very flat constant bitrate encoding. You really want to be able to move bits between GOPs to optimize for consistant quality.

    • by John Betonschaar ( 178617 ) on Wednesday July 23, 2008 @04:41PM (#24311419)

      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...

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

      Not quite true. Someone above already explained some of this re VisualHub.

      The video data/frame at 0:00 is very likely completely unrelated to the data/frame at 5:00, thus you can simply chop up the raw file into a number of segments and process them in parallel.

      Some clever stitching is probably required to put the whole thing back together in the end.

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

      Exactly, so you chop up the raw input into segments and they become discrete data sets.

    • by Fry-kun ( 619632 )

      But MPEG has keyframes - you need them for scene changes and error recovery. There's one at least every few seconds. For offline video, the threads can work on different keyframes & their respective deltas.

      For online video, it's harder.. but still can be done. Similar to how two-videocard setups work, you can split the image into pieces and have each CPU work on a particular piece, since there's little relation between . Of course it becomes very hard to scale beyond a certain point... but 2-4 cores/CPU

    • by adisakp ( 705706 )
      The problem with MPEG encoding and decoding is that the data itself is not well suited to multi-threaded analysis.

      You can also break down a frame into discrete rectalinear regions and have each separate region be performed by various threads. This block-based approach is a simple (although probably not 100% optimal) way to get parallelism with an operation involving only two buffers (current and output) in any 2D filter / transform from MPEG frame decoding to JPEG decompression to a Photoshop filter.

      Fo
  • Huh? I am using AGK and my CPU never does anything. It is always waiting for I/O. I must be doing something wrong...

  • Is there anything out there that can play a high-bitrate obese .mkv Blueray backup rip efficiently on 2 or 4 cores?
  • The mpeg algorithm is called DCT Cosine. If this is parallaizable, then mpeg encoding/decoding should be, although there is no way a general processor can beat an asic in silicon.

  • by tdelaney ( 458893 ) on Wednesday July 23, 2008 @04:44PM (#24311445)

    You don't say if you're running on Windows or Linux or something else. If you are running on Windows, the latest versions of VirtualDub have made big improvements to SMT/SMP encoding.

    VirtualDub home [virtualdub.org]
    VirtualDub 1.8.1 announcement [virtualdub.org]
    VirtualDub downloads [sourceforge.net]

    Make sure you grab 1.8.3 - 1.8.1 was pretty good, but had a few teething problems. 1.8.2 has a major regression which is fixed in 1.8.3. The comments in the 1.8.1 announcement contain a few important tips for using the new features (some of which I posted BTW).

    The two major new features that would be of interest to you are:

    1. You can run all VirtualDub processing in one thread, and the codec in another. This works very well in conjunction with a multi-threaded codec - this one change improved my CPU utilitisation from approx 75% to 95% on my dual-core machines - with an equivalent increase in encoding performance.

    2. VD now has simple support for distributed encoding. You can use a shared queue across either multiple instances of VD on a single machine, or across multiple machines (must use UNC paths for multiple machines). Each instance of VD will pick the next job in the queue when it finishes its current job. Instances can be started in slave mode (in which case they will automatically start processing the queue).

    I use 3 machines for encoding (all dual-core). With VD 1.8.x I start VD on two of the machines in slave mode, and one in master mode. I add jobs to the queue on the master instance, and the other two instances immediately pick up the new jobs and start encoding. When I've added all the jobs, I then start the master instance working on the job queue.

    To achieve a similar effect on your quad-code, start two instances of VD on the same machine - one slave, the other master.

    It's not perfect (if you've only got one job, you won't use your maximum capacity) but it has greatly simplified my transcoding tasks, and reduced the time to transcode large numbers of files.

    • by trawg ( 308495 )

      Holy shit! Somehow I missed all these VDub releases. Thanks for the notice.

      Out of interest, what sort of stuff are you encoding from/to? Are you aware of any mpeg4/h264 codecs that will work happily in Virtualdub?

  • avidemux (Score:5, Informative)

    by Unit3 ( 10444 ) on Wednesday July 23, 2008 @04: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.

  • Also consider this. (Score:2, Interesting)

    by SignOfZeta ( 907092 )
    If you do a lot of H.264 conversion, look into picking up a hardware encoder. There's the Turbo.264; it's Mac-only, but I'm fairly sure it's a rebranded PC device. Plug into a USB port, and it speeds up H.264 encoding -- even on single-core systems. Imagine that with your quad-core. It's not a free solution, but if you find yourself doing a *lot* of encodes, it may be worth your money.
  • by sjf ( 3790 ) on Wednesday July 23, 2008 @06: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.

  • heroinewarrior.com (Score:3, Informative)

    by heroine ( 1220 ) on Wednesday July 23, 2008 @07:09PM (#24312969) Homepage

    The version of Cinelerra from heroinewarrior.com uses SMP. It's highly dependant on the supporting libraries & who implemented the feature. In the worst case, use renderfarm mode & nodes for each processor. Sometimes the libraries work in SMP mode & sometimes they don't. Sometimes the feature was intended for everyone to use on any number of processors & sometimes it was written for 1 person's cheap single processor.

  • Now I'm a bit curious.

    Given that all of the "usual suspects" of encoding apps support SMP on almost every platform, and have done so for quite some time, what was this guy using that didn't support it?

    ffmpeg and x264 are just about the only players in town these days.

Understanding is always the understanding of a smaller problem in relation to a bigger problem. -- P.D. Ouspensky

Working...