Ripping the individual camera streams from the Vista files
Many DVR companies do actually conform to standard video practices. When they do, it makes it so much easier to deal with the video for any purpose. One of the abilities in mpeg4 type video is to hold a number of streams together in one file. In the film world they could be different viewing angles or extra scenes. In the CCTV world, its a group of cameras. The below is a pretty common example, but you may find many different variations so always test and verify any stream mapping you conduct.
The video files are held within the Download folder but first we need to see what they look like within the player.
After going through the initial open / find file and selecting the Download folder, the above dialogue box appears in front of the player interface. From this I can see 4 files with a date and times to and from.
When I select the first one, the main interface kicks into life.
As the footage plays (not displayed in the image above) the number 12 appears next to the frame size. The frame size is shown as 360×288. The player does give a user the option to extract a still image but nothing for video export. I always look at the programs properties as well to see if any links are shown there but as is usual, there is nothing in the way of help. I see four camera views but have no idea on whether there are more cameras in use but not exported. I have no idea if Video Motion Detection is in use and another camera could kick in at any minute. It’s a bit of a mystery so we need to look further inside the Download folder.
This reveals 4, reasonably large , un-extended files and 4 smaller .idx files. The. idx extension is regularly used for video indexes showing the time clock but they are all written differently and putting these into an understandable text for later use and analysis is, quite often, impossible. There are one or two that use standard subtitle formats that make things much easier for presentation work.
The four bigger files, I assume, are therefore the video. Now, we had four clips shown in the initial dialogue box when opening the program. When we viewed the video we had four camera angles. We need to establish if these files are the cameras or the time clips.
By dragging the first un-extended file into MediaInfo, we have our answer.
This tells me that its an MP4 Video file containing 4 streams at a duration of 13mn 32s. This is the duration reported by the player in the clip window. So, the files are the time clips and each one contains 4 streams of video – the cameras.
Important: There are some files that when dragged into a media player such as SMplayer, it will detect the first mp4 stream and play it. It only plays stream0 and not the others. It is very easy to miss other cameras included in the file.
I verified the MediaInfo findings and took a closer look at the streams by parsing the file through FFprobe:
The results for Stream0:
codec_long_name=MPEG-4 part 2
Before we get into separating and dealing with the camera angles, it’s worth noting that the video, when played within the player presents an overlay stating 360 x 288. However, all the reports and analysis state a pixel width and height of 352 x 288!
Time to start creating our new files, and there are a few options. Depending on the use of the video may dictate what path is chosen. That decision would be down to you. Whatever method, we need to use the mapping parameter within FFmpeg.
ffmpeg -i videofile -map 0:0 -vcodec copy -f avi -fflags genpts stream0.avi
The -map parameter tells the program to only parse stream 0. After completing the first one I just press the up arrow on the keyboard which puts the last command back within my window. I change the stream number and output file number and then hit enter again.
ffmpeg -i videofile -map 0:1 -vcodec copy -f avi -fflags genpts stream1.avi
ffmpeg -i videofile -map 0:2 -vcodec copy -f avi -fflags genpts stream2.avi
ffmpeg -i videofile -map 0:3 -vcodec copy -f avi -fflags genpts stream3.avi
It’s really fast and within 30 seconds I have four video files.
All videos have the same encoding and timing. If your NLE can accept mp4 wrapped avi files then these should drop in nicely. They also scrub very quickly within programs like Virtualdub.
It may be necessary to do a little bit more analysis with these files.
Avinaptic (and other programs) reveal:
81227 Total Frames
71477 Null Frames
9750 Individual frames
650 are I frames
9100 are P Frames
If we wanted to create frame only streams, thereby having no duplicate files, it would be necessary to transcode out of the mp4 encoding. Before doing this though we need to know the GOP structure.
GSpot verifies my frame count and displays the GOP. A 15 Frame GOP. I verified this with FFprobe again using the same process as detailed here. The results confirmed what Gspot had reported.
By using FFmpeg again on the exported stream we can output a video with no duplicate frames. By identifying their frame numbers we know if they were an I frame or a P frame.
ffmpeg -i stream0.avi -vcodec rawvideo -vsync drop stream0-UC.avi
There are a number of other options open to us.
If we added in -r 12 to the command above we could have the avi play at the correct frame rate (remember the 12 displayed in the window of the original player). So the command would be
ffmpeg -i stream0.avi -vcodec rawvideo -vsync drop -r 12 stream0-UC12.avi
If we wanted to go straight to this from the original video file and not bother extracting the streams in their original format…..
ffmpeg -i inputstream -map 0:0 -vcodec rawvideo -vsync drop -r 12 stream0-UC12.avi
The only problem in doing this is proving the GOP structure.
Mp4 is now pretty easy to deal with….h264 is becoming easier…..and now they have gone and brought out h265! Perhaps DVR manufacturers will start to give us an idea on what they do to the video by the time h265 starts to spread, then again perhaps pigs might fly!