Hikvision video batch convert

msmcknight

n3wb
Joined
Apr 27, 2020
Messages
22
Reaction score
10
Location
usa
Hi all,

As many know, when you save a block of video from a hikvision camera, dvr, ivms, etc., you might end up with multiple video files, and whether it's one file or 20, they will be in a semi-proprietary format. ie. mpeg-ps in an mp4 container. The hikvision format converter isn't the most friendly utility to use, and is really poorly written if you have a bunch of files to convert (ie you have to add them one at a time).

Anyway, below is a little script I wrote using ffmpeg that will convert videos from hikvision from cameras with or without audio streams. I'm not a programmer by any stretch, so I'm sure improvements could be made, but it's made converting an entire directory of hikvision mpeg-ps video files easy as running a single command.

I named the script "hikconvert" and put it in my path. I wrote it on unix, but I think the concepts will transfer to windows even if the scripting language itself doesn't. To use the script, I "cd" into the directory where my video files are stored and just type "hikconvert" and walk away. The script will create a new sub-directory called "fixed" and put the converted videos in there, preserving the originals.

Code:
#!/usr/bin/ksh
mkdir ./fixed
for i in  *.mp4
do
ffmpeg -err_detect ignore_err -i "$i" -c:v copy -c:a aac ./fixed/"$i-fixed.mp4"
done
I'm hoping someone else finds this useful.
 
Top