ffmpeg分析系列之三(输入输出格式)
来源:互联网 发布:阿里云服务器客服电话 编辑:程序博客网 时间:2024/05/16 07:18
/** This structure contains the data a format has to probe a file. */
typedef struct AVProbeData {
const char *filename;
unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
int buf_size; /**< Size of buf except extra allocated bytes */
} AVProbeData;
static int h264_probe(AVProbeData *p)
{
uint32_t code= -1;
int sps=0, pps=0, idr=0, res=0, sli=0;
int i;
for(i=0; i<p->buf_size; i++){
code = (code<<8) + p->buf[i];
if ((code & 0xffffff00) == 0x100) {
int ref_idc= (code>>5)&3;
int type = code & 0x1F;
static const int8_t ref_zero[32]={
2, 0, 0, 0, 0,-1, 1,-1,
-1, 1, 1, 1, 1,-1, 2, 2,
2, 2, 2, 0, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2
};
if(code & 0x80) //forbidden bit
return 0;
if(ref_zero[type] == 1 && ref_idc)
return 0;
if(ref_zero[type] ==-1 && !ref_idc)
return 0;
if(ref_zero[type] == 2)
res++;
switch(type){
case 1: sli++; break;
case 5: idr++; break;
case 7:
if(p->buf[i+2]&0x0F)
return 0;
sps++;
break;
case 8: pps++; break;
}
}
}
if(sps && pps && (idr||sli>3) && res<(sps+pps+idr))
return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
return 0;
}
static int video_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
AVStream *st;
st = av_new_stream(s, 0);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = s->iformat->value;
st->need_parsing = AVSTREAM_PARSE_FULL;
/* for MJPEG, specify frame rate */
/* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/
if (ap->time_base.num) {
st->codec->time_base= ap->time_base;
} else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
st->codec->codec_id == CODEC_ID_MPEG4 ||
st->codec->codec_id == CODEC_ID_DIRAC ||
st->codec->codec_id == CODEC_ID_DNXHD ||
st->codec->codec_id == CODEC_ID_H264) {
st->codec->time_base= (AVRational){1,25};
}
av_set_pts_info(st, 64, 1, 1200000);
return 0;
}
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
{
int ret, size;
size = RAW_PACKET_SIZE;
if (av_new_packet(pkt, size) < 0)
return AVERROR(ENOMEM);
pkt->pos= url_ftell(s->pb);
pkt->stream_index = 0;
ret = get_partial_buffer(s->pb, pkt->data, size);
if (ret < 0) {
av_free_packet(pkt);
return ret;
}
pkt->size = ret;
return ret;
}
static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
{
put_buffer(s->pb, pkt->data, pkt->size);
put_flush_packet(s->pb);
return 0;
}
AVOutputFormat h264_muxer = {
"h264",
NULL_IF_CONFIG_SMALL("raw H.264 video format"),
NULL,
"h264",
0,
CODEC_ID_NONE,
CODEC_ID_H264,
NULL,
raw_write_packet,
.flags= AVFMT_NOTIMESTAMPS,
};
AVInputFormat h264_demuxer = {
"h264",
NULL_IF_CONFIG_SMALL("raw H.264 video format"),
0,
h264_probe,
video_read_header,
ff_raw_read_partial_packet,
.flags= AVFMT_GENERIC_INDEX,
.extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
.value = CODEC_ID_H264,
}
#define REGISTER_MUXER(X,x) { \
extern AVOutputFormat x##_muxer; \
if(CONFIG_##X##_MUXER) av_register_output_format(&x##_muxer); }
#define REGISTER_DEMUXER(X,x) { \
extern AVInputFormat x##_demuxer; \
if(CONFIG_##X##_DEMUXER) av_register_input_format(&x##_demuxer); }
#define REGISTER_MUXDEMUX(X,x) REGISTER_MUXER(X,x); REGISTER_DEMUXER(X,x)
void av_register_all(void)
{
/* 省略部分代码 */
/* protocols */
REGISTER_MUXDEMUX (H264, h264);
/* 省略部分代码 */
}
/** head of registered input format linked list */
AVInputFormat *first_iformat = NULL;
/** head of registered output format linked list */
AVOutputFormat *first_oformat = NULL;
void av_register_input_format(AVInputFormat *format)
{
AVInputFormat **p;
p = &first_iformat;
while (*p != NULL) p = &(*p)->next;
*p = format;
format->next = NULL;
}
void av_register_output_format(AVOutputFormat *format)
{
AVOutputFormat **p;
p = &first_oformat;
while (*p != NULL) p = &(*p)->next;
*p = format;
format->next = NULL;
}
- ffmpeg分析系列之三(输入输出格式)
- ffmpeg分析系列之三(输入输出格式)
- ffmpeg分析系列之三(输入输出格式)
- ffmpeg分析系列之四(探测输入的格式)
- ffmpeg分析系列之六(再次探测输入的格式)
- ffmpeg分析系列之四(探测输入的格式)
- ffmpeg分析系列之六(再次探测输入的格式)
- ffmpeg分析系列之四(探测输入的格式)
- ffmpeg分析系列之六(再次探测输入的格式)
- ffmpeg分析系列之六(再次探测输入的格式)
- FFMPEG之图片系列 --- png格式
- FFMPEG之图片系列 --- tif 格式
- 输入输出格式(三)
- 移植FFMPEG到VS2008系列之三
- ffmpeg分析系列之二(文件协议)
- ffmpeg分析系列之二(文件协议)
- ffmpeg分析系列之二(文件协议)
- ffmpeg分析系列之二(文件协议)
- c++ 纯虚函数
- Facebook接入(新)--iframe方式
- 社交网站用户的构成遵循1/9/90原则
- 值得推荐的免费网上课程
- 您的意见真的很重要!!!
- ffmpeg分析系列之三(输入输出格式)
- 利用Arguments对象模拟函数重载的例子
- Asp.net MVC 3 Razor视图引擎的使用(一)
- 发现新浪微博RSS源修改了,不显示全部内容了。。。
- 无需表格制作CSS菜单
- X Window 的设计原则 ( Design principles )
- cdecl、stdcall、fastcall函数调用约定区别
- Spring的使用Annotation以及XML进行声明式事务管理
- C# 单张图片的保存[BLOB保存与文件上传两种方式]与展示