ffmpeg-截取视频段

该博客详细介绍了如何使用ffmpeg工具来截取视频文件中的特定时间段,包括操作目的、实现思路、主要使用的API、源码示例以及在实际操作中可能遇到的问题和解决方法。
摘要由CSDN通过智能技术生成

目的

截取视频中的一段

思路

先是将源媒体文件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,
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值