iv8.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 = av_new_stream(s, 0);
  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;
  49. retry:
  50. type= avio_rb16(s->pb); // 257 or 258
  51. size= avio_rb16(s->pb);
  52. avio_rb16(s->pb); //some flags, 0x80 indicates end of frame
  53. avio_rb16(s->pb); //packet number
  54. pts=avio_rb32(s->pb);
  55. avio_rb32(s->pb); //6A 13 E3 88
  56. size -= 12;
  57. if(size<1)
  58. return -1;
  59. if(type==258){
  60. avio_skip(s->pb, size);
  61. goto retry;
  62. }
  63. ret= av_get_packet(s->pb, pkt, size);
  64. pkt->pts= pts;
  65. pkt->pos-=16;
  66. pkt->stream_index = 0;
  67. return ret;
  68. }
  69. AVInputFormat ff_iv8_demuxer = {
  70. .name = "iv8",
  71. .long_name = NULL_IF_CONFIG_SMALL("A format generated by IndigoVision 8000 video server"),
  72. .read_probe = probe,
  73. .read_header = read_header,
  74. .read_packet = read_packet,
  75. .flags= AVFMT_GENERIC_INDEX,
  76. .value = CODEC_ID_MPEG4,
  77. };