iv8.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (c) 2009 Michael Niedermayer
  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. static int probe(AVProbeData *p)
  23. {
  24. // the single file I have starts with that, I do not know if others do, too
  25. if( p->buf[0] == 1
  26. && p->buf[1] == 1
  27. && p->buf[2] == 3
  28. && p->buf[3] == 0xB8
  29. && p->buf[4] == 0x80
  30. && p->buf[5] == 0x60
  31. )
  32. return AVPROBE_SCORE_MAX-2;
  33. return 0;
  34. }
  35. static int read_header(AVFormatContext *s)
  36. {
  37. AVStream *st;
  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_id = AV_CODEC_ID_MPEG4;
  43. st->need_parsing = AVSTREAM_PARSE_FULL;
  44. avpriv_set_pts_info(st, 64, 1, 90000);
  45. return 0;
  46. }
  47. static int read_packet(AVFormatContext *s, AVPacket *pkt)
  48. {
  49. int ret, size, pts, type, flags;
  50. int first_pkt = 0;
  51. int frame_complete = 0;
  52. while (!frame_complete) {
  53. type = avio_rb16(s->pb); // 257 or 258
  54. size = avio_rb16(s->pb);
  55. flags = avio_rb16(s->pb); //some flags, 0x80 indicates end of frame
  56. avio_rb16(s->pb); //packet number
  57. pts = avio_rb32(s->pb);
  58. avio_rb32(s->pb); //6A 13 E3 88
  59. frame_complete = flags & 0x80;
  60. size -= 12;
  61. if (size < 1)
  62. return -1;
  63. if (type == 258) {
  64. avio_skip(s->pb, size);
  65. frame_complete = 0;
  66. continue;
  67. }
  68. if (!first_pkt) {
  69. ret = av_get_packet(s->pb, pkt, size);
  70. if (ret < 0)
  71. return ret;
  72. first_pkt = 1;
  73. pkt->pts = pts;
  74. pkt->pos -= 16;
  75. } else {
  76. ret = av_append_packet(s->pb, pkt, size);
  77. if (ret < 0) {
  78. av_log(s, AV_LOG_ERROR, "failed to grow packet\n");
  79. av_free_packet(pkt);
  80. return ret;
  81. }
  82. }
  83. if (ret < size) {
  84. av_log(s, AV_LOG_ERROR, "Truncated packet! Read %d of %d bytes\n",
  85. ret, size);
  86. pkt->flags |= AV_PKT_FLAG_CORRUPT;
  87. break;
  88. }
  89. }
  90. pkt->stream_index = 0;
  91. return 0;
  92. }
  93. AVInputFormat ff_iv8_demuxer = {
  94. .name = "iv8",
  95. .long_name = NULL_IF_CONFIG_SMALL("IndigoVision 8000 video"),
  96. .read_probe = probe,
  97. .read_header = read_header,
  98. .read_packet = read_packet,
  99. .flags = AVFMT_GENERIC_INDEX,
  100. };