This project analyzes video complexity using various metrics such as advanced motion complexity, DCT complexity, temporal DCT complexity, histogram complexity, edge detection, ORB feature complexity, and color histogram complexity. Additionally, it computes video quality metrics like PSNR, SSIM, and VMAF using FFmpeg.
- Frame-based Scene Complexity Analysis: Calculates complexity using motion estimation, DCT, histogram, edge detection, and ORB features.
- Quality Metrics Calculation: Computes PSNR, SSIM, and VMAF between original and compressed videos.
- Parallel Processing: Processes video frames in parallel to speed up computation using batch processing.
- Exponential Smoothing: Smooths metrics over time to reduce noise in complexity measurements.
- Configurable Parameters: Easily configure CRF, frame interval, and video resizing in a JSON file.
- GPU acceleration: Use CUDA is GPU is defined otherwise fallback on CPU
-
Python 3.6+
-
FFmpeg (installed and available in the system's PATH)
-
Python packages: Install them by running:
pip install -r requirements.txt
The requirements.txt should include:
- OpenCV
- NumPy
- Pandas
- tqdm
- logging
- json
- multiprocessing
You can configure the parameters in config.json. The default parameters are as follows:
{
"crf": 23,
"vmaf_model_path": null,
"resize_width": 64,
"resize_height": 64,
"frame_interval": 10
}
- crf: CRF (Constant Rate Factor) for video encoding.
- vmaf_model_path: Path to the VMAF model file. If not specified, FFmpeg’s default model is used.
- resize_width: Width to which frames are resized for processing.
- resize_height: Height to which frames are resized for processing.
- frame_interval: Interval of frames to process for complexity analysis.
To run the project, use the following command:
python video_processing.py config.json input_video.mp4
python video_processing.py config.json sample_video.mp4
This will process the sample_video.mp4 file and calculate the complexity and quality metrics, saving the results to video_quality_data.csv.
One row for each piece of content analyzed.
Bitrate (kbps),Resolution (px),Frame Rate (fps),CRF,PSNR,SSIM,VMAF,Advanced Motion Complexity,DCT Complexity,Temporal DCT Complexity,Histogram Complexity,Edge Detection Complexity,ORB Feature Complexity,Color Histogram Complexity,Framerate Variation
4486,1920x1080,30.0,23,50.78,0.994884,95.837165,1.8996385499013766,2257755.4423618754,235402.93371073596,2.701894116582357,177.94077592605998,0.08097739594415695,8.07616546666872,3.0000000000000004
- calculate_average_scene_complexity: Calculates complexity metrics like motion, DCT, temporal DCT, and edge detection.
- process_in_batches: Handles the parallel processing of frames in batches.
- run_ffmpeg_metrics: Executes FFmpeg commands to calculate PSNR, SSIM, and VMAF.
- thread_safe_update_csv: Updates CSV files in a thread-safe manner to store results.
The results of the analysis are saved in a CSV file (video_quality_data.csv). The following metrics are included:
- Advanced Motion Complexity
- DCT Complexity
- Temporal DCT Complexity
- ORB Feature Complexity
- Histogram Complexity
- Edge Detection Complexity
- Color Histogram Complexity
- Framerate Variation
- PSNR, SSIM, and VMAF (Quality Metrics)
- Bitrate, Frame Rate, and Resolution
Logs are stored in video_processing.log, providing details of the processing steps, warnings, and errors.
This project is licensed under the MIT License. See the LICENSE file for details.