GitPedia

Sdl2 video player

video player built with ffmpeg and SDL2

From fosterseth·Updated March 27, 2026·View on GitHub·

A lightweight video player built on the SDL2 and ffmpeg libraries. It can play multiple videos simultaneously, all synced to a master clock. In addition, the video playback can be controlled via TCP commands, e.g. "open movie.mp4", "play", "pause", "seekto 350.0", etc. This allows for an easy interface to other applications - Python, Javascript, etc. -- anything that handles basic network sockets. The project is written primarily in C, first published in 2017. Key topics include: audio-video, audiovideo, ffmpeg, libav, msys2.

sdl2 video player

Overview

A lightweight video player built on the SDL2 and ffmpeg libraries. It can play multiple videos simultaneously, all synced to a master clock.
In addition, the video playback can be controlled via TCP commands, e.g. "open movie.mp4", "play", "pause", "seekto 350.0", etc.
This allows for an easy interface to other applications - Python, Javascript, etc. -- anything that handles basic network sockets.

Requirements to Compile

Originally built with msys2 and the mingw64 gcc compiler on a Windows 10 machine.

msys2 packages:

  • mingw-w64-x86_64-ffmpeg 3.3-1
  • mingw-w64-x86_64-SDL2 2.0.5-1

Here are my compiler options in CodeLite

  • preprocessor : main=SDL_main
  • libraries : mingw32;SDL2main;SDL2;avutil;swresample;avcodec;avformat;swscale;ws2_32

Cross-platform note

Everything is crossplatform except the socket programming code, read_from_client() method. The current source code has a winsock2 implementation, for Windows. It would be pretty easy to swap this out with linux socket programming.

Basic Usage

vidserv.exe portnum movie1.mp4 movie2.mp4 ...

If you don't specify a port number, it defaults with 50001, which should be open on most machines.

ffmpeg supports a wide range of codecs and formats, so most videos should load fine.

HotkeyCommand
DownSeek 10 seconds forward
UpSeek 10 seconds backward
RightShow next frame
LeftSeek 0.25 seconds backward
SpaceToggle play/pause

TCP Control

Videos can be opened and controlled via tcp commands.

For example in Python, after setting up tcp connection to vidserv.exe,

python
sock.send("seekto 60.0".encode())
  • open movie1.mp4 xscreen yscreen width height windowname

    • e.g. open c:/users/fosterseth/desktop/movie.mp4 100 100 640 480 movie1
    • To use native width and height of video, just put 0 for both width and height
  • seekto x

    • x is in seconds
  • seek+

    • seeks 60 seconds forward
  • seek-

    • seeks 60 seconds back
  • seek+small

    • seeks to next frame
  • seek-small

    • seeks back 0.25 seconds
  • play

  • pause

  • toggleplay

  • gettime

    • a request for the current playback time, in seconds
    • client must call recv() to get the message back
  • getnumvideos

    • a request for the number of active videos
    • client must call recv() to get message back
  • getpos movie1.mp4

    • a request for the current x,y,w,h of movie1.mp4
    • client must call recv() to get message back
  • raisewindows

    • restores minimized windows
  • closewindows

    • closes all windows, but keeps server running
  • break

    • closes all windows and quits the server

Binaries

For convenience, the bin/ folder contains a compiled vidserv and the required DLL to run on a Windows machine.

Credits

dranger's tutorial was immensely helpful for this project. Check out his tutorial if you are new to AV processing.

Contributors

Showing top 1 contributor by commit count.

View all contributors on GitHub →

This article is auto-generated from fosterseth/sdl2_video_player via the GitHub API.Last fetched: 6/19/2026