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.

102 lines
2.9KB

  1. /*
  2. * MXF muxer
  3. * Copyright (c) 2008 GUCAS, Zhentan Feng <spyfeng at gmail dot com>
  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. * References
  23. * SMPTE 336M KLV Data Encoding Protocol Using Key-Length-Value
  24. * SMPTE 377M MXF File Format Specifications
  25. * SMPTE 379M MXF Generic Container
  26. * SMPTE 381M Mapping MPEG Streams into the MXF Generic Container
  27. * SMPTE RP210: SMPTE Metadata Dictionary
  28. * SMPTE RP224: Registry of SMPTE Universal Labels
  29. */
  30. //#define DEBUG
  31. static const MXFCodecUL *mxf_get_essence_container_ul(enum CodecID type)
  32. {
  33. const MXFCodecUL *uls = mxf_essence_container_uls;
  34. while (uls->id != CODEC_ID_NONE) {
  35. if (uls->id == type)
  36. break;
  37. uls++;
  38. }
  39. return uls;
  40. }
  41. static void mxf_free(AVFormatContext *s)
  42. {
  43. MXFContext *mxf = s->priv_data;
  44. AVStream *st;
  45. int i;
  46. av_freep(&mxf->reference.identification);
  47. av_freep(mxf->reference.package);
  48. av_freep(&mxf->reference.package);
  49. av_freep(&mxf->reference.content_storage);
  50. for (i = 0; i < s->nb_streams; i++) {
  51. st = s->streams[i];
  52. av_freep(&st->priv_data);
  53. }
  54. av_freep(mxf->reference.sub_desc);
  55. av_freep(&mxf->reference.sub_desc);
  56. av_freep(&mxf->reference.mul_desc);
  57. av_freep(&mxf->essence_container_uls);
  58. }
  59. static const MXFDataDefinitionUL *mxf_get_data_definition_ul(enum CodecType type)
  60. {
  61. const MXFDataDefinitionUL *uls = mxf_data_definition_uls;
  62. while (uls->type != CODEC_TYPE_DATA) {
  63. if (type == uls->type)
  64. break;
  65. uls ++;
  66. }
  67. return uls;
  68. }
  69. static int mux_write_packet(AVFormatContext *s, AVPacket *pkt)
  70. {
  71. ByteIOContext *pb = s->pb;
  72. AVStream *st = s->streams[pkt->stream_index];
  73. MXFStreamContext *sc = st->priv_data;
  74. put_buffer(pb, sc->track_essence_element_key, 16); // write key
  75. klv_encode_ber_length(pb, pkt->size); // write length
  76. put_buffer(pb, pkt->data, pkt->size); // write value
  77. put_flush_packet(pb);
  78. return 0;
  79. }
  80. AVOutputFormat mxf_muxer = {
  81. "mxf",
  82. NULL_IF_CONFIG_SMALL("Material eXchange Format"),
  83. NULL,
  84. "mxf",
  85. sizeof(MXFContext),
  86. CODEC_ID_PCM_S16LE,
  87. CODEC_ID_MPEG2VIDEO,
  88. mux_write_header,
  89. mux_write_packet,
  90. mux_write_footer,
  91. };