[关闭]
@ltlovezh 2020-03-20T02:09:46.000000Z 字数 2320 阅读 2853

ffmpeg

ffmpeg


编译

支持命令行

libavformat

AVFormatContext

AVStream

libavcodec

AVCodecParameters

AVCodec

AVCodecContext

AVPacket

AVBitStreamFilter

libavutil

AVFrame

BitStreamFilter逻辑

AVBitStreamFilter

Register a bitstream filter
av_register_bitstream_filter

AVBSFContext

channel <-> channel_layout

av_get_default_channel_layout : 根据channel个数,获取默认的channel_layout(uint64_t)

av_get_channel_layout_nb_channels : 根据channel_layout(uint64_t)获取对应的channel数。

模块

  1. libswresample : 音频重采样、采样格式变换
  2. libswscale : 视频格式、Size等变换

常用命令

  1. ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}

编码

  1. ffmpeg -s 1280*720 -pix_fmt nv12 -i output-nv12.yuv -b:v 2000k -vcodec libx264 output-2000.h264

对NV12格式的YUV数据,进行H264编码。

解码

  1. //解码为yuv420p
  2. ffmpeg -i output.h264 [-pix_fmt yuv420p] output.yuv
  3. //解码为rgb24
  4. ffmpeg -i output.h264 [-pix_fmt rgb24] output.yuv

-pix_fmt指定解码的格式,默认为yuv420p。

格式转换

  1. ffmpeg -s 1920x1080 -pix_fmt rgb24 -i origin.rgb -s 1920x1080 -pix_fmt yuv420p origin.yuv

通过FFmpeg可以进行RGB和YUV、YUV和YUV等格式的转换。

截取视频帧

  1. //截取一定时间内的视频帧
  2. ffmpeg -s 1920x1080 -pix_fmt yuv420p -i origin-500-libyuv.yuv -ss 5 -t 10 out.yuv
  3. //截取指定的帧数
  4. ffmpeg -s 1920x1080 -pix_fmt yuv420p -i origin.yuv -ss 5 -vframes 100 out.yuv
  5. //截取某一帧,保存成图片
  6. ffmpeg -s 1920x1080 -pix_fmt yuv420p -i origin.yuv -ss 5 -vframes 1 out.jpg
  7. //把视频帧,拆分成图片
  8. ffmpeg -s 1920x1080 -pix_fmt yuv420p -i origin.yuv %04d.jpg
  9. //从第10秒开始,以每秒截取1张图片的速度,截取5秒时长的图片
  10. ffmpeg -i origin.mp4 -r 1 -ss 00:00:10 -t 00:00:05 images%04d.jpg

-ss表示开始时间,-t表示需要截取的时长,-r表示fps,-vframes表示截取的帧数

修改视频帧尺寸

  1. //把1920*1080的YUV转成到1280*720的YUV
  2. ffmpeg -s:v 1920x1080 -i origin.yuv -vf scale=1280:720 -c:v rawvideo -pix_fmt yuv420p output.yuv

ffplay

播放原始数据

  1. ffplay -i leon.rgb -pixel_format rgb24 -video_size 720x1280
  1. typedef struct AVStream {
  2. /** stream index in AVFormatContext */
  3. int index;
  4. } AVStream;
  1. enum AVMediaType {
  2. AVMEDIA_TYPE_UNKNOWN = -1,
  3. AVMEDIA_TYPE_VIDEO, // 视频流
  4. AVMEDIA_TYPE_AUDIO, // 音频流
  5. AVMEDIA_TYPE_DATA,
  6. AVMEDIA_TYPE_SUBTITLE, // 字幕流
  7. AVMEDIA_TYPE_ATTACHMENT,
  8. AVMEDIA_TYPE_NB
  9. };
  10. typedef struct AVCodecParameters {
  11. /**
  12. * General type of the encoded data.
  13. * 流类型
  14. */
  15. enum AVMediaType codec_type;
  16. /**
  17. * Specific type of the encoded data (the codec used).
  18. * 流编码类型,H264是AV_CODEC_ID_H264,H265是AV_CODEC_ID_HEVC或者AV_CODEC_ID_H265
  19. */
  20. enum AVCodecID codec_id;
  21. /**
  22. * 有关编解码器的附加信息,可以通过宏:av_fourcc_make_string转换为四字母字符串,例 * 如:avc1、mp4a
  23. */
  24. uint32_t codec_tag;
  25. } AVCodecParameters;

ffmpeg编译

  1. FFMPEG - MAC编译指南
  2. Mac OS X编译ffmpeg
  3. 官方文档
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注