一、实现功能
从mp4文件截取局部视频。
splite_video(std::string in_filename, std::string out_filename, int begin_index, int end_index)
参数解析:
in_filename:输入文件
out_filename:输出文件
begin_index:起始帧 //若起始帧不是关键帧,则选取前面一帧关键帧作为起始帧
end_index:结束帧
av_seek_frame(ifmt_ctx, video_stream_index, 0, 4);//从头开始读取流
二、源程序
#include "SpliteVideo.h"
#ifdef __cplusplus
extern "C" {
#endif __cplusplus
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
#ifdef __cplusplus
}
#endif __cplusplus
static void log_packet(const AVFormatContext *fmt_ctx, const AVPacket *pkt, const char *tag)
{
AVRational *time_base = &fmt_ctx->streams[pkt->stream_index]->time_base;
printf("%s: pts:%s pts_time:%s dts:%s dts_time:%s duration:%s duration_time:%s stream_index:%d\n",
tag,
av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, time_base),
av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, time_base),
av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, time_base),
pkt->stream_index);
}
int splite_video(std::string in_filename, std::string out_filename, int begin_index, int end_index) {
if (begin_index < 0 |