Script to encode multiple videos into a single file and correct fisheye distortion

instant_record

New Member
Joined
Aug 25, 2016
Messages
36
Points
0
I've written a mega-script that that you can run in a BASH shell in Linux/Mac. It will take multiple recordings made using the 10 minute loop option from a Gitup camera and encode them into a single file. It chooses a sensible bitrate to encode them into using a "divider" value and the source recording resolution. You can also specify to remove the fisheye distortion caused by the camera's lens (I worked this out using OpenCV and a chessboard target).

Alternatively, it will combine all 10 minute clips into a single file with lossless encoding, but in this case you can't correct the fisheye distortion.

Download the script, rename the extension to ".sh" and run "chmod +x" on it to make it executable. The usage of the script is you run it in a directory containing *.MP4 files and it will find the ones created by the Git2 camera based on their file name, and process them into clips. You can have multiple recording sessions in the current directory and it will detect which files make up which recording session based on their length.

I see lots of people talking about white balance/chroma correction, so if someone gives me an ffmpeg filter to correct this, I will incorporate this into the script.

DISCLAIMER: I ACCEPT NO RESPONSIBILITY IF THIS DESTROYS YOUR HARD DRIVE AND ALL YOUR FILES!!!!
(But in all my testing I've never had this happen.)

Enjoy!
 
Last edited by a moderator:

instant_record

New Member
Joined
Aug 25, 2016
Messages
36
Points
0
Forgot to add, if you want to change any parameters or enable fisheye correction, you need to open up the file in a text editor and change the values. It is well commented so should be easy to do.
 

javiersegurar

New Member
Joined
Oct 14, 2016
Messages
6
Points
0
Hello instant_record!

First, Thank you very much for share your script!...

Ok, I use linux and have a very limited script capability, however, I download your script and open it in order to try to learn about the section that make the fisheye correction, since I would like to use for a small script that make only the fisheye correction over a single file, but your work is really of a high kind! :) ...so, in my limited skill I could no identify properly which is the command that you use for the fisheye correction (I try to following the track of the values but with the sed used in your script I was lost in figure out the fisheye correction)

If may share some info about I would apreciate it.

Thanks again for share! Best regards.


I've written a mega-script that that you can run in a BASH shell in Linux/Mac. It will take multiple recordings made using the 10 minute loop option from a Gitup camera and encode them into a single file. It chooses a sensible bitrate to encode them into using a "divider" value and the source recording resolution. You can also specify to remove the fisheye distortion caused by the camera's lens (I worked this out using OpenCV and a chessboard target).
 

instant_record

New Member
Joined
Aug 25, 2016
Messages
36
Points
0
No problem. I'm so glad someone else has a use for it - I thought I was the only one who needed such a script!

If you want to see what the script is running, replace the command "eval" with "echo" and it will print the encoding command it is using. For a single file and NO image stabilisation:

ffmpeg -y -i "MYFILE.MP4" -filter_complex '[0:0] [0:1] concat=n=1:v=1:a=1 [vtemp] [a]; [vtemp] lenscorrection=k1=-0.45954925213364517:k2=0.34005346602863429:cx=0.5:cy=0.5 [v]' -map '[v]' -map '[a]' -c:v libx264 -tune film -preset slow -b:v 25000k -pass 1 -acodec libmp3lame -b:a 320k -f mov /dev/null
ffmpeg -y -i "MYFILE.MP4" -filter_complex '[0:0] [0:1] concat=n=1:v=1:a=1 [vtemp] [a]; [vtemp] lenscorrection=k1=-0.45954925213364517:k2=0.34005346602863429:cx=0.5:cy=0.5 [v]' -map '[v]' -map '[a]' -c:v libx264 -tune film -preset slow -b:v 25077k -pass 2 -acodec libmp3lame -b:a 320k -f mov NOFISHEYE.mov


For a single file WITH image stabilisation:

ffmpeg -y -i "MYFILE.MP4" -filter_complex '[0:0] [0:1] concat=n=1:v=1:a=1 [vtemp] [a]; [vtemp] lenscorrection=k1=-0.12235909607751325:k2=-0.11229774620099663:cx=0.5:cy=0.5 [v]' -map '[v]' -map '[a]' -c:v libx264 -tune film -preset slow -b:v 25000k -pass 1 -acodec libmp3lame -b:a 320k -f mov /dev/null
ffmpeg -y -i "MYFILE.MP4" -filter_complex '[0:0] [0:1] concat=n=1:v=1:a=1 [vtemp] [a]; [vtemp] lenscorrection=k1=-0.12235909607751325:k2=-0.11229774620099663:cx=0.5:cy=0.5 [v]' -map '[v]' -map '[a]' -c:v libx264 -tune film -preset slow -b:v 25000k -pass 2 -acodec libmp3lame -b:a 320k -f mov NOFISHEYE.mov


There are 2 commands to run each time because it is a 2 pass encode. That means during the first pass, ffmpeg works out what different bitrate is required at different parts of the file in order to achieve the correct average bitrate. Hope this helps.
 

javiersegurar

New Member
Joined
Oct 14, 2016
Messages
6
Points
0
No problem. I'm so glad someone else has a use for it - I thought I was the only one who needed such a script .


Hi!
First of all, my apologies for so late reply and thank you very much for so kind and usefull answer.

By now I am more on the photo side of my git2 but your info and script are really great. I will be testing for my side and would comment about.

Thanks again for kind reply and best regards!
 
Top