This repository provides a way to post-process media file to decrease the vibration of the video which is caused by other external factors(e.g. hands).
This repository is Microsoft Visual Studio Project and consist of two parts.
One is to show the optical flow of each frames.
The other is to estimate the motion of camera and smooth it, and then genrate the media file which each frame is tranformed by the motion.
Download libraries and header files here before compile
|
+-- ffmpeg (the library and header files of FFmpeg)
| |___ lib
| |___ include
|
+-- opencv (the library and header files of OpenCV)
| |___ lib
| |___ include
|
+-- optical_flow (the code files of optical flow)
| |___ optical_flow.cpp (the main code is here)
| |___ optical_flow.vcxproj/optical_flow.vcxproj.filter
| | (the projects configures)
| |___ stdafx.h (pre-compiled header files)
|
+-- video_stabilization (the code files of video stabilization)
|___ ffmpeg_cv_utils.cpp/hpp (some self-defined functions and structures)
|___ video_stabilization (the main code is here)
|___ video_stabilization.vcxproj/.vcxproj.filter
| (the projects configures)
|___ stdafx.h (pre-compiled header files)
- The sample code which is provided by OpenCV. More info, please refer here
- The concept of the algorithms is inspired by here
- Brief Concept
- Use corner detection by the minimal eigen-value of gradient to get the corners we want to track.
- Track the motions of these corners with Lucas-Kanade optical flow algorithm.
- To sum the motions vector to get the uniform motion of the frame.
- Smooth the motion with moving-average filter.
- Transform the frame with affine model with the motion.
- The input media file is read by OpenCV and the the results of affine transformation of every frames are stored.
- We need to read input again with FFmpeg library and decode every frames because the media which is read by OpenCV is lack of audio and exist more limitaion about writing output file(e.g. size, bit-rate and format).
- Get video/audio frames of input media after decoding
- If video frames, Convert
AVFrame
intocv::Mat
, apply the tranformation and fix the border of the frame and finally encode it with FFmpeg and write to the output media files. - If audio frames, Just encoding and write to the output media files.
- If video frames, Convert
- Get video/audio frames of input media after decoding
- Brief Concept