ffmpeg is a set of video processing tools used by ZoneMinder to generate video files from the frames captured and saved. It has always been under heavy development.
FFMPEG is used in two fashions in Zoneminder.
- 1) For exporting videos, an ffmpeg binary is used (vers. 1.30.4).
- 2) If you examine the source code, you will see zm_ffmpeg.cpp which uses libavcodec, which is library for the functions that the ffmpeg binary provides which you can wrap into a program (such as ZM). This is how ZM records when using only the ffmpeg method. Note that here it does not use the binary.
- 1 Obtaining FFMPEG
- 2 Using FFMPEG
- 3 FFMPEG Video Export Options
- 4 Examples
- 5 See Also
You should first check your distribution's package manager. Aside from that you have the option of compiling from source, or downloading a binary, which are linked from the main ffmpeg website.
Testing a Stream Path with FFMPEG
$ ffmpeg -i rtsp://admin:email@example.com:554/video/1 output.mp4
Note that output.mp4 is the output file, not the -i input stream. Don't miss the space. This can be done from the terminal, and does not require X. Useful for testing from servers. If successful it will output the encoding of the stream and the resolution. It will also record the stream to output.mp4.
A note on the RPI
The RPI has its own build of FFMPEG which includes support for the omx and mmal hardware peripherals. It is recommended to obtain it from the official RPI repos. Note that this provides hardware support for exporting, but not necessarily for recording videos (see above paragraphs).
FFMPEG Video Export Options
Ffmpeg is used in exporting events to downloadable video files. Exporting video is done using the zmvideo.pl script.
You can control the options that get passed to ffmpeg during the export process using 2 config options found in the Images tab of the options dialog.
usually leave this empty
Here are some possible settings:
To obtain a good quality export x264 based mp4 video file - the following example works...
-r 30 -vcodec libx264 -threads 2 -b 2000k -minrate 800k -maxrate 5000k
If you want as fast as possible h264(with some sacrifice in quality) you can try
-c:v libx264 -preset ultrafast
Use ffmpeg to concatenate all jpg images in an event export to MP4 (=<1.30.4)
ffmpeg -framerate 5 -i %05d-capture.jpg output.mp4
Note that %05d-capture.jpg here means, escape (%), search for numbers (0), search for 5 of them, increment numbers d, then the rest is a string common to all jpg files. Edit the framerate appropriately
Joining Video / Audio
Use ffmpeg to concatenate a number of audio / video files (not jpegs)(assumes same codec)
first put all desired files into a list
for f in ./*.mp4; do echo "file '$f'" >> mylist.txt; done
combine files using concat filter
ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4
Note that special characters and spaces can be troublesome.
Extract Portion of Video/Audio
Use the -ss option to specify the starting timestamp, and the -t option to specify the encoding duration, eg from 3 minutes and 5 seconds in for 45 seconds:
ffmpeg -i sample.avi -ss 00:03:05 -t 00:00:45.0 -q:a 0 -map a sample.mp3
The timestamps need to be in HH:MM:SS.xxx format or in seconds.
If you don't specify the -t option it will go to the end.
NOTE: This doesn't always work as you expect it. ffmpeg is always jumping around where the end is of the file, so don't be surprised if your extract starts earlier or later than you thought.
Debugging Media streams
This may be useful, if you are trying to determine why a camera is failing to connect properly to ffmpeg. (reference book: FFMPEG Basics)
ffmpeg -debug mmco -i rtsp://user:password@ipaddress:554/streampath output.mp4
Note that the -debug flag has a number of parameters other than mmco (which is only valid for h264) that can be passed. A few other possible values are buffers, pict, bitstream, rc
- Zmodopipe - Some examples of ffmpeg reading from a pipe, outputting to a JPEG file, and also ffserver.
- FFMPEG Basics by Frantisek Korbel. A book on the shell use of ffmpeg (does not cover c usage w/libraries).