视频慢动作处理是个比较常用的操作,可以在播放的时候处理,这里我们考虑把视频修改为慢动作,使用ffmpeg命令,可以这样
ffmpeg -i test.mp4 -vf "setpts=5*PTS" -an test_slow3.mp4
这里把视频放慢了5倍,生成的文件大小也变大了几倍。
怎么用程序来实现呢,参考一下GPT给出的code,
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstring>
extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/opt.h>
}
// 慢速播放的速度因子
const double SLOWDOWN_FACTOR = 2.0;
int main(int argc, char* argv[]) {
if (argc < 3) {
std::cout << "Usage: " << argv[0] << " input_file output_file" << std::endl;
return 1;
}
const std::string inputFileName = argv[1];
const std::string outputFileName = argv[2];
av_register_all();
AVFormatContext* inputFormatContext = nullptr;
if (avformat_open_input(&inputFormatContext, inputFileName.c_str(), nullptr, nullptr) != 0) {
std::cerr << "Failed to open input file: " << inputFileName << std::endl;
return 1;
}
if (avformat_find_stream_info(inputFormatContext, nullptr) < 0) {
std::cerr << "Failed to retrieve input stream information" << std::endl;
avformat_close_input(&inputFormatContext);
return 1;
}
AVFormatContext* outputFormatContext = nullptr;
if (avformat_alloc_o