[FFmpeg-devel] [PATCH] avformat: add H264 and HEVC support in IVF muxer

Alex Sukhanov alx.sukhanov at gmail.com
Thu Oct 11 22:58:22 EEST 2018


On Sat, Oct 6, 2018 at 10:37 AM Mark Thompson <sw at jkqxz.net> wrote:

> On 05/10/18 21:45, Alex Sukhanov wrote:
> > On Mon, Oct 1, 2018 at 11:01 AM <alx.sukhanov at gmail.com> wrote:
> >
> >> From: Alex Sukhanov <asukhanov at google.com>
> >>
> >> ---
> >>  libavformat/ivfenc.c | 50 +++++++++++++++++++++++++++++++++-----------
> >>  1 file changed, 38 insertions(+), 12 deletions(-)
> >>
> >> diff --git a/libavformat/ivfenc.c b/libavformat/ivfenc.c
> >> index 66441a2a43..6410828533 100644
> >> --- a/libavformat/ivfenc.c
> >> +++ b/libavformat/ivfenc.c
> >> @@ -36,19 +36,29 @@ static int ivf_write_header(AVFormatContext *s)
> >>          return AVERROR(EINVAL);
> >>      }
> >>      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_VP8 ||
> >> -          par->codec_id == AV_CODEC_ID_VP9)) {
> >> -        av_log(s, AV_LOG_ERROR, "Currently only VP8, 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:
> >> +        av_log(s, AV_LOG_ERROR, "Currently only AV1, H264, HEVC, VP8
> and
> >> VP9 and AV1 are supported!\n");
> >> +        return AVERROR(EINVAL);
> >> +    }
> >>      avio_wl16(pb, par->width);
> >>      avio_wl16(pb, par->height);
> >>      avio_wl32(pb, s->streams[0]->time_base.den);
> >> @@ -95,16 +105,32 @@ 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;
> >>  }
> >>
> >>  static const AVCodecTag codec_ivf_tags[] = {
> >> +    { AV_CODEC_ID_AV1,  MKTAG('A', 'V', '0', '1') },
> >> +    { AV_CODEC_ID_H264, MKTAG('H', '2', '6', '4') },
> >> +    { AV_CODEC_ID_HEVC, MKTAG('H', 'E', 'V', 'C') },
> >>      { AV_CODEC_ID_VP8,  MKTAG('V', 'P', '8', '0') },
> >>      { AV_CODEC_ID_VP9,  MKTAG('V', 'P', '9', '0') },
> >> -    { AV_CODEC_ID_AV1,  MKTAG('A', 'V', '0', '1') },
> >> +
> >>      { AV_CODEC_ID_NONE, 0 }
> >>  };
> >>
> >> --
> >> 2.19.0.605.g01d371f741-goog
> >>
> >>
> > Can you please take a look on this patch?
>
> Can you answer the question posed in <
> https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2018-September/234655.html>
> about the reasoning for this patch?
>
> In particular, it might be helpful if you could point out any
> tools/standards which support (or are in future intending to support) this
> format - in my experience pretty much everything dealing with H.26[45] raw
> streams uses the Annex B format.
>
> Thanks,
>
> - Mark
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Hi Mark,

at Google we have some old service which is still running and it works only
with the IVF container. It would be great if ffmpeg could generate such
videos so we could give them to the service then. Given that ffmpeg IVF
demuxer already supports reading such files, I think it's reasonable to
make IVF muxer be able to generate them.
Hope it answers the question.

Thank you


More information about the ffmpeg-devel mailing list