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.

117 lines
3.4KB

  1. /*
  2. * Adobe Filmstrip demuxer
  3. * Copyright (c) 2010 Peter Ross
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * Adobe Filmstrip demuxer
  24. */
  25. #include "libavutil/intreadwrite.h"
  26. #include "avformat.h"
  27. #include "internal.h"
  28. #define RAND_TAG MKBETAG('R','a','n','d')
  29. typedef struct FilmstripDemuxContext {
  30. int leading;
  31. } FilmstripDemuxContext;
  32. static int read_header(AVFormatContext *s)
  33. {
  34. FilmstripDemuxContext *film = s->priv_data;
  35. AVIOContext *pb = s->pb;
  36. AVStream *st;
  37. if (!s->pb->seekable)
  38. return AVERROR(EIO);
  39. avio_seek(pb, avio_size(pb) - 36, SEEK_SET);
  40. if (avio_rb32(pb) != RAND_TAG) {
  41. av_log(s, AV_LOG_ERROR, "magic number not found\n");
  42. return AVERROR_INVALIDDATA;
  43. }
  44. st = avformat_new_stream(s, NULL);
  45. if (!st)
  46. return AVERROR(ENOMEM);
  47. st->nb_frames = avio_rb32(pb);
  48. if (avio_rb16(pb) != 0) {
  49. avpriv_request_sample(s, "Unsupported packing method");
  50. return AVERROR_PATCHWELCOME;
  51. }
  52. avio_skip(pb, 2);
  53. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  54. st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
  55. st->codec->pix_fmt = AV_PIX_FMT_RGBA;
  56. st->codec->codec_tag = 0; /* no fourcc */
  57. st->codec->width = avio_rb16(pb);
  58. st->codec->height = avio_rb16(pb);
  59. film->leading = avio_rb16(pb);
  60. if (st->codec->width * 4LL * st->codec->height >= INT_MAX) {
  61. av_log(s, AV_LOG_ERROR, "dimensions too large\n");
  62. return AVERROR_PATCHWELCOME;
  63. }
  64. avpriv_set_pts_info(st, 64, 1, avio_rb16(pb));
  65. avio_seek(pb, 0, SEEK_SET);
  66. return 0;
  67. }
  68. static int read_packet(AVFormatContext *s,
  69. AVPacket *pkt)
  70. {
  71. FilmstripDemuxContext *film = s->priv_data;
  72. AVStream *st = s->streams[0];
  73. if (avio_feof(s->pb))
  74. return AVERROR(EIO);
  75. pkt->dts = avio_tell(s->pb) / (st->codec->width * (int64_t)(st->codec->height + film->leading) * 4);
  76. pkt->size = av_get_packet(s->pb, pkt, st->codec->width * st->codec->height * 4);
  77. avio_skip(s->pb, st->codec->width * (int64_t) film->leading * 4);
  78. if (pkt->size < 0)
  79. return pkt->size;
  80. pkt->flags |= AV_PKT_FLAG_KEY;
  81. return 0;
  82. }
  83. static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
  84. {
  85. AVStream *st = s->streams[stream_index];
  86. if (avio_seek(s->pb, FFMAX(timestamp, 0) * st->codec->width * st->codec->height * 4, SEEK_SET) < 0)
  87. return -1;
  88. return 0;
  89. }
  90. AVInputFormat ff_filmstrip_demuxer = {
  91. .name = "filmstrip",
  92. .long_name = NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
  93. .priv_data_size = sizeof(FilmstripDemuxContext),
  94. .read_header = read_header,
  95. .read_packet = read_packet,
  96. .read_seek = read_seek,
  97. .extensions = "flm",
  98. };