Beta testers wanted. Extract and archive jpeg images from hikvision .pic files.

Wilbur

n3wb
Joined
Mar 4, 2019
Messages
14
Reaction score
3
Location
UK
Hi,

I am looking for beta testers for a Perl program (jpegs_from_hic_pic.pl). It extracts images from a hikvision IP camera stored on a NAS. It allows selection of images created in the last n days, hours or minutes. The primary purpose is to create an archive where the file structure is myoutputdir/YYYYMM/DD/HHMMSS.jpg. It was written for a Linux system (/ rather than \ separating directory names but easily changeable if required, Perl might even do it for you, let me know). I mount my input directory on my NAS using Samba or SSHFS. Either seems to work well for me. Anyway a little bit of IT knowledge might be required for you to set it up. I only have one camera to test this with a DS-2CD2345FWD-I.

The program use a simple text parameter file like the one attached and it is run by

perl jpegs_from_hic_pic.pl hic_pic_parms.txt

My plan is to run this every few ours by CRON so I can easily locate image taken at a specific time rather than using a clunky Hikvision interface. Then I will reduce the size of the partition on my NAS to store the PIC files and put them in a regular file system that can be browsed by any PC or over DLNA.

Wilbur.
 

Attachments

SamM

Pulling my weight
Joined
Mar 29, 2020
Messages
245
Reaction score
110
Location
SA
Hi

What will be the purpose of this?
 

watchful_ip

Pulling my weight
Joined
Nov 24, 2019
Messages
251
Reaction score
226
Location
london
Actually this is quite useful depending on your setup.

I do something similar for my cameras archiving all pictures and videos to a centralized server I keep for a period of some months. They have SD cards in them with limited capacity, and don't need a NAS server to record to (which could fail/get stolen etc) - but the SD cards are exported over NFS and mounted on the central extraction server for automatic archival (actually in cron.hourly in my case).

FYI the new G3 cameras use a different storage scheme - sqlite3 dbs indexing the pic/video files. I assume future Hik cameras will go the same way. Actually makes it easier than parsing the binary indexes previously used.

Code:
 SELECT file_no,segment_id,stream_id,record_type,encoder_type,resolution,start_time_tv_sec,start_time_tv_usec,end_time_tv_sec,end_time_tv_usec,first_key_frame_abstime_tv_sec,first_key_frame_abstime_tv_usec,last_frame_stdtime,start_offset,end_offset,audio_samplerate,compatible_data,is_smart_h264,audio_bitrate,info_types,info_start_offset,info_end_offset,info_start_time,info_end_time,is_encrypt  from record_segment_idx_tb where file_no = %d and segment_id = %d;
Note that I used a c program to do this, because there is a file locking issue with php's sqlite3 wrapper, and possibly perl as well. In c you can do:

Code:
sprintf(index_file,"file:%s?immutable=1",INDEXFILE);
    int rc =  sqlite3_open_v2(index_file, &db, SQLITE_OPEN_READONLY | SQLITE_OPEN_URI,NULL );
which won't require locking on files already locked by a running camera. A bad idea if you are changing the dbs, but fine in a read only context for this purpose.
 
Last edited:

Wilbur

n3wb
Joined
Mar 4, 2019
Messages
14
Reaction score
3
Location
UK
It is good to see Hikvision making it easier for users to do their own thing. I will stick with my old camera for now but if I get another I'll certain make use of the information provided so thank you. When you say your new camera exports over NFS are you saying the camera is recording to an NFS share or the camera is allowing access to the SD card via NFS while still in use? If the first do yo have to use the Admin interface to get it to export the SD card recordings or is it automated?

Now I just have to look at my DVR indexes (DS-7200HQHI-K1) to see if I can reverse engineer those. It is recording from 6 old analog cameras and the one ip camera capturing jpegs. The DVR records to an internal drive and to a small share on my NAS. I then copy the NAS recording to a larger share and rename them at the same time. My only real issue is identifying which recording came from which camera.

I notice the Perl code for extracting the jpegs with file type .pl was not attached to the post. If anyone wants it I'll attach it with .txt.

Regards.
 

watchful_ip

Pulling my weight
Joined
Nov 24, 2019
Messages
251
Reaction score
226
Location
london
When you say your new camera exports over NFS are you saying the camera is recording to an NFS share or the camera is allowing access to the SD card via NFS while still in use? If the first do yo have to use the Admin interface to get it to export the SD card recordings or is it automated?
The second - my cameras export the SD card via NFS while still in use. They don't mount an NFS share on a server.*

*except one camera that doesn't have an SD card slot. That camera uses a different camera as it's NFS server and exports 2 shares from it's partitioned SD card.
 
Top