目的
截取视频中的一段
思路
先是将源媒体文件copy一份 知道截取视频的起始点与结束点
主要API
1. av_seek_frame():跳一段时间
源码
#include<stdlib.h>
#include<libavutil/timestamp.h>
#include<libavformat/avformat.h>
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->pts,time_base),
av_ts2str(pkt->duration),av_ts2timestr(pkt->duration,time_base),
pkt->stream_index);
}
int cut_video(double from_seconds,double end_seconds,const char* in_filename, const char* out_filename){
AVOutputFormat *ofmt =NULL;
AVFormatContext *ifmt_ctx= NULL, *ofmt_ctx = NULL;
AVPacket pkt;
int ret,i;
/*input*/
//1.open in_filename
if((ret = avformat_open_input(&ifmt_ctx,in_filename,0,0))<0){
fprintf(stderr,"Could not open input file '%s'",in_filename);
goto end;
}
if((ret = avformat_find_stream_info(ifmt_ctx,0))<0){
fprintf(stderr,