Jump to content
TheUberOverLord

A How To: Diagnose, Record, Play & Capture Image Via Stream

Recommended Posts

FFmpeg is a very well known and free media multimedia framework and player that has great logging abilities and is easy to use.

 

I have put together some free Windows .bat file scripts that use FFmpeg and FFplay which are also free ("Both of which are included in each .zip file") for Foscam, Hikvision and Top-201 ("Very bare bones and cheap +- $18.00 U.S. including shipping") IP Cameras.

 

The goals in creating these FFmpeg and FFplay Window scripts were the following:

 

a. Quick setup.

b. Make sure all media players can also use any recording files produced, not requiring exclusively FFplay for playback.

c. Allow copying the script folder on a per IP Camera basis for quick use/access at anytime for multiple IP Camera support.

d. Provide real-time detailed logging and save log output as well. So that any issues with a IP Camera can be seen and/or reviewed easily.

e. Limit file clutter and re-use log and recording files vs. creating new files every time the same script is used.

f. Include all files required so that nothing else is needed and no formal Windows installation is required.

g. Grab snapshots from main or sub video stream to show how easily that can be done when needed.

h. Make the scripts parameter driven using a global script so that multiple scripts don't require editing to allow easy copying of the folder for other IP Cameras. Only requiring the global parameter file to be modified for those other IP Cameras.

 

I will add more IP Camera brands in the future, but these are the current brands supported by these free scripts and their download links:

 

Once the global parameter script file is modified for a IP Camera. The scripts for the IP Camera brands below. All support using a double left click to instantly:

 

1. Record video only or audio only and video with audio for main and sub video stream.

2. Record all video or audio only, video with audio streams for your configured amount of seconds. Then automatically stop.

3. Playback of all recording files saved using FFplay. You can also use the media player(s) of your choice as well.

4. Real-Time playing of your IP Cameras audio only, video only and video with audio for main and sub streams. Using FFplay.

5. Grabbing a single snapshot from main and sub video streams.

6. View the detailed log which was saved while also being displayed in real-time, for each script run.

 

Download Link For All Foscam IP Camera Models

 

http://107.170.59.150/FFmpegTools/ffmpegForFoscamCameras.zip

 

Download Link For All Hikvision IP Camera, NVR/DVR Models and iVMS

 

http://107.170.59.150/FFmpegTools/ffmpegForHikvisionCamerasAndNvrsDvrsV11.zip

 

Download Link For All TOP-201 IP Camera and NVR/DVR Models

 

http://107.170.59.150/FFmpegTools/ffmpegForTop-201CamerasAndNvrsDvrsV11.zip

 

Caveats:

 

You may need to allow firewall access to both FFmpeg and FFplay to access your IP Cameras, NVR/DVR or iVMS from your Windows system. Depending on any firewall(s) you use on that Windows system.

 

You may need to right click on each .bat file ("After initial download and unzipping, once") and choose security and click an allow button. It depends on your version of Windows and its security settings.

 

Log file lines can sometimes be truncated when using Windows Notepad to view the detailed logs. Other text viewers like Windows Wordpad and others display the detailed logs properly.

 

I would create a Operator/User level Id that is not an admin level User Id for these scripts if you intend to use them on a non-secure LAN or remotely via WAN. Because the scripts run in the clear. While making sure that User Id is allowed to have access to the NVR/DVR, iVMS or IP Cameras, audio and/or video stream(s).

 

If a IP Camera, DVR/NVR or iVMS is not configured to access video sub streams then the video sub stream related scripts will fail because of that.

 

If a IP Camera does not support audio. Then the audio only stream related scripts will fail because of that.

 

All RTSP recording and real-time playing using RTSP streams by the scripts. Force TCP to be used vs. defaulting to trying UDP first. To minimize delay. Of course this does not apply to Foscam MJPEG based IP Cameras which are also supported by these scripts and use MJPEG streams as are Foscam H.264 based IP Cameras which do use RTSP streams.

 

The default recording time is set to 60 seconds. You can set that lower or higher. You can set the recording time to a very small amount of seconds, such as 10 seconds. If you are trying to get a true and accurate measurement of how many bytes per second of real-time bandwidth and/or a recording file will need on a stream by stream basis. For a specific IP Camera. With video or audio only or with video and audio. For both main and video sub streams with and without audio and audio only.

 

This also allows you to view real-time bandwidth usage for a specific IP Camera. By viewing recording bandwidth differences with audio only, video only and video and audio. Because the log detail is also displayed in real-time during all recordings as well as saved to a log file which is re-used anytime that specific script is re-run as well as the recording file created by any specific script is also re-used.

 

As you change IP Camera resolution, FPS rates, Bit rates, numbers of key frames and other IP Camera settings. You can see instant cause and effects for both MJPEG or RTSP based real-time bandwidth utilization as well as changes in MJPEG or RTSP recording file sizes of fewer or more bytes required for the same recording time. You can also see any data packet issues like re-transmissions, slow response times and other issues when using these scripts as well.

 

The scripts also support saving video only and video with audio recordings as .avi or .asf formats. So you can see the differences in recording file sizes between the two formats as well. All audio recording only recording files are saved in .wav formats.

 

Don

Edited by Guest

Share this post


Link to post
Share on other sites

Example 10 second FFmpeg recording of RTSP Main video stream:

 

http://107.170.59.150/FFmpegTools/h264_MainStreamAudioVideo.avi

 

Example of FFmpeg snapshot grabbed from RTSP Main video stream:

 

http://107.170.59.150/FFmpegTools/MainSnapShot.jpg

 

Example 10 second FFmpeg recording of RTSP Sub video stream:

 

http://107.170.59.150/FFmpegTools/h264_SubStreamAudioVideo.avi

 

Example of FFmpeg snapshot grabbed from RTSP Sub video stream:

 

http://107.170.59.150/FFmpegTools/SubSnapShot.jpg

 

Example 10 second FFmpeg recording of MJPEG video stream:

 

http://107.170.59.150/FFmpegTools/MJPEG_VideoOnly.avi

 

Example of FFmpeg snapshot grabbed from MJPEG video stream:

 

http://107.170.59.150/FFmpegTools/MJPEGSnapShot.jpg

 

Example FFmpeg Detail Log Output:

 

ffmpeg started on 2015-12-01 at 23:11:59
Report written to "H264RecordMainStreamAudioVideoAvi.log"
Command line:
"..\\ffmpeg.exe" -rtsp_transport tcp -i rtsp://User:Password@IPorDDNS:RTSPport/PSIA/Streaming/Channels/ChannelNumber/ -acodec copy -vcodec copy -force_key_frames "expr:gte(t,n_forced*5)" -t 10 -report -y h264_MainStreamAudioVideo.avi
ffmpeg version N-76860-g72eaf72 Copyright (c) 2000-2015 the FFmpeg developers
 built with gcc 5.2.0 (GCC)
 configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
 libavutil      55.  9.100 / 55.  9.100
 libavcodec     57. 16.100 / 57. 16.100
 libavformat    57. 19.100 / 57. 19.100
 libavdevice    57.  0.100 / 57.  0.100
 libavfilter     6. 15.100 /  6. 15.100
 libswscale      4.  0.100 /  4.  0.100
 libswresample   2.  0.101 /  2.  0.101
 libpostproc    54.  0.100 / 54.  0.100
Splitting the commandline.
Reading option '-rtsp_transport' ... matched as AVOption 'rtsp_transport' with argument 'tcp'.
Reading option '-i' ... matched as input file with argument 'rtsp://User:Password@IPorDDNS:RTSPport/PSIA/Streaming/Channels/ChannelNumber/'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'copy'.
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'copy'.
Reading option '-force_key_frames' ... matched as option 'force_key_frames' (force key frames at specified timestamps) with argument 'expr:gte(t,n_forced*5)'.
Reading option '-t' ... matched as option 't' (record or transcode "duration" seconds of audio/video) with argument '10'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option 'h264_MainStreamAudioVideo.avi' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Applying option y (overwrite output files) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input file rtsp://User:Password@IPorDDNS:RTSPport/PSIA/Streaming/Channels/ChannelNumber/.
Successfully parsed a group of options.
Opening an input file: rtsp://User:Password@IPorDDNS:RTSPport/PSIA/Streaming/Channels/ChannelNumber/.
[rtsp @ 0116ab80] SDP:
v=0 o=- 1109162014219182 0 IN IP4 0.0.0.0 s=HIK Media Server V3.3.4 i=HIK Media Server Session Description : standard e=NONE c=IN IP4 0.0.0.0 t=0 0 a=control:* b=AS:3082 a=range:npt=now- m=video 0 RTP/AVP 96 i=Video Media a=rtpmap:96 H264/90000 a=fmtp:96 profile-level-id=4D0014;packetization-mode=0;sprop-parameter-sets=Z2QAKKwXKgHgCJ+WEAABX5AAFfkIQA==,aP44sA== a=control:trackID=video b=AS:3072 a=Media_header:MEDIAINFO=494D4B48010100000400000100000000000000000000000000000000000000000000000000000000; a=appversion:1.0 
[rtsp @ 0116ab80] video codec set to: h264
[rtsp @ 0116ab80] RTP Profile IDC: 4d Profile IOP: 0 Level: 14
[rtsp @ 0116ab80] RTP Packetization Mode: 0
[rtsp @ 0116ab80] Extradata set to 0116d220 (size: 34)
[NULL @ 0116cd80] setting jitter buffer size to 0
[rtsp @ 0116ab80] hello state=0
[h264 @ 0116cd80] Frame num gap 21 19
[rtsp @ 0116ab80] All info found
[rtsp @ 0116ab80] rfps: 7.833333 0.019018
[rtsp @ 0116ab80] rfps: 7.916667 0.009901
[rtsp @ 0116ab80] rfps: 8.000000 0.008035
[rtsp @ 0116ab80] rfps: 8.000000 0.008035
[rtsp @ 0116ab80] rfps: 8.083333 0.013419
[rtsp @ 0116ab80] rfps: 21.916667 0.013522
[rtsp @ 0116ab80] rfps: 22.000000 0.008116
[rtsp @ 0116ab80] rfps: 22.000000 0.008116
[rtsp @ 0116ab80] rfps: 22.083333 0.009962
[rtsp @ 0116ab80] rfps: 22.166667 0.019057
[rtsp @ 0116ab80] rfps: 29.833333 0.014604
[rtsp @ 0116ab80] rfps: 29.916667 0.003707
[rtsp @ 0116ab80] rfps: 29.916667 0.003707
[rtsp @ 0116ab80] rfps: 30.000000 0.000061
[rtsp @ 0116ab80] rfps: 60.000000 0.000244
[rtsp @ 0116ab80] rfps: 120.000000 0.000976
[rtsp @ 0116ab80] rfps: 240.000000 0.003904
[rtsp @ 0116ab80] rfps: 29.970030 0.000537
[rtsp @ 0116ab80] rfps: 29.970030 0.000537
[rtsp @ 0116ab80] rfps: 59.940060 0.002150
[rtsp @ 0116ab80] rfps: 59.940060 0.002150
Input #0, rtsp, from 'rtsp://User:Password@IPorDDNS:RTSPport/PSIA/Streaming/Channels/ChannelNumber/':
 Metadata:
   title           : HIK Media Server V3.3.4
   comment         : HIK Media Server Session Description : standard
 Duration: N/A, start: 0.842000, bitrate: N/A
   Stream #0:0, 29, 1/90000: Video: h264 (High), yuv420p, 1920x1080, 8 fps, 30 tbr, 90k tbn, 16 tbc
Successfully opened the file.
Parsing a group of options: output file h264_MainStreamAudioVideo.avi.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument copy.
Applying option vcodec (force video codec ('copy' to copy stream)) with argument copy.
Applying option force_key_frames (force key frames at specified timestamps) with argument expr:gte(t,n_forced*5).
Applying option t (record or transcode "duration" seconds of audio/video) with argument 10.
Successfully parsed a group of options.
Opening an output file: h264_MainStreamAudioVideo.avi.
Successfully opened the file.
Output #0, avi, to 'h264_MainStreamAudioVideo.avi':
 Metadata:
   INAM            : HIK Media Server V3.3.4
   ICMT            : HIK Media Server Session Description : standard
   ISFT            : Lavf57.19.100
   Stream #0:0, 0, 1/16: Video: h264 (H264 / 0x34363248), yuv420p, 1920x1080, q=2-31, 8 fps, 30 tbr, 16 tbn, 16 tbc
Stream mapping:
 Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=   34 fps=0.0 q=-1.0 size=     143kB time=00:00:03.43 bitrate= 341.2kbits/s    
frame=   39 fps= 33 q=-1.0 size=     154kB time=00:00:04.06 bitrate= 310.5kbits/s    
frame=   43 fps= 25 q=-1.0 size=     162kB time=00:00:04.56 bitrate= 290.6kbits/s    
frame=   47 fps= 21 q=-1.0 size=     170kB time=00:00:05.06 bitrate= 274.7kbits/s    
frame=   51 fps= 19 q=-1.0 size=     230kB time=00:00:05.56 bitrate= 338.4kbits/s    
frame=   55 fps= 17 q=-1.0 size=     239kB time=00:00:06.06 bitrate= 322.6kbits/s    
frame=   60 fps= 16 q=-1.0 size=     247kB time=00:00:06.68 bitrate= 302.7kbits/s    
frame=   64 fps= 15 q=-1.0 size=     253kB time=00:00:07.18 bitrate= 288.5kbits/s    
frame=   68 fps= 14 q=-1.0 size=     260kB time=00:00:07.68 bitrate= 277.3kbits/s    
frame=   73 fps= 13 q=-1.0 size=     269kB time=00:00:08.31 bitrate= 265.1kbits/s    
frame=   77 fps= 13 q=-1.0 size=     275kB time=00:00:08.81 bitrate= 255.7kbits/s    
frame=   82 fps= 13 q=-1.0 size=     284kB time=00:00:09.43 bitrate= 246.3kbits/s    
frame=   87 fps= 12 q=-1.0 size=     295kB time=00:00:10.06 bitrate= 239.8kbits/s    
No more output streams to write to, finishing.
frame=   87 fps= 12 q=-1.0 Lsize=     297kB time=00:00:10.06 bitrate= 242.0kbits/s    
video:288kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 3.391166%
Input file #0 (rtsp://User:Password@IPorDDNS:RTSPport/PSIA/Streaming/Channels/ChannelNumber/):
 Input stream #0:0 (video): 89 packets read (298284 bytes); 
 Total: 89 packets (298284 bytes) demuxed
Output file #0 (h264_MainStreamAudioVideo.avi):
 Output stream #0:0 (video): 87 packets muxed (294412 bytes); 
 Total: 87 packets (294412 bytes) muxed
0 frames successfully decoded, 0 decoding errors
[AVIOContext @ 06011320] Statistics: 10 seeks, 98 writeouts

Don

Edited by Guest

Share this post


Link to post
Share on other sites

Do not start again... TheUberOverLord, I think Boogieman was just being sarcastic. At least I did get a laugh this time.

 

"How to"s are always good " title="Applause" />

Share this post


Link to post
Share on other sites

Another point to be aware of is that you can copy the folders that contain the scripts and edit their Global script so that you can even have different folders for the same IP Camera.

 

As an example. You may want a folder that is setup to run FFmpeg using that IP cameras LAN IP Address, another using that same IP Camera via your ISP IP Address and another using that same IP Camera using a DDNS. So that you can compare FPS rates, dropped packets or bandwidth issues using all the access methods for your IP Cameras.

 

Of course you can also copy the same folder for the same IP Camera brands and use the copies of each folder for multiple IP Cameras of the same brand. For each of those different IP Cameras, as needed as well.

 

I the event that your brand of IP Camera model is not a Hikvision, Foscam or Top-201 IP Camera model you can edit the scripts and use the URL for your MJPEG or RTSP video/audio streams.

 

I suggest using the Foscam Script download link from the link below. Because they contain folders which support both MJPEG and RTSP video and audio streams:

 

viewtopic.php?p=281549#p281549

 

To see the command line options for FFmpeg. Please see the link below:

 

https://ffmpeg.org/ffmpeg-all.html

 

If you need any help with your brand of IP Camera model. Please post here and I will help you get the scripts working for your IP Camera.

 

Don

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×