Skip to content

Commit a534e94

Browse files
authored
Adding Video Tampering Detection Tool
1 parent 6983fb2 commit a534e94

File tree

6 files changed

+169
-0
lines changed

6 files changed

+169
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Video Tampering and Forensics Analysis Tool
2+
3+
## Abstract
4+
5+
The **Video Tampering and Forensic Analysis Tool** is designed to ensure the authenticity and integrity of digital video content. In fields like law enforcement and journalism, reliable video evidence is crucial. This tool uses advanced techniques such as metadata examination, frame-by-frame analysis, deepfake detection, and watermark authentication to detect video tampering and manipulations. It generates detailed forensic reports to aid investigative professionals in ensuring the credibility of video evidence.
6+
7+
## Features
8+
9+
- **User-Friendly Interface**: Interactive web-based application using Streamlit.
10+
- **Video Input**: Supports video file formats such as MP4, AVI, and MOV (file size limit: 200MB).
11+
- **Metadata Extraction**: Provides key details such as resolution, codec, frame count, duration, and geolocation data (if available).
12+
- **Hashing (MD5)**: Verifies the integrity of the video by generating a unique hash for comparison.
13+
- **Frame Analysis**: Detects tampering through frame-by-frame inspection for splicing, insertion, and pixel pattern anomalies.
14+
- **Comprehensive Report Generation**: Outputs a JSON report with all findings, including extracted metadata and hash values.
15+
16+
## Technologies Used
17+
18+
- **Programming Language**: Python
19+
- **Libraries**: OpenCV, FFmpeg, hashlib, os, json
20+
- **Web Framework**: Streamlit
21+
- **Hashing Algorithm**: MD5
22+
23+
## Setup Instructions
24+
25+
#### First Fork the repository and then follow the steps given below!
26+
27+
### 1. Clone the Repository
28+
29+
```sh
30+
git clone https://github.com/<your-username>/machine-learning-repos.git
31+
cd Detection Models/Video-tampering-detection
32+
```
33+
### 2. Create a virtual environment:
34+
```sh
35+
python -m venv venv
36+
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
37+
```
38+
39+
### 3. Install the required packages:
40+
```sh
41+
pip install -r requirements.txt
42+
```
43+
44+
### 4. Run the application:
45+
```sh
46+
streamlit run main.py
47+
```
48+
### 5. Usage Instructions
49+
50+
##### 1. Open your web browser and go to `http://localhost:8501` to access the app.
51+
52+
##### 2. Upload a video file (MP4, AVI, MOV) for analysis.
53+
54+
##### 3. View the results on the web interface, including:
55+
- Extracted metadata
56+
- MD5 hash for integrity verification
57+
- Frame-by-frame analysis
58+
59+
##### 4. Download the comprehensive JSON report summarizing the findings.
60+
61+
### 6. Stop the Application:
62+
To stop the Streamlit app, press `CTRL + C` in the terminal.
63+
64+
65+
## Contributing
66+
Contributions are welcome! If you find any bugs or have suggestions for improvements, please open an issue or create a pull request.
67+
68+
## License
69+
This project is licensed under the MIT License. See the `LICENSE` file for more details.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import os
2+
import json
3+
import streamlit as st
4+
from metadata import extract_metadata
5+
from hash_calculator import calculate_hash
6+
from frame_analyzer import analyze_frames
7+
8+
# Streamlit app
9+
st.title('Video Forensic Analysis Tool')
10+
11+
# File uploader
12+
uploaded_file = st.file_uploader('Upload a video file', type=['mp4', 'avi', 'mov'])
13+
14+
if uploaded_file is not None:
15+
# Check if 'temp' folder exists, create if not
16+
temp_folder = 'temp'
17+
if not os.path.exists(temp_folder):
18+
os.makedirs(temp_folder)
19+
20+
# Save the uploaded file temporarily
21+
temp_file_path = os.path.join(temp_folder, uploaded_file.name)
22+
with open(temp_file_path, 'wb') as f:
23+
f.write(uploaded_file.read())
24+
25+
st.write("**File uploaded successfully**")
26+
27+
# Extract metadata
28+
st.write("**Extracting metadata...**")
29+
metadata = extract_metadata(temp_file_path)
30+
st.json(metadata)
31+
32+
# Calculate hash
33+
st.write("**Calculating file hash (MD5)...**")
34+
video_hash = calculate_hash(temp_file_path)
35+
st.write(f"MD5 Hash: {video_hash}")
36+
37+
# Analyze frames for alterations
38+
st.write("**Analyzing frames for alterations...**")
39+
altered_frames = analyze_frames(temp_file_path)
40+
st.write(f"Altered frames: {altered_frames}")
41+
42+
# Generate report name based on video file name
43+
file_name = os.path.splitext(uploaded_file.name)[0]
44+
report_name = f'report-{file_name}.json'
45+
46+
# Report creation
47+
report = {
48+
'metadata': metadata,
49+
'hash': video_hash,
50+
'altered_frames': altered_frames
51+
}
52+
53+
st.write(f"**Video forensic analysis complete! Report saved as: {report_name}**")
54+
st.json(report)
55+
56+
# Offer download of the JSON report
57+
report_json = json.dumps(report, indent=4)
58+
st.download_button(
59+
label="Download report as JSON",
60+
data=report_json,
61+
file_name=report_name,
62+
mime="application/json"
63+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import cv2
2+
3+
def analyze_frames(video_path):
4+
cap = cv2.VideoCapture(video_path)
5+
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
6+
altered_frames = []
7+
prev_frame = None
8+
9+
for i in range(frame_count):
10+
ret, frame = cap.read()
11+
if ret:
12+
if prev_frame is not None:
13+
if not (frame == prev_frame).all():
14+
altered_frames.append(i)
15+
prev_frame = frame.copy()
16+
17+
cap.release()
18+
return altered_frames
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import hashlib
2+
3+
def calculate_hash(video_path):
4+
hash_md5 = hashlib.md5()
5+
with open(video_path, 'rb') as f:
6+
for chunk in iter(lambda: f.read(4096), b''):
7+
hash_md5.update(chunk)
8+
return hash_md5.hexdigest()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import cv2
2+
3+
def extract_metadata(video_path):
4+
metadata = {}
5+
cap = cv2.VideoCapture(video_path)
6+
metadata['frame_count'] = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
7+
metadata['frame_width'] = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
8+
metadata['frame_height'] = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
9+
metadata['fps'] = int(cap.get(cv2.CAP_PROP_FPS))
10+
cap.release()
11+
return metadata
Binary file not shown.

0 commit comments

Comments
 (0)