[FFmpeg-devel] [PATCH] avformat: add H264 and HEVC support in IVF muxer
James Almer
jamrial at gmail.com
Sun Sep 30 22:53:52 EEST 2018
On 9/28/2018 3:51 PM, alx.sukhanov at gmail.com wrote:
> From: Alex Sukhanov <asukhanov at google.com>
>
> ---
> libavformat/ivfenc.c | 41 ++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 36 insertions(+), 5 deletions(-)
>
> diff --git a/libavformat/ivfenc.c b/libavformat/ivfenc.c
> index 66441a2a43..68c36daf09 100644
> --- a/libavformat/ivfenc.c
> +++ b/libavformat/ivfenc.c
> @@ -38,17 +38,35 @@ static int ivf_write_header(AVFormatContext *s)
> par = s->streams[0]->codecpar;
> if (par->codec_type != AVMEDIA_TYPE_VIDEO ||
> !(par->codec_id == AV_CODEC_ID_AV1 ||
> + par->codec_id == AV_CODEC_ID_H264 ||
> + par->codec_id == AV_CODEC_ID_HEVC ||
> par->codec_id == AV_CODEC_ID_VP8 ||
> par->codec_id == AV_CODEC_ID_VP9)) {
> - av_log(s, AV_LOG_ERROR, "Currently only VP8, VP9 and AV1 are supported!\n");
> + av_log(s, AV_LOG_ERROR, "Currently only AV1, H264, HEVC, VP8 and VP9 and AV1 are supported!\n");
> return AVERROR(EINVAL);
> }
> avio_write(pb, "DKIF", 4);
> avio_wl16(pb, 0); // version
> avio_wl16(pb, 32); // header length
> - avio_wl32(pb,
> - par->codec_id == AV_CODEC_ID_VP9 ? AV_RL32("VP90") :
> - par->codec_id == AV_CODEC_ID_VP8 ? AV_RL32("VP80") : AV_RL32("AV01"));
> + switch (par->codec_id) {
> + case AV_CODEC_ID_AV1:
> + avio_wl32(pb, AV_RL32("AV01"));
> + break;
> + case AV_CODEC_ID_H264:
> + avio_wl32(pb, AV_RL32("H264"));
> + break;
> + case AV_CODEC_ID_HEVC:
> + avio_wl32(pb, AV_RL32("HEVC"));
> + break;
> + case AV_CODEC_ID_VP8:
> + avio_wl32(pb, AV_RL32("VP80"));
> + break;
> + case AV_CODEC_ID_VP9:
> + avio_wl32(pb, AV_RL32("VP90"));
> + break;
> + default:
> + break;
> + }
> avio_wl16(pb, par->width);
> avio_wl16(pb, par->height);
> avio_wl32(pb, s->streams[0]->time_base.den);
> @@ -95,8 +113,21 @@ static int ivf_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
> int ret = 1;
> AVStream *st = s->streams[pkt->stream_index];
>
> - if (st->codecpar->codec_id == AV_CODEC_ID_VP9)
> + if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
> + if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
> + (AV_RB24(pkt->data) != 0x000001 ||
> + (st->codecpar->extradata_size > 0 &&
> + st->codecpar->extradata[0] == 1)))
> + ret = ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL);
> + } else if (st->codecpar->codec_id == AV_CODEC_ID_HEVC) {
> + if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
> + (AV_RB24(pkt->data) != 0x000001 ||
> + (st->codecpar->extradata_size > 0 &&
> + st->codecpar->extradata[0] == 1)))
> + ret = ff_stream_add_bitstream_filter(st, "hevc_mp4toannexb", NULL);
> + } else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) {
> ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", NULL);
> + }
>
> return ret;
> }
>
This is missing adding the new codec tags to codec_ivf_tags[] at the end
of the file.
More information about the ffmpeg-devel
mailing list