Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

57 lignes
1.9KB

  1. #include "fmp4-writer.h"
  2. #include "mov-format.h"
  3. #include "mov-reader.h"
  4. #include "mpeg4-aac.h"
  5. #include "mov-file-buffer.h"
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <assert.h>
  10. static uint8_t s_buffer[2 * 1024 * 1024];
  11. static int s_audio_track = -1;
  12. static int s_video_track = -1;
  13. static void mov_onread(void* param, uint32_t track, const void* buffer, size_t bytes, int64_t pts, int64_t dts, int flags)
  14. {
  15. fmp4_writer_t* fmp4 = (fmp4_writer_t*)param;
  16. int r = fmp4_writer_write(fmp4, track-1, buffer, bytes, pts, dts, flags);
  17. assert(0 == r);
  18. }
  19. static void mov_video_info(void* param, uint32_t track, uint8_t object, int width, int height, const void* extra, size_t bytes)
  20. {
  21. fmp4_writer_t* fmp4 = (fmp4_writer_t*)param;
  22. s_video_track = fmp4_writer_add_video(fmp4, object, width, height, extra, bytes);
  23. }
  24. static void mov_audio_info(void* param, uint32_t track, uint8_t object, int channel_count, int bit_per_sample, int sample_rate, const void* extra, size_t bytes)
  25. {
  26. fmp4_writer_t* fmp4 = (fmp4_writer_t*)param;
  27. s_audio_track = fmp4_writer_add_audio(fmp4, object, channel_count, bit_per_sample, sample_rate, extra, bytes);
  28. }
  29. void fmp4_writer_test2(const char* mp4, const char* outmp4)
  30. {
  31. struct mov_file_cache_t file, wfile;
  32. memset(&file, 0, sizeof(file));
  33. memset(&wfile, 0, sizeof(wfile));
  34. file.fp = fopen(mp4, "rb");
  35. wfile.fp = fopen(outmp4, "wb");
  36. mov_reader_t* mov = mov_reader_create(mov_file_cache_buffer(), &file);
  37. fmp4_writer_t* fmp4 = fmp4_writer_create(mov_file_cache_buffer(), &wfile, MOV_FLAG_SEGMENT);
  38. struct mov_reader_trackinfo_t info = { mov_video_info, mov_audio_info };
  39. mov_reader_getinfo(mov, &info, fmp4);
  40. fmp4_writer_init_segment(fmp4);
  41. while (mov_reader_read(mov, s_buffer, sizeof(s_buffer), mov_onread, fmp4) > 0)
  42. {
  43. }
  44. fmp4_writer_destroy(fmp4);
  45. mov_reader_destroy(mov);
  46. fclose(wfile.fp);
  47. fclose(wfile.fp);
  48. }