main.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. -- LuaTools需要PROJECT和VERSION这两个信息
  2. PROJECT = "vtool"
  3. VERSION = "1.0.0"
  4. httpplus = require "httpplus"
  5. local rtos_bsp = rtos.bsp()
  6. -- spi_id,pin_cs
  7. local function fatfs_spi_pin()
  8. if rtos_bsp == "AIR101" then
  9. return 0, pin.PB04
  10. elseif rtos_bsp == "AIR103" then
  11. return 0, pin.PB04
  12. elseif rtos_bsp == "AIR105" then
  13. return 2, pin.PB03
  14. elseif rtos_bsp == "ESP32C3" then
  15. return 2, 7
  16. elseif rtos_bsp == "ESP32S3" then
  17. return 2, 14
  18. elseif rtos_bsp == "EC618" then
  19. return 0, 8
  20. elseif string.find(rtos_bsp,"EC718") then
  21. return 0, 8
  22. elseif string.find(rtos_bsp,"Air810") then
  23. gpio.setup(13, 1, gpio.PULLUP)
  24. return 0, 3, fatfs.SDIO
  25. else
  26. log.info("main", "bsp not support")
  27. return
  28. end
  29. end
  30. sys.taskInit(function()
  31. sys.wait(1000)
  32. -- fatfs.debug(1) -- 若挂载失败,可以尝试打开调试信息,查找原因
  33. gpio.set(13, 1)
  34. -- 此为spi方式
  35. local spi_id, pin_cs,tp = fatfs_spi_pin()
  36. if tp and tp == fatfs.SPI then
  37. -- 仅SPI方式需要自行初始化spi, sdio不需要
  38. spi.setup(spi_id, nil, 0, 0, 8, 400 * 1000)
  39. gpio.setup(pin_cs, 1)
  40. end
  41. log.info("fatfs", "mounting...")
  42. fatfs.mount(tp or fatfs.SPI, "/sd", spi_id, pin_cs, 24 * 1000 * 1000)
  43. log.info("fatfs", "mounted")
  44. local data, err = fatfs.getfree("/sd")
  45. if data then
  46. log.info("fatfs", "getfree", json.encode(data))
  47. else
  48. log.info("fatfs", "err", err)
  49. end
  50. local pnum = 27
  51. local init_qp = 40
  52. local i_qp_max = 28
  53. local p_qp_max = 28
  54. local imb_bits = 3
  55. local pmb_bits = 3
  56. camera.config(0, camera.CONF_H264_QP_INIT, init_qp)
  57. camera.config(0, camera.CONF_H264_QP_I_MAX, i_qp_max)
  58. camera.config(0, camera.CONF_H264_QP_P_MAX, p_qp_max)
  59. camera.config(0, camera.CONF_H264_IMB_BITS, imb_bits)
  60. camera.config(0, camera.CONF_H264_PMB_BITS, pmb_bits)
  61. log.info("开始测试==================")
  62. vtool.h264_encoder_init()
  63. vtool.h264_encoder_start()
  64. local dst = "/sd/test.mp4"
  65. local mp4 = vtool.mp4create(dst, 1280, 720, 15)
  66. log.info("vtool", "开始写入jpeg文件")
  67. -- 从0.jpg, 写到 4.jpg
  68. for i = 0, 4 do
  69. local filename = string.format("/sd/C8C2C68CACB8_904_1.mp4.%d.jpg", i)
  70. log.info("vtool", "写入文件", filename)
  71. local ret = vtool.mp4write_jpeg(mp4, filename)
  72. log.info("vtool", "写入结果", ret)
  73. sys.wait(70)
  74. end
  75. sys.wait(1000)
  76. vtool.mp4close(mp4)
  77. log.info("vtool", "测试完成, 文件保存在", dst)
  78. -- 打印文件大小
  79. log.info("vtool", "test.mp4 size", io.fileSize(dst))
  80. vtool.h264_encoder_deinit()
  81. wlan.init()
  82. wlan.connect("luatos1234", "12341234")
  83. sys.waitUntil("IP_READY")
  84. httpplus.request({
  85. url = "http://upload.air32.cn/api/upload/mp4",
  86. method = "POST",
  87. bodyfile = dst
  88. })
  89. log.info("执行结束------")
  90. end)
  91. -- 用户代码已结束---------------------------------------------
  92. -- 结尾总是这一句
  93. sys.run()
  94. -- sys.run()之后后面不要加任何语句!!!!!