ffmpeg c接口

ffmpeg新版本很多接口发生了变化,因此在使用时需要确定自己的版本,在这里使用的版本为4.1.4。 

在此特别感谢雷博提供的相关文章:FFmpeg_雷霄骅的博客-优快云博客

  • ffmpeg视频解码

#include <iostream>
#include <stdio.h>
extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavformat/avio.h"
#include <libavutil/log.h>
#include <libavutil/timestamp.h>
}

#define ERROR_STR_SIZE 1024

int main() {
  
  int ret = -1;
  int err_code;
  char errors[ERROR_STR_SIZE];
  AVFormatContext *ifmt_ctx = NULL;
  AVCodecContext *pCodecCtx;
  const AVOutputFormat *ofmt = NULL;
  AVStream *in_stream1 = NULL;
  int vedio_stream_indes = 0;
  // 文件最大时长,保证音频和视频数据长度一致
  double max_duration = 0;
  AVPacket *pkt;
  int stream1 = 0, stream2 = 0;
  const char* video = "E:\\jiao\\project\\162300.mp4";
  /*//初始化网络,如果要解封装网络数据格式,则可调用该函数。
  avformat_network_init();*/
  //av_register_all();//高版本已弃用
  //打开输入文件(可解析视频参数)
  ifmt_ctx = avformat_alloc_context();
  if ((err_code = avformat_open_input(&ifmt_ctx, video, 0, 0)) != 0) {
    av_strerror(err_code, errors, ERROR_STR_SIZE);
    return -1;
  }
  if (avformat_find_stream_info(ifmt_ctx, NULL) < 0) {
    printf("Couldn't find stream information.\n");
    return -1;
  }

  // 找到视频流下标
  vedio_stream_indes = -1;
  for (int i = 0; i < ifmt_ctx->nb_streams; i++) {
    if (ifmt_ctx->streams[i]->codecpar->codec_type =&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值