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