vc1testenc.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * VC-1 test bitstreams format muxer.
  3. * Copyright (c) 2008 Konstantin Shishkov
  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. #include "avformat.h"
  22. typedef struct RCVContext {
  23. int frames;
  24. } RCVContext;
  25. static int vc1test_write_header(AVFormatContext *s)
  26. {
  27. AVCodecContext *avc = s->streams[0]->codec;
  28. ByteIOContext *pb = s->pb;
  29. if (avc->codec_id != CODEC_ID_WMV3) {
  30. av_log(s, AV_LOG_ERROR, "Only WMV3 is accepted!\n");
  31. return -1;
  32. }
  33. put_le24(pb, 0); //frames count will be here
  34. put_byte(pb, 0xC5);
  35. put_le32(pb, 4);
  36. put_buffer(pb, avc->extradata, 4);
  37. put_le32(pb, avc->height);
  38. put_le32(pb, avc->width);
  39. put_le32(pb, 0xC);
  40. put_le24(pb, 0); // hrd_buffer
  41. put_byte(pb, 0x80); // level|cbr|res1
  42. put_le32(pb, 0); // hrd_rate
  43. if (s->streams[0]->r_frame_rate.den && s->streams[0]->r_frame_rate.num == 1)
  44. put_le32(pb, s->streams[0]->r_frame_rate.den);
  45. else
  46. put_le32(pb, 0xFFFFFFFF); //variable framerate
  47. return 0;
  48. }
  49. static int vc1test_write_packet(AVFormatContext *s, AVPacket *pkt)
  50. {
  51. RCVContext *ctx = s->priv_data;
  52. ByteIOContext *pb = s->pb;
  53. if (!pkt->size)
  54. return 0;
  55. put_le32(pb, pkt->size | ((pkt->flags & PKT_FLAG_KEY) ? 0x80000000 : 0));
  56. put_le32(pb, pkt->pts);
  57. put_buffer(pb, pkt->data, pkt->size);
  58. put_flush_packet(pb);
  59. ctx->frames++;
  60. return 0;
  61. }
  62. static int vc1test_write_trailer(AVFormatContext *s)
  63. {
  64. RCVContext *ctx = s->priv_data;
  65. ByteIOContext *pb = s->pb;
  66. if (!url_is_streamed(s->pb)) {
  67. url_fseek(pb, 0, SEEK_SET);
  68. put_le24(pb, ctx->frames);
  69. put_flush_packet(pb);
  70. }
  71. return 0;
  72. }
  73. AVOutputFormat vc1t_muxer = {
  74. "rcv",
  75. NULL_IF_CONFIG_SMALL("VC-1 test bitstream"),
  76. "",
  77. "rcv",
  78. sizeof(RCVContext),
  79. CODEC_ID_NONE,
  80. CODEC_ID_WMV3,
  81. vc1test_write_header,
  82. vc1test_write_packet,
  83. vc1test_write_trailer,
  84. };