Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

59 рядки
2.0KB

  1. #include "mkv-format.h"
  2. #include "mkv-reader.h"
  3. #include "mkv-writer.h"
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <assert.h>
  7. extern "C" const struct mkv_buffer_t* mkv_file_buffer(void);
  8. static uint8_t s_buffer[2 * 1024 * 1024];
  9. static int s_audio_track = -1;
  10. static int s_video_track = -1;
  11. static int s_subtitle_track = -1;
  12. static void mkv_onread(void* param, uint32_t track, const void* buffer, size_t bytes, int64_t pts, int64_t dts, int flags)
  13. {
  14. mkv_writer_t* mkv = (mkv_writer_t*)param;
  15. int r = mkv_writer_write(mkv, track, buffer, bytes, pts, dts, flags);
  16. assert(0 == r);
  17. }
  18. static void mkv_video_info(void* param, uint32_t track, enum mkv_codec_t codec, int width, int height, const void* extra, size_t bytes)
  19. {
  20. mkv_writer_t* mkv = (mkv_writer_t*)param;
  21. s_video_track = mkv_writer_add_video(mkv, codec, width, height, extra, bytes);
  22. }
  23. static void mkv_audio_info(void* param, uint32_t track, enum mkv_codec_t codec, int channel_count, int bit_per_sample, int sample_rate, const void* extra, size_t bytes)
  24. {
  25. mkv_writer_t* mkv = (mkv_writer_t*)param;
  26. s_audio_track = mkv_writer_add_audio(mkv, codec, channel_count, bit_per_sample, sample_rate, extra, bytes);
  27. }
  28. static void mkv_subtitle_info(void* param, uint32_t track, enum mkv_codec_t codec, const void* extra, size_t bytes)
  29. {
  30. mkv_writer_t* mkv = (mkv_writer_t*)param;
  31. s_subtitle_track = mkv_writer_add_subtitle(mkv, codec, extra, bytes);
  32. }
  33. void mkv_writer_test2(const char* file, const char* outfile)
  34. {
  35. FILE* fp = fopen(file, "rb");
  36. FILE* wfp = fopen(outfile, "wb");
  37. mkv_reader_t* mkv = mkv_reader_create(mkv_file_buffer(), fp);
  38. mkv_writer_t* w = mkv_writer_create(mkv_file_buffer(), wfp, 0);
  39. struct mkv_reader_trackinfo_t info = { mkv_video_info, mkv_audio_info, mkv_subtitle_info };
  40. mkv_reader_getinfo(mkv, &info, w);
  41. while (mkv_reader_read(mkv, s_buffer, sizeof(s_buffer), mkv_onread, w) > 0)
  42. {
  43. }
  44. mkv_writer_destroy(w);
  45. mkv_reader_destroy(mkv);
  46. fclose(fp);
  47. fclose(wfp);
  48. }