Sign up ×
Video Production Stack Exchange is a question and answer site for engineers, producers, editors, and enthusiasts spanning the fields of video, and media creation. It's 100% free, no registration required.

I have developed a desktop application that records motion from any video source - ie ip Camera, web cam (etc).

These motion 'clips' timestamps are uploaded to my server.

The Web user can log in and view these 'Time-clips'.

If they want to view any of these clips they double-click on it a request is made to a clients PC (in this scenario a very old laptop) and the images which are in jpeg format are encoded to ogg video format using ffmpeg.

Everything works well and fast.

Now, the client has complained/wants constant streaming of all the video captured from the client.

My second immediate thoughts was to have a base image on my server (or 2 - for caching)) and update the differences between 2 frames and upload and overlay the pixel changes on the base image on my server.

Now, as I have been informed before this actual process is how a video encoder works?

If that is the case I could save a lot of time using an encoder to change the base image on my server.

ffmpeg naturally comes to mind.

1). Does this sound reasonable to try to achieve? 2). Are they any pointers to what arguments I could use with ffmpeg to achieve all this?

I am very new to this fascinating subject and I am keen to learn and understand rather than copy & paste (sounds like a job interview!).

I am using C# as a programming tool but consider this is irrelevant to the initial question?

I very much welcome people's thoughts.


share|improve this question
Old question, but as soon as you started talking about detecting pixel differences yourself, I just had to say: It's not worth it to invent your own video codec. Use h.264 or something. Huge amounts of time have been put into optimizing the hell out of x264, for example. And use ffmpeg's mpdecimate to drop similar frames before sending them to a video codec. – Peter Cordes Feb 26 at 3:12
@PeterCordes I appreciate your comments. I have to admit when I originally posted this question I was VERY naive. Now I am just naive :) Thanks – Andrew Simpson Feb 26 at 7:42

3 Answers 3

The way I've seen this done in other systems intended for CCTV is to encode every couple of frames compressed with something like MJPEG and then stream that to the client, the server component of ffmpeg, ffserver may be able to help you with that. Of course, depending on your needs a different video codec may be more appropriate, particularly if you intend to send every frame in which case something like H.264 may be more efficient.

share|improve this answer
Hi, that has given me something to think about -thanks – Andrew Simpson Nov 19 '13 at 12:50
A fixed camera is always going to have a LOT of temporal redundancy between frames, so you'll save a lot of bits with any codec that can use P and B frames (inter prediction). – Peter Cordes Feb 26 at 3:28

So you have a client computer with a camera, and want to stream video from it to a server where it's archived and accessible?

client runs: ffmpeg -i some_kind_of_input -vf mpdecimate -c:v libx264 -preset medium -crf 25 some_kind_of_output

Choose an appropriate framerate to capture. mpdecimate will run constantly at that framerate. libx264 with your chosen preset will have to keep up with realtime to avoid dropped frames when there is motion going on, so mpdecimate isn't dropping any duplicate frames.

The output from that should be buffered somehow so upload to the server can lag behind the bitrate of the output when there is a burst of data (because of motion).

Your output will be VFR video. There will be continuous 10fps or w/e bits, and other bits with 1 frame per hour or something. x264 doesn't care, and most container formats have no trouble storing timestamps for each frame. (e.g. mkv or mp4 are probably both ok choices.)

The server receives this video stream, and breaks it into 1 minute or 1 hour chunks or something. (or maybe it's easier to break into chunks on the client side, and upload a chunk after it's done being written. That would stop you from getting a realtime feed from your cam though.)

Or server just decodes it and stores jpg images with timestamps for filenames. I'm not sure what kind of support ffmpeg has for VFR output to the image2 muxer (that's the "directory of image files" with %04d.jpg filenames, or w/e. AFAIK, the %04d can only substitute frame numbers, not timestamps.)

Anyway, I just made all this up. I'm sure you'll find lots of stuff if you google on motion detection security video.

IDK why this was on the recent-activity questions list, but since I read it, I figured I'd post an answer.

share|improve this answer
I too do not know why this has appeared on the recent-activity list but I am glad it did! If I can work out how this happened I will attempt to regurgitate all my past questions :) Also, your answer was A1! – Andrew Simpson Feb 26 at 7:58
Hi, When i run this command via my C# app I just a get byte values of 255? What have I missed? – Andrew Simpson Feb 26 at 9:48
you need ffmpeg installed, and some_kind_of_input is just a placeholder. Same for output. If you want to use it from within a C# app, you might want to use the libav* API, instead of piping data through ffmpeg running as an external process. I haven't used the api myself, but ffmpeg (the cmdline program) is just a front-end for libavformat, libavfilter, libavcodec, etc. Have a look at, and google on using ffmpeg libraries. (also note that there's a fork of ffmpeg called libav, so you'll get google hits on that.) – Peter Cordes Feb 26 at 21:50
sorry, didn't take as long thinking about your reply as I should have. So you mean the output file is filled with 0xff bytes? Or the system() function call returns 255? I really don't have a very good idea of exactly what you might have done. You might want to ask a new question (with code and output) on (which would be the right place, since you're writing code.) You might get answers telling you to use the library API instead of trying to pipe your data through the cmdline frontend, though. If ffmpeg can read directly from the camera, that might be useful... – Peter Cordes Feb 27 at 0:35
Yes, deleted as I thought it was a reply to another of my questions lol. Using mobile to reply, sorry – Andrew Simpson Feb 27 at 0:37

If you are on Windows (presumably since you are using C#) is there a reason that you can't simply use Windows Media Encoder and Windows Streaming Media Services on the server? It sounds like it is designed to do exactly what you are trying to do. I'm not sure I understand why you need to build your own solution when many great (and even free or no additional cost) solutions exist already.

Update: Based on the understanding that you just need about 10fps jpeg's and that latency doesn't matter as much as guaranteeing delivery, I would probably do the following:

1) Client submits each image with an incrementing sequence number to the server.

2) The server takes each image and stores it in to the file system with the path and sequence number in a dictionary.

3) When the viewer connects it starts by asking for the current image and is given the image and sequence number.

4) Upon display of an image, the viewer then requests the next sequence number. Timing information for how far behind the viewer is could also be sent back to keep it from getting too far behind. The server would wait until an image is available for the sequence number if it doesn't yet have one. This would help keep in sync as well.

share|improve this answer
Hi, thanks for replying. I did take a look at Windows media Encoder but it is working with streams. I am using jpegs you see. – Andrew Simpson Nov 19 '13 at 14:31
@AndrewSimpson - ah, so video (even at low framerate) isn't an option? Would you like to jump in chat to discuss a bit more about what you need. I'm still not 100% sure I understand the scenario. – AJ Henderson Nov 19 '13 at 14:33
hi, I would love to. How do do that? – Andrew Simpson Nov 19 '13 at 14:34
@AndrewSimpson - updated my comment with a link on the word Chat, just click it. :) – AJ Henderson Nov 19 '13 at 14:34
ffmpeg has an input demuxer that can read a stream of image files piped in back-to-back. -f image2pipe. Or just decode the jpegs, and feed the image data to WME. – Peter Cordes Feb 26 at 3:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.