Play Video in Command Line with FFmpeg SDL
This guide explains how to use FFmpeg’s Simple DirectMedia Layer (SDL) output device to play videos directly from your command line. You will learn the exact command syntax, the importance of real-time streaming flags, and how to control the playback window.
Verifying SDL Support in FFmpeg
Before attempting to play a video, you must ensure your FFmpeg build was compiled with SDL support. Run the following command in your terminal:
ffmpeg -muxers | grep sdlIf you see sdl or sdl2 in the output list,
your FFmpeg installation is ready to render video directly to an SDL
window.
The Basic Playback Command
To play a video file using the SDL output device, use the following command structure:
ffmpeg -re -i input.mp4 -f sdl "Video Playback"Here is what each parameter does:
-re: This flag tells FFmpeg to read the input at the native frame rate (real-time). Without this flag, FFmpeg will process and render the video as fast as your CPU allows, resulting in extremely sped-up playback.-i input.mp4: Specifies the path to your input video file.-f sdl: Forces the output format to the SDL device, which opens a graphical window to display the video."Video Playback": The final argument defines the title of the window that pops up.
Handling Video Scaling and Aspect Ratio
If you want to force the playback window to a specific resolution while using the SDL device, you can apply a video filter before sending the output to SDL:
ffmpeg -re -i input.mp4 -vf scale=1280:720 -f sdl "Scaled Video Playback"The -vf scale=1280:720 flag rescales the video to 720p
HD on the fly before rendering it in the SDL window.
Controlling the Playback
Once the SDL window opens, you can control the playback directly from the terminal where the command is running:
- Pause/Resume: Press
SPC(Spacebar) in the terminal. - Quit Playback: Press
qin the terminal or close the SDL window to stop the process and close the window.