luat_vtool_mp4box.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef LUAT_VTOOL_MP4BOX_H
  2. #define LUAT_VTOOL_MP4BOX_H
  3. #include "luat_base.h"
  4. #include "luat_malloc.h"
  5. #include "luat_rtos.h"
  6. #define LUAT_VTOOL_MP4BOX_MAX_CLIENT 8
  7. #define LUAT_VTOOL_MP4BOX_PATH_MAX 255
  8. typedef struct mp4box
  9. {
  10. size_t len;
  11. uint8_t tp[8];
  12. struct mp4box* mboxs[LUAT_VTOOL_MP4BOX_MAX_CLIENT];
  13. size_t self_data_len;
  14. uint8_t *data;
  15. }mp4box_t;
  16. typedef struct mp4_ctx {
  17. FILE* fd; // 文件句柄
  18. char path[LUAT_VTOOL_MP4BOX_PATH_MAX + 1];
  19. uint32_t frame_id; // 当前帧的id
  20. uint64_t prev_frame_time; // 上一帧的时间, 单位ms
  21. uint32_t frame_w; // 宽
  22. uint32_t frame_h; // 高
  23. uint32_t frame_fps; // 帧率
  24. uint32_t* iframe_ids; // iframe的id列表
  25. uint32_t iframe_id_index;
  26. uint32_t iframe_id_len;
  27. uint32_t* frame_offsets; // 帧的偏移列表
  28. uint32_t frame_offset_index;
  29. uint32_t frame_offset_len;
  30. uint32_t* frame_sizes; // 帧的偏移列表
  31. uint32_t frame_size_index;
  32. uint32_t frame_size_len;
  33. uint32_t* frame_durs; // 帧的时长列表,暂时不使用
  34. uint32_t frame_dur_index;
  35. uint32_t frame_dur_len;
  36. uint64_t prev_frame_tms; // 上一帧的时间戳, 单位ms
  37. uint64_t start_time; // 开始时间戳, 单位ms
  38. uint8_t* sps;
  39. uint32_t sps_len;
  40. uint8_t* pps;
  41. uint32_t pps_len;
  42. uint32_t mdat_offset; // mdat的偏移
  43. // box列表
  44. // 只填充必要的box, 其他box一概不加
  45. // 这里是扁平的结构
  46. // 后面用代码整理成树形结构
  47. mp4box_t box_moov;
  48. mp4box_t box_mvhd;
  49. mp4box_t box_trak;
  50. mp4box_t box_tkhd;
  51. mp4box_t box_mdia;
  52. mp4box_t box_mdhd;
  53. mp4box_t box_hdlr;
  54. mp4box_t box_minf;
  55. mp4box_t box_vmhd;
  56. mp4box_t box_dinf;
  57. mp4box_t box_dref;
  58. mp4box_t box_url;
  59. mp4box_t box_stbl;
  60. mp4box_t box_avcc;
  61. mp4box_t box_avc1;
  62. mp4box_t box_stsd;
  63. mp4box_t box_stts;
  64. mp4box_t box_stsc;
  65. mp4box_t box_stsz;
  66. mp4box_t box_stco;
  67. mp4box_t box_stss;
  68. char* box_buff;
  69. size_t box_buff_size;
  70. size_t box_buff_offset;
  71. uint64_t first_frame_tms; // 第一帧的时间戳, 单位ms
  72. uint64_t last_frame_tms; // 最后一帧的时间戳, 单位ms
  73. }mp4_ctx_t;
  74. mp4_ctx_t* luat_vtool_mp4box_create(const char* path, uint32_t frame_w, uint32_t frame_h, uint32_t frame_fps);
  75. int luat_vtool_mp4box_write_frame(mp4_ctx_t* ctx, uint8_t* data, size_t len);
  76. int luat_vtool_mp4box_close(mp4_ctx_t* ctx);
  77. // int luat_vtool_jpeg_decoder_init(void);
  78. // int luat_vtool_jpeg_decoder_deinit(void);
  79. int luat_vtool_jpeg_add(const char* path);
  80. int luat_vtool_h264_encoder_init(void);
  81. int luat_vtool_h264_encoder_start(void);
  82. int luat_vtool_h264_encoder_deinit(void);
  83. #include "luat_mcu.h"
  84. #endif