filmstripenc.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Adobe Filmstrip muxer
  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 muxer
  24. */
  25. #include "libavutil/intreadwrite.h"
  26. #include "avformat.h"
  27. #define RAND_TAG MKBETAG('R','a','n','d')
  28. typedef struct {
  29. int nb_frames;
  30. } FilmstripMuxContext;
  31. static int write_header(AVFormatContext *s)
  32. {
  33. if (s->streams[0]->codec->pix_fmt != PIX_FMT_RGBA) {
  34. av_log(s, AV_LOG_ERROR, "only PIX_FMT_RGBA is supported\n");
  35. return AVERROR_INVALIDDATA;
  36. }
  37. return 0;
  38. }
  39. static int write_packet(AVFormatContext *s, AVPacket *pkt)
  40. {
  41. FilmstripMuxContext *film = s->priv_data;
  42. avio_write(s->pb, pkt->data, pkt->size);
  43. film->nb_frames++;
  44. return 0;
  45. }
  46. static int write_trailer(AVFormatContext *s)
  47. {
  48. FilmstripMuxContext *film = s->priv_data;
  49. AVIOContext *pb = s->pb;
  50. AVStream *st = s->streams[0];
  51. int i;
  52. avio_wb32(pb, RAND_TAG);
  53. avio_wb32(pb, film->nb_frames);
  54. avio_wb16(pb, 0); // packing method
  55. avio_wb16(pb, 0); // reserved
  56. avio_wb16(pb, st->codec->width);
  57. avio_wb16(pb, st->codec->height);
  58. avio_wb16(pb, 0); // leading
  59. avio_wb16(pb, 1/av_q2d(st->codec->time_base));
  60. for (i = 0; i < 16; i++)
  61. avio_w8(pb, 0x00); // reserved
  62. avio_flush(pb);
  63. return 0;
  64. }
  65. AVOutputFormat ff_filmstrip_muxer = {
  66. .name = "filmstrip",
  67. .long_name = NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
  68. .extensions = "flm",
  69. .priv_data_size = sizeof(FilmstripMuxContext),
  70. .audio_codec = CODEC_ID_NONE,
  71. .video_codec = CODEC_ID_RAWVIDEO,
  72. .write_header = write_header,
  73. .write_packet = write_packet,
  74. .write_trailer = write_trailer,
  75. };