ivfdec.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2010 David Conrad
  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 "riff.h"
  22. #include "libavutil/intreadwrite.h"
  23. static int probe(AVProbeData *p)
  24. {
  25. if (AV_RL32(p->buf) == MKTAG('D','K','I','F')
  26. && !AV_RL16(p->buf+4) && AV_RL16(p->buf+6) == 32)
  27. return AVPROBE_SCORE_MAX-2;
  28. return 0;
  29. }
  30. static int read_header(AVFormatContext *s, AVFormatParameters *ap)
  31. {
  32. AVStream *st;
  33. AVRational time_base;
  34. avio_rl32(s->pb); // DKIF
  35. avio_rl16(s->pb); // version
  36. avio_rl16(s->pb); // header size
  37. st = av_new_stream(s, 0);
  38. if (!st)
  39. return AVERROR(ENOMEM);
  40. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  41. st->codec->codec_tag = avio_rl32(s->pb);
  42. st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codec->codec_tag);
  43. st->codec->width = avio_rl16(s->pb);
  44. st->codec->height = avio_rl16(s->pb);
  45. time_base.den = avio_rl32(s->pb);
  46. time_base.num = avio_rl32(s->pb);
  47. st->duration = avio_rl64(s->pb);
  48. st->need_parsing = AVSTREAM_PARSE_HEADERS;
  49. if (!time_base.den || !time_base.num) {
  50. av_log(s, AV_LOG_ERROR, "Invalid frame rate\n");
  51. return AVERROR_INVALIDDATA;
  52. }
  53. av_set_pts_info(st, 64, time_base.num, time_base.den);
  54. return 0;
  55. }
  56. static int read_packet(AVFormatContext *s, AVPacket *pkt)
  57. {
  58. int ret, size = avio_rl32(s->pb);
  59. int64_t pts = avio_rl64(s->pb);
  60. ret = av_get_packet(s->pb, pkt, size);
  61. pkt->stream_index = 0;
  62. pkt->pts = pts;
  63. pkt->pos -= 12;
  64. return ret;
  65. }
  66. AVInputFormat ff_ivf_demuxer = {
  67. "ivf",
  68. NULL_IF_CONFIG_SMALL("On2 IVF"),
  69. 0,
  70. probe,
  71. read_header,
  72. read_packet,
  73. .flags= AVFMT_GENERIC_INDEX,
  74. .codec_tag = (const AVCodecTag*[]){ff_codec_bmp_tags, 0},
  75. };