You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.2KB

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