ivfenc.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2010 Reimar Döffinger
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "avformat.h"
  21. #include "libavutil/intreadwrite.h"
  22. static int ivf_write_header(AVFormatContext *s)
  23. {
  24. AVCodecContext *ctx;
  25. AVIOContext *pb = s->pb;
  26. if (s->nb_streams != 1) {
  27. av_log(s, AV_LOG_ERROR, "Format supports only exactly one video stream\n");
  28. return AVERROR(EINVAL);
  29. }
  30. ctx = s->streams[0]->codec;
  31. if (ctx->codec_type != AVMEDIA_TYPE_VIDEO || ctx->codec_id != CODEC_ID_VP8) {
  32. av_log(s, AV_LOG_ERROR, "Currently only VP8 is supported!\n");
  33. return AVERROR(EINVAL);
  34. }
  35. avio_write(pb, "DKIF", 4);
  36. avio_wl16(pb, 0); // version
  37. avio_wl16(pb, 32); // header length
  38. avio_wl32(pb, ctx->codec_tag ? ctx->codec_tag : AV_RL32("VP80"));
  39. avio_wl16(pb, ctx->width);
  40. avio_wl16(pb, ctx->height);
  41. avio_wl32(pb, s->streams[0]->time_base.den);
  42. avio_wl32(pb, s->streams[0]->time_base.num);
  43. avio_wl64(pb, s->streams[0]->duration); // TODO: duration or number of frames?!?
  44. return 0;
  45. }
  46. static int ivf_write_packet(AVFormatContext *s, AVPacket *pkt)
  47. {
  48. AVIOContext *pb = s->pb;
  49. avio_wl32(pb, pkt->size);
  50. avio_wl64(pb, pkt->pts);
  51. avio_write(pb, pkt->data, pkt->size);
  52. avio_flush(pb);
  53. return 0;
  54. }
  55. AVOutputFormat ff_ivf_muxer = {
  56. .name = "ivf",
  57. .long_name = NULL_IF_CONFIG_SMALL("On2 IVF"),
  58. .extensions = "ivf",
  59. .audio_codec = CODEC_ID_NONE,
  60. .video_codec = CODEC_ID_VP8,
  61. .write_header = ivf_write_header,
  62. .write_packet = ivf_write_packet,
  63. };