基于ffmpeg-2.2.2,添加FLV的HEVC格式,patch:
diff -r -p -C 3 ffmpeg-2.2.2/libavformat/flvdec.c orignal/ffmpeg-2.2.2/libavformat/flvdec.c *** ffmpeg-2.2.2/libavformat/flvdec.c 2014-06-02 10:22:35.755356970 +0800
--- orignal/ffmpeg-2.2.2/libavformat/flvdec.c 2014-05-05 12:14:30.000000000 +0800
*************** static int flv_same_video_codec(AVCodecC
*** 217,224 ****
return vcodec->codec_id == AV_CODEC_ID_VP6A;
case FLV_CODECID_H264:
return vcodec->codec_id == AV_CODEC_ID_H264;
- case FLV_CODECID_HEVC:
- return vcodec->codec_id == AV_CODEC_ID_HEVC;
default:
return vcodec->codec_tag == flv_codecid;
}
--- 217,222 ----
*************** static int flv_set_video_codec(AVFormatC
*** 263,272 ****
case FLV_CODECID_MPEG4:
vcodec->codec_id = AV_CODEC_ID_MPEG4;
return 3;
- case FLV_CODECID_HEVC:
- vcodec->codec_id = AV_CODEC_ID_HEVC;
- vstream->need_parsing = AVSTREAM_PARSE_HEADERS;
- return 3; // not 4, reading packet type will consume one byte
default:
avpriv_request_sample(s, "Video codec (%x)", flv_codecid);
vcodec->codec_tag = flv_codecid;
--- 261,266 ----
*************** retry_duration:
*** 933,944 ****
if (st->codec->codec_id == AV_CODEC_ID_AAC ||
st->codec->codec_id == AV_CODEC_ID_H264 ||
! st->codec->codec_id == AV_CODEC_ID_MPEG4 ||
! st->codec->codec_id == AV_CODEC_ID_HEVC) {
int type = avio_r8(s->pb);
size--;
! if (st->codec->codec_id == AV_CODEC_ID_H264 || st->codec->codec_id == AV_CODEC_ID_MPEG4 ||
! st->codec->codec_id == AV_CODEC_ID_HEVC) {
// sign extension
int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000;
pts = dts + cts;
--- 927,936 ----
if (st->codec->codec_id == AV_CODEC_ID_AAC ||
st->codec->codec_id == AV_CODEC_ID_H264 ||
! st->codec->codec_id == AV_CODEC_ID_MPEG4) {
int type = avio_r8(s->pb);
size--;
! if (st->codec->codec_id == AV_CODEC_ID_H264 || st->codec->codec_id == AV_CODEC_ID_MPEG4) {
// sign extension
int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000;
pts = dts + cts;
diff -r -p -C 3 ffmpeg-2.2.2/libavformat/flvenc.c orignal/ffmpeg-2.2.2/libavformat/flvenc.c
*** ffmpeg-2.2.2/libavformat/flvenc.c 2014-06-02 09:55:17.383782326 +0800
--- orignal/ffmpeg-2.2.2/libavformat/flvenc.c 2014-05-05 12:14:30.000000000 +0800
***************
*** 28,34 ****
#include "flv.h"
#include "internal.h"
#include "metadata.h"
- #include "hevc.h"
static const AVCodecTag flv_video_codec_ids[] = {
--- 28,33 ----
*************** static const AVCodecTag flv_video_codec_
*** 41,47 ****
{ AV_CODEC_ID_VP6, FLV_CODECID_VP6 },
{ AV_CODEC_ID_VP6A, FLV_CODECID_VP6A },
{ AV_CODEC_ID_H264, FLV_CODECID_H264 },
- { AV_CODEC_ID_HEVC, FLV_CODECID_HEVC },
{ AV_CODEC_ID_NONE, 0 }
};
--- 40,45 ----
*************** static int flv_write_header(AVFormatCont
*** 391,398 ****
for (i = 0; i < s->nb_streams; i++) {
AVCodecContext *enc = s->streams[i]->codec;
! if (enc->codec_id == AV_CODEC_ID_AAC || enc->codec_id == AV_CODEC_ID_H264 ||
! enc->codec_id == AV_CODEC_ID_MPEG4 || enc->codec_id == AV_CODEC_ID_HEVC) {
int64_t pos;
avio_w8(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ?
FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO);
--- 389,395 ----
for (i = 0; i < s->nb_streams; i++) {
AVCodecContext *enc = s->streams[i]->codec;
! if (enc->codec_id == AV_CODEC_ID_AAC || enc->codec_id == AV_CODEC_ID_H264 || enc->codec_id == AV_CODEC_ID_MPEG4) {
int64_t pos;
avio_w8(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ?
FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO);
*************** static int flv_write_header(AVFormatCont
*** 409,418 ****
avio_w8(pb, enc->codec_tag | FLV_FRAME_KEY); // flags
avio_w8(pb, 0); // AVC sequence header
avio_wb24(pb, 0); // composition time
! if (enc->codec_id == AV_CODEC_ID_HEVC)
! ff_isom_write_hvcc(pb, enc->extradata, enc->extradata_size, 0);
! else
! ff_isom_write_avcc(pb, enc->extradata, enc->extradata_size);
}
data_size = avio_tell(pb) - pos;
avio_seek(pb, -data_size - 10, SEEK_CUR);
--- 406,412 ----
avio_w8(pb, enc->codec_tag | FLV_FRAME_KEY); // flags
avio_w8(pb, 0); // AVC sequence header
avio_wb24(pb, 0); // composition time
! ff_isom_write_avcc(pb, enc->extradata, enc->extradata_size);
}
data_size = avio_tell(pb) - pos;
avio_seek(pb, -data_size - 10, SEEK_CUR);
*************** static int flv_write_trailer(AVFormatCon
*** 438,445 ****
AVCodecContext *enc = s->streams[i]->codec;
FLVStreamContext *sc = s->streams[i]->priv_data;
if (enc->codec_type == AVMEDIA_TYPE_VIDEO &&
! (enc->codec_id == AV_CODEC_ID_H264 || enc->codec_id == AV_CODEC_ID_MPEG4 ||
! enc->codec_id == AV_CODEC_ID_HEVC))
put_avc_eos_tag(pb, sc->last_ts);
}
--- 432,438 ----
AVCodecContext *enc = s->streams[i]->codec;
FLVStreamContext *sc = s->streams[i]->priv_data;
if (enc->codec_type == AVMEDIA_TYPE_VIDEO &&
! (enc->codec_id == AV_CODEC_ID_H264 || enc->codec_id == AV_CODEC_ID_MPEG4))
put_avc_eos_tag(pb, sc->last_ts);
}
*************** static int flv_write_packet(AVFormatCont
*** 473,480 ****
if (enc->codec_id == AV_CODEC_ID_VP6F || enc->codec_id == AV_CODEC_ID_VP6A ||
enc->codec_id == AV_CODEC_ID_VP6 || enc->codec_id == AV_CODEC_ID_AAC)
flags_size = 2;
! else if (enc->codec_id == AV_CODEC_ID_H264 || enc->codec_id == AV_CODEC_ID_MPEG4 ||
! enc->codec_id == AV_CODEC_ID_HEVC)
flags_size = 5;
else
flags_size = 1;
--- 466,472 ----
if (enc->codec_id == AV_CODEC_ID_VP6F || enc->codec_id == AV_CODEC_ID_VP6A ||
enc->codec_id == AV_CODEC_ID_VP6 || enc->codec_id == AV_CODEC_ID_AAC)
flags_size = 2;
! else if (enc->codec_id == AV_CODEC_ID_H264 || enc->codec_id == AV_CODEC_ID_MPEG4)
flags_size = 5;
else
flags_size = 1;
*************** static int flv_write_packet(AVFormatCont
*** 512,521 ****
if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1)
if ((ret = ff_avc_parse_nal_units_buf(pkt->data, &data, &size)) < 0)
return ret;
- } else if (enc->codec_id == AV_CODEC_ID_HEVC) {
- if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1)
- if ((ret = ff_hevc_annexb2mp4_buf(pkt->data, &data, &size, 0, NULL)) < 0)
- return ret;
} else if (enc->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 &&
(AV_RB16(pkt->data) & 0xfff0) == 0xfff0) {
if (!s->streams[pkt->stream_index]->nb_frames) {
--- 504,509 ----
*************** static int flv_write_packet(AVFormatCont
*** 586,593 ****
(FFALIGN(enc->height, 16) - enc->height));
} else if (enc->codec_id == AV_CODEC_ID_AAC)
avio_w8(pb, 1); // AAC raw
! else if (enc->codec_id == AV_CODEC_ID_H264 || enc->codec_id == AV_CODEC_ID_MPEG4 ||
! enc->codec_id == AV_CODEC_ID_HEVC) {
avio_w8(pb, 1); // AVC NALU
avio_wb24(pb, pkt->pts - pkt->dts);
}
--- 574,580 ----
(FFALIGN(enc->height, 16) - enc->height));
} else if (enc->codec_id == AV_CODEC_ID_AAC)
avio_w8(pb, 1); // AAC raw
! else if (enc->codec_id == AV_CODEC_ID_H264 || enc->codec_id == AV_CODEC_ID_MPEG4) {
avio_w8(pb, 1); // AVC NALU
avio_wb24(pb, pkt->pts - pkt->dts);
}
diff -r -p -C 3 ffmpeg-2.2.2/libavformat/flv.h orignal/ffmpeg-2.2.2/libavformat/flv.h
*** ffmpeg-2.2.2/libavformat/flv.h 2014-06-01 21:14:09.879856014 +0800
--- orignal/ffmpeg-2.2.2/libavformat/flv.h 2014-03-24 06:07:53.000000000 +0800
*************** enum {
*** 109,115 ****
FLV_CODECID_H264 = 7,
FLV_CODECID_REALH263= 8,
FLV_CODECID_MPEG4 = 9,
- FLV_CODECID_HEVC = 12,
};
enum {
--- 109,114 ----
阅读(4044) | 评论(3) | 转发(0) |