Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions Detection Models/Video-tampering-detection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Video Tampering and Forensics Analysis Tool

## Abstract

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.

## Features

- **User-Friendly Interface**: Interactive web-based application using Streamlit.
- **Video Input**: Supports video file formats such as MP4, AVI, and MOV (file size limit: 200MB).
- **Metadata Extraction**: Provides key details such as resolution, codec, frame count, duration, and geolocation data (if available).
- **Hashing (MD5)**: Verifies the integrity of the video by generating a unique hash for comparison.
- **Frame Analysis**: Detects tampering through frame-by-frame inspection for splicing, insertion, and pixel pattern anomalies.
- **Comprehensive Report Generation**: Outputs a JSON report with all findings, including extracted metadata and hash values.

## Technologies Used

- **Programming Language**: Python
- **Libraries**: OpenCV, FFmpeg, hashlib, os, json
- **Web Framework**: Streamlit
- **Hashing Algorithm**: MD5

## Setup Instructions

#### First Fork the repository and then follow the steps given below!

### 1. Clone the Repository

```sh
git clone https://github.com/<your-username>/machine-learning-repos.git
cd Detection Models/Video-tampering-detection
```
### 2. Create a virtual environment:
```sh
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
```

### 3. Install the required packages:
```sh
pip install -r requirements.txt
```

### 4. Run the application:
```sh
streamlit run main.py
```
### 5. Usage Instructions

##### 1. Open your web browser and go to `http://localhost:8501` to access the app.

##### 2. Upload a video file (MP4, AVI, MOV) for analysis.

##### 3. View the results on the web interface, including:
- Extracted metadata
- MD5 hash for integrity verification
- Frame-by-frame analysis

##### 4. Download the comprehensive JSON report summarizing the findings.

### 6. Stop the Application:
To stop the Streamlit app, press `CTRL + C` in the terminal.


## Contributing
Contributions are welcome! If you find any bugs or have suggestions for improvements, please open an issue or create a pull request.

## License
This project is licensed under the MIT License. See the `LICENSE` file for more details.
63 changes: 63 additions & 0 deletions Detection Models/Video-tampering-detection/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import os
import json
import streamlit as st
from metadata import extract_metadata
from hash_calculator import calculate_hash
from frame_analyzer import analyze_frames

# Streamlit app
st.title('Video Forensic Analysis Tool')

# File uploader
uploaded_file = st.file_uploader('Upload a video file', type=['mp4', 'avi', 'mov'])

if uploaded_file is not None:
# Check if 'temp' folder exists, create if not
temp_folder = 'temp'
if not os.path.exists(temp_folder):
os.makedirs(temp_folder)

# Save the uploaded file temporarily
temp_file_path = os.path.join(temp_folder, uploaded_file.name)
with open(temp_file_path, 'wb') as f:
f.write(uploaded_file.read())

st.write("**File uploaded successfully**")

# Extract metadata
st.write("**Extracting metadata...**")
metadata = extract_metadata(temp_file_path)
st.json(metadata)

# Calculate hash
st.write("**Calculating file hash (MD5)...**")
video_hash = calculate_hash(temp_file_path)
st.write(f"MD5 Hash: {video_hash}")

# Analyze frames for alterations
st.write("**Analyzing frames for alterations...**")
altered_frames = analyze_frames(temp_file_path)
st.write(f"Altered frames: {altered_frames}")

# Generate report name based on video file name
file_name = os.path.splitext(uploaded_file.name)[0]
report_name = f'report-{file_name}.json'

# Report creation
report = {
'metadata': metadata,
'hash': video_hash,
'altered_frames': altered_frames
}

st.write(f"**Video forensic analysis complete! Report saved as: {report_name}**")
st.json(report)

# Offer download of the JSON report
report_json = json.dumps(report, indent=4)
st.download_button(
label="Download report as JSON",
data=report_json,
file_name=report_name,
mime="application/json"
)
18 changes: 18 additions & 0 deletions Detection Models/Video-tampering-detection/frame_analyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import cv2

def analyze_frames(video_path):
cap = cv2.VideoCapture(video_path)
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
altered_frames = []
prev_frame = None

for i in range(frame_count):
ret, frame = cap.read()
if ret:
if prev_frame is not None:
if not (frame == prev_frame).all():
altered_frames.append(i)
prev_frame = frame.copy()

cap.release()
return altered_frames
8 changes: 8 additions & 0 deletions Detection Models/Video-tampering-detection/hash_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import hashlib

def calculate_hash(video_path):
hash_md5 = hashlib.md5()
with open(video_path, 'rb') as f:
for chunk in iter(lambda: f.read(4096), b''):
hash_md5.update(chunk)
return hash_md5.hexdigest()
11 changes: 11 additions & 0 deletions Detection Models/Video-tampering-detection/metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import cv2

def extract_metadata(video_path):
metadata = {}
cap = cv2.VideoCapture(video_path)
metadata['frame_count'] = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
metadata['frame_width'] = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
metadata['frame_height'] = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
metadata['fps'] = int(cap.get(cv2.CAP_PROP_FPS))
cap.release()
return metadata
Binary file not shown.
Loading