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.

103 lines
2.7KB

  1. /*
  2. * MODS demuxer
  3. * Copyright (c) 2015-2016 Florian Nouwt
  4. * Copyright (c) 2017 Adib Surani
  5. * Copyright (c) 2020 Paul B Mahol
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include "libavutil/intreadwrite.h"
  24. #include "avformat.h"
  25. #include "internal.h"
  26. static int mods_probe(const AVProbeData *p)
  27. {
  28. if (memcmp(p->buf, "MODSN3\x0a\x00", 8))
  29. return 0;
  30. if (AV_RB32(p->buf + 8) == 0)
  31. return 0;
  32. if (AV_RB32(p->buf + 12) == 0)
  33. return 0;
  34. if (AV_RB32(p->buf + 16) == 0)
  35. return 0;
  36. return AVPROBE_SCORE_MAX;
  37. }
  38. static int mods_read_header(AVFormatContext *s)
  39. {
  40. AVIOContext *pb = s->pb;
  41. AVRational fps;
  42. int64_t pos;
  43. AVStream *st = avformat_new_stream(s, NULL);
  44. if (!st)
  45. return AVERROR(ENOMEM);
  46. avio_skip(pb, 8);
  47. st->nb_frames = avio_rl32(pb);
  48. st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
  49. st->codecpar->codec_id = AV_CODEC_ID_MOBICLIP;
  50. st->codecpar->width = avio_rl32(pb);
  51. st->codecpar->height = avio_rl32(pb);
  52. fps.num = avio_rl32(pb);
  53. fps.den = 0x1000000;
  54. avpriv_set_pts_info(st, 64, fps.den, fps.num);
  55. avio_skip(pb, 16);
  56. pos = avio_rl32(pb) + 4;
  57. avio_seek(pb, pos, SEEK_SET);
  58. pos = avio_rl32(pb);
  59. avio_seek(pb, pos, SEEK_SET);
  60. return 0;
  61. }
  62. static int mods_read_packet(AVFormatContext *s, AVPacket *pkt)
  63. {
  64. AVIOContext *pb = s->pb;
  65. unsigned size;
  66. int64_t pos;
  67. int ret;
  68. if (avio_feof(pb))
  69. return AVERROR_EOF;
  70. pos = avio_tell(pb);
  71. size = avio_rl32(pb) >> 14;
  72. ret = av_get_packet(pb, pkt, size);
  73. pkt->pos = pos;
  74. pkt->stream_index = 0;
  75. pkt->flags |= AV_PKT_FLAG_KEY;
  76. return ret;
  77. }
  78. AVInputFormat ff_mods_demuxer = {
  79. .name = "mods",
  80. .long_name = NULL_IF_CONFIG_SMALL("MobiClip MODS"),
  81. .read_probe = mods_probe,
  82. .read_header = mods_read_header,
  83. .read_packet = mods_read_packet,
  84. .extensions = "mods",
  85. .flags = AVFMT_GENERIC_INDEX,
  86. };