views:

304

answers:

2

Hey,

Does anyone know a good way to do real-time video re-encoding (Target formats being 3GP s263 AMR narrowband and MP4 mp4v mp4a, but not at the same time of course. Input files would be WMV, but the more input formats supported the better)?

Currently we do asynchronous processing using a C# service that calls the ffmpeg command-line, but the idea of doing that for a synchronous request is a little sub-optimal cause the user ends up waiting quite a while before the playback starts (Though if that's the best-case scenario let me know and I guess I'll live with it).

It would be awesome if we could simultaneously serve the file and save it (So that we can store it for future requests), but it wouldn't be a disaster if we can't do that.

As a sidenote I'd prefer to avoid a streaming solution since less devices will support it, but if there's no good way to do what I want I would love to hear alternatives even if they involve streaming.

Update

Just to keep you guys up-to-date with where I've gotten to I'm currently playing around with the idea of writing a wrapper that calls directly to FFmpeg's DLL's rather than the exe, starting to think I might be able to get the functionality I'm after that way (Catching the data progressively rather than once it's all done may get me close enough to real-time to suffice).

Still playing around with whether this will work and trying to find good samples of how to do it (even those written in c rather than c# cause it'll show how to interface with the DLL).

+1  A: 

As for a streaming solution, we used StreamCoders' MediaSuite.net. It worked OK for us for streaming any MPG based video to 3GP/H263. However, you should know exactly what you are doing in terms of specs, formats, encodings etc. It's a huge field and their product doesn't "explain" some of the basic terms, they assume you already know what you're doing. In addition, as far as I can remember, you have to manually synchronize the audio and video channels. Their demo app shows how to do it (but then again, it's just a demo app, so you might end up with your optimization).

I think you can use it for re-encoding as well as streaming, I didn't try it myself lately. How do you plan to output the result? As a System.IO.MemoryStream?

Another streaming solution is to have a well known streaming server such as Xenon, and use it doing a "back-to-back" technique: your handler gets a request and creates a request to the streaming server. The streaming server's response is streamed to the client. It's kind of a hack, but it worked great for us for a while.

Your ffmpeg solution is fine, and you may find it simpler to implement rather than the lower-level almost-real-time convertion. If you can "tolerate" this, maybe it's better to leave it as it is.

Update: If you end up wrapping ffmpeg with a .Net library, which seems like a great solution, since ffmpeg is a great library, it'd be great if you could share your solution. We tried playing with it but we didn't enough time.

Ron Klein
Those pack some pretty hefty price-tags on those third party tools. Definitely look useful but might be a bit beyond what we were hoping to spend. As far as output goes Ideal-word I was hoping to get some kind of solution I could pass a System.IO.Stream object to (probably a custom one that sends it both to a file and the response stream), I suspect I'd have to wrap any solution in some code to handle it in .NET objects to make it that friendly to use but that's basically the point I wanted to expose from the library I write to the main app.
Tim Schneider
I'm accepting this answer cause it's the best and the bounty is almost out. I'll put a note on this question later if I write an FFmpeg wrapper (The exact amount of the work I can give out will depend on whether I do it for the company I work for or in my own time - if I do it on their time I can't really open-source it but I can provide a few hints to someone else who may try).
Tim Schneider
+1  A: 

I have been playing with real-time encoding for presentations and user-group meetings. The best solution I found was the Microsoft Expression Encoder. The included SDK is fairly straightforward to use and should provide most of the functionality you need.

John Nunn
I just had a skim but unless I'm mistaken it doesn't support any of the output formats I need?
Tim Schneider