Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

61 Zeilen
1.5KB

  1. #include "flv-writer.h"
  2. #include "flv-muxer.h"
  3. #include "mpeg4-avc.h"
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <assert.h>
  8. struct h264_raw_t
  9. {
  10. flv_muxer_t* flv;
  11. uint32_t pts, dts;
  12. const uint8_t* ptr;
  13. int vcl;
  14. };
  15. static int on_flv_packet(void* flv, int type, const void* data, size_t bytes, uint32_t timestamp)
  16. {
  17. return flv_writer_input(flv, type, data, bytes, timestamp);
  18. }
  19. static void h264_handler(void* param, const uint8_t* nalu, size_t bytes)
  20. {
  21. struct h264_raw_t* ctx = (struct h264_raw_t*)param;
  22. assert(ctx->ptr < nalu);
  23. const uint8_t* ptr = nalu - 3;
  24. // const uint8_t* end = (const uint8_t*)nalu + bytes;
  25. uint8_t nalutype = nalu[0] & 0x1f;
  26. if (ctx->vcl > 0 && h264_is_new_access_unit((const uint8_t*)nalu, bytes))
  27. {
  28. flv_muxer_avc(ctx->flv, ctx->ptr, ptr - ctx->ptr, ctx->pts, ctx->dts);
  29. ctx->pts += 40;
  30. ctx->dts += 40;
  31. ctx->ptr = ptr;
  32. ctx->vcl = 0;
  33. }
  34. if (1 <= nalutype && nalutype <= 5)
  35. ++ctx->vcl;
  36. }
  37. void avc2flv_test(const char* inputH264, const char* outputFLV)
  38. {
  39. struct h264_raw_t ctx;
  40. memset(&ctx, 0, sizeof(ctx));
  41. void* f = flv_writer_create(outputFLV);
  42. ctx.flv = flv_muxer_create(on_flv_packet, f);
  43. FILE* fp = fopen(inputH264, "rb");
  44. static uint8_t buffer[32 * 1024 * 1024];
  45. size_t n = fread(buffer, 1, sizeof(buffer), fp);
  46. ctx.ptr = buffer;
  47. mpeg4_h264_annexb_nalu(buffer, n, h264_handler, &ctx);
  48. fclose(fp);
  49. flv_muxer_destroy(ctx.flv);
  50. flv_writer_destroy(f);
  51. }