FFmpeg使用问题汇总

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FFmpeg使用问题汇总相关的知识,希望对你有一定的参考价值。

参考技术A Invalid MIT-MAGIC-COOKIE-1 key[x11grab @ 0x5580691486e0] Cannot open display :0.0, error 1.

:0.0: Input/output error

echo $DISPLAY 查看设备代号 替换掉:0.0

参考:https://www.linuxquestions.org/questions/linux-desktop-74/ffmpeg-fails-cannot-open-display-0-0-error-1-a-4175613512/

FFMpeg SDK使用API汇总解析

avformat_alloc_output_context2

作用: 根据输出文件的格式获取AVFormatContext结构,获取AVFormatContext结构,封装的时候使用

int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat, const char *format_name, const char *filename);

参数:

  • ctx:输出到AVFormatContext结构的指针,如果函数失败则返回给该指针为NULL;
  • oformat:指定输出的AVOutputFormat类型,如果设为NULL则使用format_name和filename生成;
  • format_name:输出格式的名称,如果设为NULL则使用filename默认格式;
  • filename:目标文件名,如果不使用,可以设为NULL;
    注意: 2、3参数都设置为NULL,则使用默认

avformat_new_stream

作用: 根据AVCodec new一个AVStream,封装时使用

AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c);

参数:

  • s:AVFormatContext结构,表示要封装生成的视频文件;
  • c:上一步根据codec_id产生的编码器指针;

返回值: 指向生成的stream对象的指针;如果失败则返回NULL指针,并且会根据AVCodec自动分配AVCodecContext
注: avformat_new_stream调用之后s->nb_streams就会增加1,可以用此值表示唯一的流id

avio_open

作用: 打开封装格式的文件

int avio_open(AVIOContext **s, const char *url, int flags);

参数:

  • AVIOContext **s
  • url:文件名
  • flags:读写AVIO_FLAG_WRITE

av_compare_ts

作用: 比较两个流时间戳进度,用于音视频同步

int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b);

参数:

  • 1、3是时间戳

返回值:

  • -1 if ts_a is before ts_b
  • 1 if ts_a is after ts_b
  • 0 if they represent the same position

例子:
前面的与后面比,后面是1s一帧,并且第10帧,前面是1s 25fps,目前是第0帧

AVRational r1 = { 1, 25 };
AVRational r = { 1, 1 };
int64_t next_pts = 0;
if (av_compare_ts(next_pts, r1, 10, r) >= 0)
{
	return NULL;
}

以上是关于FFmpeg使用问题汇总的主要内容,如果未能解决你的问题,请参考以下文章

基于ffmpeg的视频处理汇总

FFmpeg编程博客汇总from: cnblogs - 山上有风景

FFMpeg SDK使用API汇总解析

FFmpeg功能命令汇总

FFmpeg学习博客汇总from: cnblogs - 山上有风景

FFmpeg功能命令汇总