test_file_size_fix.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <iostream>
  2. #include "include/rtsp_client.h"
  3. #include "include/config.h"
  4. using namespace jtjai_media;
  5. int main() {
  6. std::cout << "测试文件大小统计修复" << std::endl;
  7. // 创建测试配置
  8. StreamConfig test_config;
  9. test_config.rtsp_url = "rtsp://218.94.57.146:40007/rtp/44010200492000000074_34020000001320000001";
  10. test_config.duration_seconds = 5; // 短时间测试
  11. test_config.weight = 1.0;
  12. test_config.output_filename = "test_file_size.mp4";
  13. // 创建输出目录
  14. std::string output_dir = "./test_output";
  15. std::filesystem::create_directories(output_dir);
  16. // 创建RTSP客户端
  17. RTSPClient client(0, test_config, output_dir);
  18. std::cout << "开始录制测试..." << std::endl;
  19. bool success = client.start_recording(5);
  20. // 获取统计信息
  21. auto stats = client.get_stats();
  22. std::cout << "\n=== 录制结果 ===" << std::endl;
  23. std::cout << "状态: " << static_cast<int>(stats.status) << std::endl;
  24. std::cout << "输出文件: " << stats.output_file << std::endl;
  25. std::cout << "接收字节数: " << stats.bytes_received << std::endl;
  26. std::cout << "接收帧数: " << stats.frames_received << std::endl;
  27. // 验证文件是否存在并检查实际大小
  28. if (std::filesystem::exists(stats.output_file)) {
  29. auto actual_file_size = std::filesystem::file_size(stats.output_file);
  30. std::cout << "实际文件大小: " << actual_file_size << " 字节" << std::endl;
  31. if (stats.bytes_received > 0) {
  32. std::cout << "✅ 文件大小统计正常!" << std::endl;
  33. } else {
  34. std::cout << "❌ 文件大小统计仍为0" << std::endl;
  35. }
  36. } else {
  37. std::cout << "⚠️ 文件未创建" << std::endl;
  38. }
  39. return 0;
  40. }