Chinaunix首页 | 论坛 | 博客
  • 博客访问: 170255
  • 博文数量: 60
  • 博客积分: 15
  • 博客等级: 民兵
  • 技术积分: 638
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-26 10:59
个人简介

喜欢coding,因为那是一件伟大的事情,是将无生命的IC赋予灵魂的过程,让我拥有了和上帝一样的成就感。(w1c2g3@163.com)

文章分类

全部博文(60)

文章存档

2017年(7)

2016年(41)

2015年(1)

2014年(4)

2013年(7)

我的朋友

分类: C/C++

2014-06-03 15:30:50

基于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) |
0

上一篇:mprotect

下一篇:USB Skeleton

给主人留下些什么吧!~~

youngalmond2014-11-24 15:48:14

大神,有空的话,希望能得到您的指导……谢谢!

youngalmond2014-11-24 15:38:17

我这样转了一个,用ffplay播的时候提示missing picture in access unit 等错误,倒是能播,感觉是头尾处理的不对,能指教下么?

youngalmond2014-11-21 16:22:53

请教下,楼主这样能成功么?