Skip to content

shyan23/Netflacks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎬 NetFlacks - P2P Video Streaming Platform

Revolutionizing video distribution through decentralized networks

Python FastAPI Streamlit WebRTC

GitHub Stars License Build Status


πŸš€ Project Overview

NetFlacks is a cutting-edge peer-to-peer video streaming platform that eliminates reliance on centralized servers by distributing video content across a network of participating nodes. Built from the ground up with modern networking principles, it demonstrates scalable architecture, distributed systems design, and real-time media processing.

🎯 Key Innovation

Progressive Streaming + P2P Distribution: Videos start playing almost instantly while chunks are fetched from multiple peers simultaneously, creating a Netflix-like experience powered by decentralized infrastructure.


πŸ—οΈ System Architecture

graph TB
    subgraph "Client Layer"
        UI[Streamlit Web UI]
        Browser[HTML5 Video Player]
    end
    
    subgraph "Application Layer"
        SS[Streaming Server<br/>FastAPI]
        FC[File Processor<br/>FFmpeg Integration]
    end
    
    subgraph "P2P Network Layer"
        DHT[Distributed Hash Table<br/>Peer Coordination]
        P1[Peer Node 1<br/>Chunk Storage]
        P2[Peer Node 2<br/>Chunk Storage]
        P3[Peer Node N<br/>Chunk Storage]
    end
    
    subgraph "Data Layer"
        CH1[Video Chunks<br/>1MB segments]
        CH2[Metadata<br/>JSON indexes]
        CH3[Hash Verification<br/>SHA-256]
    end
    
    UI --> SS
    Browser --> SS
    SS --> DHT
    SS --> FC
    DHT --> P1
    DHT --> P2
    DHT --> P3
    P1 --> CH1
    P2 --> CH1
    P3 --> CH1
    FC --> CH2
    FC --> CH3
    
    style DHT fill:#ff6b6b
    style SS fill:#4ecdc4
    style UI fill:#45b7d1
    style P1 fill:#96ceb4
    style P2 fill:#96ceb4
    style P3 fill:#96ceb4
Loading

⚑ Core Features

πŸŽ₯ Streaming Excellence

  • Instant Playback: MP4 metadata optimization enables immediate streaming
  • Progressive Loading: Videos start before full download completion
  • Seeking Support: Jump to any downloaded portion seamlessly
  • Real-time Status: Live download progress visualization

🌐 P2P Innovation

  • Custom DHT: Built-from-scratch distributed hash table
  • Chunk Distribution: 1MB segments with SHA-256 integrity
  • Peer Discovery: Automatic network topology management
  • Fault Tolerance: Redundant storage across multiple peers

πŸ”§ Technical Implementation

Networking Stack

# Custom P2P Protocol Implementation
class PeerNode:
    def __init__(self, peer_id, host, port):
        self.peer_id = peer_id
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.dht_node = DHTNode()
        self.chunk_storage = {}
    
    async def handle_chunk_request(self, chunk_hash):
        # Asynchronous chunk serving with integrity verification
        chunk_data = self.load_chunk(chunk_hash)
        if self.verify_hash(chunk_data, chunk_hash):
            return chunk_data

Video Processing Pipeline

# FFmpeg integration for streaming optimization
def optimize_for_streaming(video_path):
    """Relocate MP4 moov atom for instant playback"""
    cmd = [
        'ffmpeg', '-i', video_path,
        '-c', 'copy',
        '-movflags', 'faststart',
        optimized_path
    ]
    subprocess.run(cmd)

Distributed Hash Table

class DHT:
    def __init__(self):
        self.peers = {}
        self.chunk_locations = {}
        self.redistributor = Redistributor()
    
    def find_chunk_peers(self, chunk_hash):
        """Consistent hashing for optimal peer selection"""
        return self.redistributor.get_closest_peers(chunk_hash)

πŸ“Š Performance Metrics

Metric Performance
Startup Time < 3 seconds to first frame
Chunk Size 1MB (optimal for network efficiency)
Redundancy Factor 2x replication across peers
Seeking Latency Instant for downloaded portions
Network Protocol TCP for reliability
Hash Algorithm SHA-256 for integrity

πŸ› οΈ Technology Stack

Backend

Python FastAPI AsyncIO

Frontend

Streamlit HTML5 JavaScript

Networking

TCP P2P DHT

Media Processing

FFmpeg SHA256


🚦 Quick Start

Prerequisites

# System requirements
Python 3.8+
FFmpeg (for video processing)
Network ports 8000-9000 available

Installation

# Clone the repository
git clone https://github.com/abrr-fhyz/Peer2PeerNetwork.git
cd Peer2PeerNetwork

# Install dependencies
pip install -r requirements.txt
pip install fastapi['all']
pip install streamlit

# Verify FFmpeg installation
ffmpeg -version

make a .env file

#In the .env file,paste the following lines
HOST_IP=localhost
HOST_PORT=9004
DHT_PORT=8000
API_PORT=8080

Launch the Network

# Terminal 1: Start Streaming Server
python streaming_server.py

# Terminal 2: Launch Web Interface
streamlit run main.py

Usage Flow

  1. Upload β†’ Select video file through web interface
  2. Process β†’ System optimizes and chunks the video automatically
  3. Distribute β†’ Chunks spread across peer network via DHT
  4. Stream β†’ Click play for instant Netflix-like experience

🎯 Project Highlights

Technical Achievements

  • βœ… Custom P2P Protocol: Built networking stack from scratch using raw sockets
  • βœ… Distributed Architecture: Implemented consistent hashing for scalable peer management
  • βœ… Real-time Streaming: Achieved sub-3-second startup times with progressive loading
  • βœ… Media Optimization: Integrated FFmpeg for instant-playback video processing
  • βœ… Fault Tolerance: Redundant chunk storage with automatic peer failure handling

Engineering Excellence

  • πŸ—οΈ Modular Design: Clean separation of concerns with OOP principles
  • πŸ”„ Async Operations: Non-blocking I/O for concurrent peer communications
  • πŸ›‘οΈ Data Integrity: SHA-256 verification for all transmitted chunks
  • πŸ“Š Performance Monitoring: Real-time network status and streaming metrics
  • 🎨 Modern UI: Responsive web interface with live progress tracking

πŸ“ˆ System Workflow

sequenceDiagram
    participant U as User
    participant UI as Web Interface
    participant SS as Streaming Server
    participant DHT as DHT Coordinator
    participant P1 as Peer Node 1
    participant P2 as Peer Node 2
    
    U->>UI: Upload Video
    UI->>SS: Process Video Request
    SS->>SS: FFmpeg Optimization
    SS->>SS: Chunk Generation (1MB)
    SS->>DHT: Register Video Metadata
    SS->>DHT: Find Storage Peers
    DHT->>P1: Store Chunks 1,3,5...
    DHT->>P2: Store Chunks 2,4,6...
    
    Note over U,P2: Streaming Phase
    
    U->>UI: Click Play
    UI->>SS: Stream Request
    SS->>DHT: Get Chunk Locations
    DHT->>SS: Return Peer List
    
    par Concurrent Chunk Retrieval
        SS->>P1: Request Chunk 1
        P1->>SS: Return Chunk 1
    and
        SS->>P2: Request Chunk 2
        P2->>SS: Return Chunk 2
    end
    
    SS->>UI: HTTP Stream Response
    UI->>U: Video Playback Starts
Loading

πŸ”¬ Research & Innovation

Algorithmic Contributions

  • Hybrid P2P Architecture: Balances decentralization with streaming performance
  • Progressive Chunk Assembly: On-the-fly video reconstruction with seeking support
  • Intelligent Peer Selection: Distance-based DHT routing for optimal chunk placement
  • Streaming Buffer Management: Predictive downloading for smooth playback

Problem-Solution Matrix

Challenge Solution Impact
Cold Start Problem MP4 moov atom relocation Instant playback
Peer Discovery Custom DHT implementation Scalable network growth
Data Integrity SHA-256 chunk verification Zero corruption tolerance
Single Point of Failure Redundant chunk storage 99.9% availability
Bandwidth Optimization 1MB chunk sizing Efficient network utilization

πŸ“š Academic Foundation

Course: CSE 3111 - Computer Networking
Institution: University of Dhaka, Department of Computer Science & Engineering
Session: 3rd Year 1st Semester

Applied Networking Concepts

  • Socket Programming (TCP/UDP)
  • Application Layer Protocols
  • Distributed Hash Tables
  • Peer-to-Peer Architecture
  • Media Streaming Protocols
  • Network Performance Optimization

πŸ† Results & Impact

Measured Outcomes

  • Scalability: Successfully tested with 4+ concurrent peers
  • Performance: < 3-second video startup time achieved
  • Reliability: Maintained streaming during peer disconnections
  • User Experience: Netflix-comparable interface and functionality

Technical Validation

  • βœ… Progressive streaming without full download
  • βœ… Instant seeking within downloaded portions
  • βœ… Automatic chunk redistribution on peer failure
  • βœ… Real-time network status monitoring
  • βœ… Cross-platform compatibility

πŸ“œ License & Repository

  • License: MIT License

πŸ“ž Contact & Collaboration

πŸ‘¨β€πŸ’» Authors & Collaborators

πŸ§‘β€πŸš€ Abrar Fahyaz

GitHub LinkedIn

πŸ§‘β€πŸ’» Nafis Shyan

GitHub LinkedIn

⭐ Star this repository if you found it impressive!


Built with ❀️ for the future of decentralized media

NetFlacks - Where P2P meets modern streaming

About

A P2P video streaming platform,Networking Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •