iFrameExtractor地址:https://github.com/lajos/iFrameExtractor
ffmpeg的简介
FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。
“FFmpeg”这个单词中的”FF”指的是”Fast Forward”。
ffmpeg支持的格式
ASF
AVI
BFI
FLV
GXF, General eXchange Format, SMPTE 360M
IFF
RL2
ISO base media file format(包括QuickTime, 3GP和MP4)
Matroska(包括WebM)
Maxis XA
MPEG program stream
MPEG transport stream(including AVCHD)
MXF, Material eXchange Format, SMPTE 377M
MSN Webcam stream
Ogg
OMA
TXD
WTV
ffmpeg支持的协议
IETF标准:TCP, UDP, Gopher, HTTP, RTP, RTSP和SDP
苹果公司的相关标准:HTTP Live Streaming
RealMedia的相关标准:RealMedia RTSP/RDT
Adobe的相关标准:RTMP, RTMPT(由librtmp实现),RTMPE(由librtmp实现),RTMPTE(由librtmp)和RTMPS(由librtmp实现)
微软的相关标准:MMS在TCP上和MMS在HTTP上
iFrameExtractor的使用
初始化
1 2 3 4 |
self.video = [[VideoFrameExtractor alloc] initWithVideo:[Utilities bundlePath:@"sophie.mov"]]; video.outputWidth = 426; video.outputHeight = 320; |
播放
1 2 3 4 5 6 |
[video seekTime:0.0]; [NSTimer scheduledTimerWithTimeInterval:1.0/30 target:self selector:@selector(displayNextFrame:) userInfo:nil repeats:YES]; |
1 2 3 4 5 6 7 8 |
-(void)displayNextFrame:(NSTimer *)timer { if (![video stepFrame]) { return; } imageView.image = video.currentImage; } |
VideoFrameExtractor类解析
initWithVideo:(NSString *)moviePath方法
VideoFrameExtractor的初始化,主要是配置三个全局的结构体变量。
AVFormatContext类型的pFormatCtx,AVFormatContext主要存储视音频封装格式中包含的信息;AVInputFormat存储输入视音频使用的封装格式。每种视音频封装格式都对应一个AVInputFormat 结构。
AVCodecContext类型的pCodecCtx ,每个AVStream存储一个视频/音频流的相关数据;每个AVStream对应一个AVCodecContext,存储该视频/音频流使用解码方式的相关数据;每个AVCodecContext中对应一个AVCodec,包含该视频/音频对应的解码器。每种解码器都对应一个AVCodec结构。
AVFrame类型的pFrame,视频的话,每个结构一般是存一帧,音频可能有好几帧。解码前数据是AVPacket,解码后数据是AVFrame。
FMPEG中结构体很多。最关键的结构体他们之间的对应关系如下所示:
图片来自:FFMPEG中最关键的结构体之间的关系
下面就是初始化的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
-(id)initWithVideo:(NSString *)moviePath { if (!(self=[super init])) return nil; AVCodec *pCodec; // Register all formats and codecs avcodec_register_all(); av_register_all(); // Open video file if(avformat_open_input(&pFormatCtx, [moviePath cStringUsingEncoding:NSASCIIStringEncoding], NULL, NULL) != 0) { av_log(NULL, AV_LOG_ERROR, "Couldn't open file\n"); goto initError; } // Retrieve stream information if(avformat_find_stream_info(pFormatCtx,NULL) < 0) { av_log(NULL, AV_LOG_ERROR, "Couldn't find stream information\n"); goto initError; } // Find the first vidcrayon-sy">; } // Find the first vid 套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。
“FFmpeg”这个单词中的”FF”指的是”Fast Forward”。 ffmpeg支持的格式ASF AVI BFI FLV GXF, General eXchange Format, SMPTE 360M IFF RL2 ISO base media file format(包括QuickTime, 3GP和MP4) Matroska(包括WebM) Maxis XA MPEG program stream MPEG transport stream(including AVCHD) MXF, Material eXchange Format, SMPTE 377M MSN Webcam stream Ogg OMA TXD WTV ffmpeg支持的协议IETF标准:TCP, UDP, Gopher, HTTP, RTP, RTSP和SDP 苹果公司的相关标准:HTTP Live Streaming RealMedia的相关标准:RealMedia RTSP/RDT Adobe的相关标准:RTMP, RTMPT(由librtmp实现),RTMPE(由librtmp实现),RTMPTE(由librtmp)和RTMPS(由librtmp实现) 微软的相关标准:MMS在TCP上和MMS在HTTP上 iFrameExtractor的使用初始化
播放
VideoFrameExtractor类解析initWithVideo:(NSString *)moviePath方法VideoFrameExtractor的初始化,主要是配置三个全局的结构体变量。 AVFormatContext类型的pFormatCtx,AVFormatContext主要存储视音频封装格式中包含的信息;AVInputFormat存储输入视音频使用的封装格式。每种视音频封装格式都对应一个AVInputFormat 结构。 AVCodecContext类型的pCodecCtx ,每个AVStream存储一个视频/音频流的相关数据;每个AVStream对应一个AVCodecContext,存储该视频/音频流使用解码方式的相关数据;每个AVCodecContext中对应一个AVCodec,包含该视频/音频对应的解码器。每种解码器都对应一个AVCodec结构。 AVFrame类型的pFrame,视频的话,每个结构一般是存一帧,音频可能有好几帧。解码前数据是AVPacket,解码后数据是AVFrame。 FMPEG中结构体很多。最关键的结构体他们之间的对应关系如下所示:
图片来自:FFMPEG中最关键的结构体之间的关系 下面就是初始化的代码
|