Search code examples
windows-phone-7windows-phone-7.1video-encoding

How to convert images to video in Windows Phone 7


I am developing an IP Camera application in Windows Phone 7. My requirements are to record the video and save it to the local path. I can already access the images through the IP Camera API, and now I want to convert the images to video. How should I do that?


Solution

  • I'm not sure sample code for this exact task exists. You may start by looking at the System.Windows.Media docs, in particularly VideoRecorder, CaptureSource and FileSink. The How to: Record Video in a Camera Application for Windows Phone article and Video Recorder Sample may also be useful. I understand that you are not trying to encode video from the camera, but these examples show how to access the available encoders on the phone, you just need to figure out how to give them your own video frames. One problem I can see is that CaptureSource, FileSink and VideoCaptureDevice are all sealed classes. Normally FileSink calls CaptureSource.CaptureImageAsync and gets the next frame as a WriteableBitmap as a property in the CaptureSource.CaptureImageCompleted event handler. This is where you would want to provide the frames you have, but how? You cannot inherit from CaptureSource... if you could you would simply set that as the source to the file sink and provide your own frames. So at a glance it is not clear whether you can even encode your own video using the built-in codecs on Windows Phone.

    Another approach if you can use open-source codecs is to compile ffmpeg (or gstreamer, or xuggler, or x264, ...). You might check out ffmpeg4pocketpc, I don't know much about it but looks promising. Or, pick up a commercial codec library such as CoreCodec.