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.


  • 1
    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. Feb 26 '15 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 Feb 26 '15 at 7:42

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.

  • Hi, that has given me something to think about -thanks 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). Feb 26 '15 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.

  • 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! Feb 26 '15 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? Feb 26 '15 at 9:48
  • 1
    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 ffmpeg.org/documentation.html, 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.) Feb 26 '15 at 21:50
  • 1
    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 stackoverflow.com (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... Feb 27 '15 at 0:35
  • Yes, deleted as I thought it was a reply to another of my questions lol. Using mobile to reply, sorry Feb 27 '15 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.

  • 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. Nov 19 '13 at 14:31
  • 1
    @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? 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. Feb 26 '15 at 3:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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