DevelopmentNovember 01, 20244 min read

Video Player using Python and Streamlit

Build a simple in-browser video player with Python and Streamlit — upload and play video files with playback controls and file info, all inside the app.

Galvan

Galvan

Founder & Creator

Introduction

This project shows you how to build a video player web app using Python and Streamlit. Users can upload any video file directly in the browser and watch it with built-in playback controls — no extra software required.


> 🎬 Watch the Full Video Tutorial:

> Watch the walkthrough on YouTube: TOP Python PRO Shares Video Player SECRETS Using Streamlit


Prerequisites

  • Python 3.8+python.org
  • Streamlit:
  • code
    pip install streamlit

    Step 1: Create the Script

    Create video_player.py and paste the following:

    code
    import streamlit as st
    
    st.set_page_config(page_title="Video Player", page_icon="🎬")
    st.title("🎬 Video Player")
    st.write("Upload a video file to play it directly in your browser.")
    
    uploaded_file = st.file_uploader(
        "Choose a video file",
        type=["mp4", "mov", "avi", "mkv", "webm"]
    )
    
    if uploaded_file is not None:
        file_details = {
            "File Name": uploaded_file.name,
            "File Size": f"{uploaded_file.size / (1024 * 1024):.2f} MB",
            "File Type": uploaded_file.type,
        }
        st.subheader("📋 File Information")
        for key, value in file_details.items():
            st.write(f"**{key}:** {value}")
    
        st.subheader("▶️ Now Playing")
        st.video(uploaded_file)
        st.success("Video loaded! Use the player controls to play, pause, or seek.")
    else:
        st.info("Please upload a video file to get started.")

    Step 2: Run the App

    code
    streamlit run video_player.py

    Step 3: Use the Video Player

    Open the app in your browser, click Browse files, and select a video. The file info panel and video player appear instantly below.

    Key Concepts

  • `st.file_uploader()` — Creates a drag-and-drop upload widget with file-type filtering.
  • `st.video()` — Renders a native HTML5 video player for the uploaded file.
  • `uploaded_file.size` — Returns file size in bytes (divide by 1,048,576 for MB).
  • `uploaded_file.type` — Returns the MIME type, e.g. video/mp4.
  • Supported Formats

    FormatExtensionNotes
    MP4.mp4Most common, best browser support
    WebM.webmOpen format, great for the web
    MOV.movApple QuickTime format
    AVI.aviWindows Media format
    MKV.mkvMatroska container

    What to Try Next

  • Extract and show a thumbnail from the first frame using OpenCV.
  • Let users trim the video by specifying start/end times.
  • Allow side-by-side comparison of two uploaded videos.