A simple video player backend built using FFmpeg for video decoding and OpenGL/GLFW for rendering, designed to process and display video frames with customizable transformations. This project currently supports playing a video with the option to double the width using a bilinear scaling shader, maintaining the original height for a stretched effect.
- Decodes video files using FFmpeg's software decoding pipeline.
- Renders video frames in an OpenGL window using GLFW.
- Supports doubling the video width with smooth bilinear interpolation via an OpenGL shader.
- Maintains even dimensions for compatibility with FFmpeg's scaling requirements.
- Robust error handling to prevent crashes (e.g., access violations).
- MSVC-compatible file handling using
fopen_s.
- Operating System: Windows (tested on Windows 10/11)
- Compiler: Microsoft Visual Studio (tested with VS 2022)
- Dependencies:
- FFmpeg: Libraries (
libavformat,libavcodec,libavutil,libswscale) and DLLs (avformat-61.dll,avcodec-61.dll,avutil-59.dll,swscale-8.dll,avdevice-61,avfilter-10.dll,swresample-5.dll,postproc-58.dll) - GLEW: OpenGL Extension Wrangler Library (
glew32.lib,glew32.dll) - GLFW: Window and input handling (
glfw3.lib,glfw3.dll) - OpenGL: Provided by Windows (
opengl32.lib)
- FFmpeg: Libraries (
Here’s a detailed breakdown of the dependencies (GLEW, FFmpeg, GLFW, and OpenGL), including their libraries, DLLs, and how they integrate into the project.
- Purpose: Simplifies the use of OpenGL extensions by loading them at runtime. The code uses GLEW to access modern OpenGL functions (e.g., for shaders and textures).
- Files Needed:
- Header:
include/GL/glew.h - Static Library:
lib/Release/x64/glew32.lib(links at compile time) - DLL:
bin/Release/x64/glew32.dll(required at runtime)
- Header:
- Why Both Lib and DLL?: The
glew32.libfile tells the linker how to interface withglew32.dll, which contains the actual runtime code for OpenGL extension management. - Source: Download from GLEW Releases or GitHub.
- Purpose: Handles video file parsing, decoding, and color space conversion. The code uses FFmpeg’s
libavformat(file I/O),libavcodec(decoding),libavutil(utilities), andlibswscale(YUV-to-RGB conversion). - Files Needed:
- Headers:
include/libavformat/avformat.h,include/libavcodec/avcodec.h,include/libavutil/imgutils.h,include/libswscale/swscale.h - Static Libraries:
lib/avformat.lib,lib/avcodec.lib,lib/avutil.lib,lib/swscale.lib(links at compile time) - DLLs:
bin/avformat-61.dll,bin/avcodec-61.dll,bin/avutil-59.dll,bin/swscale-8.dll(required at runtime)
- Headers:
- Why Both Lib and DLL?: The
.libfiles are import libraries that provide the interface for the linker to connect to the corresponding.dllfiles, which contain the actual FFmpeg functionality at runtime. - Source: Download a shared and dev build from FFmpeg Builds or gyan.dev. Ensure the version matches your DLLs (e.g., 7.0 for
avcodec-61.dll).
- Purpose: Creates windows, handles input, and manages the OpenGL context. The code uses GLFW to open a window and render video frames.
- Files Needed:
- Header:
include/GLFW/glfw3.h - Static Library:
lib-vc2022/glfw3.lib(links at compile time, adjust for your VS version) - DLL:
glfw3.dll(required at runtime, location varies by build)
- Header:
- Why Both Lib and DLL?: Similar to GLEW and FFmpeg,
glfw3.libprovides the linker interface toglfw3.dll, which handles window and context management at runtime. - Source: Download pre-compiled binaries or source from GLFW Downloads.
- Purpose: Provides the graphics API for rendering video frames. The code uses OpenGL to create textures, shaders, and render a quad.
- Files Needed:
- Header: Provided by Windows SDK (
include/GL/gl.h, included via GLEW) - Static Library:
opengl32.lib(included with Windows SDK, links at compile time) - DLL:
opengl32.dll(system-provided, no need to copy)
- Header: Provided by Windows SDK (
- Why Only Lib?:
opengl32.libinterfaces with the system’sopengl32.dll, which is part of Windows and doesn’t need to be distributed.
Here’s a step-by-step guide to set up the dependencies in Visual Studio 2022 for the VideoPlayer-BackendProcessing-OpenGL project. This assumes you’ve downloaded FFmpeg, GLEW, and GLFW and have their include, lib, and bin folders ready.
- FFmpeg:
- Example path:
C:\ffmpeg - Folders:
C:\ffmpeg\include,C:\ffmpeg\lib,C:\ffmpeg\bin - Copy DLLs (
avformat-61.dll,avcodec-61.dll,avutil-59.dll,swscale-8.dll,avdevice-61,avfilter-10.dll,swresample-5.dll,postproc-58.dll) fromC:\ffmpeg\binto your project’sx64\Debugandx64\Releasedirectories (e.g.,VideoPlayer-BackendProcessing-OpenGL\x64\Debug).
- Example path:
- GLEW:
- Example path:
C:\glew - Folders:
C:\glew\include,C:\glew\lib\Release\x64,C:\glew\bin\Release\x64 - Copy
glew32.dllfromC:\glew\bin\Release\x64to where your.slnfile is.
- Example path:
- Open Visual Studio 2022 and create a new C++ project (e.g., Empty Project) or open your existing
VideoPlayer-BackendProcessing-OpenGL.sln. - Add
main.cpp(the code provided in the previous message) to the project. - Set the solution configuration to
Debugand platform tox64(Solution Explorer > Solution Platforms > x64).
- Right-click the project in Solution Explorer > Properties.
- Ensure the configuration is set to
Debugand platform tox64in the Property Pages dialog. - Update the following settings:
- C/C++ > General > Additional Include Directories:
Replace paths with your actual folder locations.
C:\ffmpeg\include;C:\glew-2.1.0\include;C:\glfw-3.4.bin.WIN64\include - Linker > General > Additional Library Directories:
Adjust paths as needed.
C:\ffmpeg\lib;C:\glew-2.1.0\lib\Release\x64;C:\glfw-3.4.bin.WIN64\lib-vc2022 - Linker > Input > Additional Dependencies:
glew32.lib, glfw3.lib, opengl32.lib, user32.lib, gdi32.lib, shell32.lib, avcodec.lib, avdevice.lib, avfilter.lib, avformat.lib, avutil.lib, postproc.lib, swresample.lib, swscale.lib
- C/C++ > General > Additional Include Directories:
- Repeat for the
Releaseconfiguration if you plan to build in Release mode (optional for now, as you’re using Debug).
- Ensure the following DLLs are in
x64\Debug(relative to your project’s executable):avformat-61.dllavcodec-61.dllavdevice-61.dllavfilter-10.dllavutil-59.dllswscale-8.dllswresample-5.dllpostproc-58.dll
- If Visual Studio can’t find the DLLs at runtime, you’ll get an error like “The application was unable to start correctly (0xc000007b)”. Copying them to the executable directory resolves this.
- Place a valid H.264 MP4 video at
C:\Users\ferni\Videos\Captures\video.mp4. - Alternatively, edit
main.cppto updatevideoPath:const char* videoPath = "path\\to\\your\\video.mp4";