To get the frames per second (FPS) value from a video file using FFmpeg and C++, you can follow these steps:
- Include the required FFmpeg header files in your C++ source code:
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
- Open the input video file using the
avformat_open_input()
function:
AVFormatContext *format_context = nullptr;
int error = avformat_open_input(&format_context, input_filename, nullptr, nullptr);
if (error < 0) {
// Handle error
}
- Find the stream information in the input file using the
avformat_find_stream_info()
function:
error = avformat_find_stream_info(format_context, nullptr);
if (error < 0) {
// Handle error
}
- Find the video stream in the input file using the
av_find_best_stream()
function:
int video_stream_index = av_find_best_stream(format_context, AVMEDIA_TYPE_VIDEO, -1, -1, nullptr, 0);
if (video_stream_index < 0) {
// Handle error
}
- Get the FPS value from the video stream's codec context using the
av_q2d()
function:
AVStream *video_stream = format_context->streams[video_stream_index];
AVCodecContext *codec_context = video_stream->codec;
double fps = av_q2d(codec_context->framerate);
- Close the input file and release the format context using the
avformat_close_input()
function:
avformat_close_input(&format_context);
Similar way of identifying the fps, refer the many upvoted stackoverflow answer
Comments
Post a Comment