mjpg-streamer.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. -- Copyright 2014 Roger D <rogerdammit@gmail.com>
  2. -- Licensed to the public under the Apache License 2.0.
  3. m = Map("mjpg-streamer", "MJPG-streamer", translate("mjpg streamer is a streaming application for Linux-UVC compatible webcams"))
  4. --- General settings ---
  5. section_gen = m:section(TypedSection, "mjpg-streamer", translate("General"))
  6. section_gen.addremove=false
  7. section_gen.anonymous=true
  8. enabled = section_gen:option(Flag, "enabled", translate("Enabled"), translate("Enable MJPG-streamer"))
  9. input = section_gen:option(ListValue, "input", translate("Input plugin"))
  10. input:depends("enabled", "1")
  11. input:value("uvc", "UVC")
  12. ---input:value("file", "File")
  13. input.optional = false
  14. output = section_gen:option(ListValue, "output", translate("Output plugin"))
  15. output:depends("enabled", "1")
  16. output:value("http", "HTTP")
  17. output:value("file", "File")
  18. output.optional = false
  19. --- Plugin settings ---
  20. s = m:section(TypedSection, "mjpg-streamer", translate("Plugin settings"))
  21. s.addremove=false
  22. s.anonymous=true
  23. s:tab("output_http", translate("HTTP output"))
  24. s:tab("output_file", translate("File output"))
  25. s:tab("input_uvc", translate("UVC input"))
  26. ---s:tab("input_file", translate("File input"))
  27. --- Input UVC settings ---
  28. this_tab = "input_uvc"
  29. device = s:taboption(this_tab, Value, "device", translate("Device"))
  30. device.default="/dev/video0"
  31. --device.datatype = "device"
  32. device:value("/dev/video0", "/dev/video0")
  33. device:value("/dev/video1", "/dev/video1")
  34. device:value("/dev/video2", "/dev/video2")
  35. device.optional = false
  36. resolution = s:taboption(this_tab, Value, "resolution", translate("Resolution"))
  37. resolution.default = "640x480"
  38. resolution:value("320x240", "320x240")
  39. resolution:value("640x480", "640x480")
  40. resolution:value("800x600", "800x600")
  41. resolution:value("864x480", "864x480")
  42. resolution:value("960x544", "960x544")
  43. resolution:value("960x720", "960x720")
  44. resolution:value("1280x720", "1280x720")
  45. resolution:value("1280x960", "1280x960")
  46. resolution:value("1920x1080", "1920x1080")
  47. resolution.optional = true
  48. fps = s:taboption(this_tab, Value, "fps", translate("Frames per second"))
  49. fps.datatype = "and(uinteger, min(1))"
  50. fps.placeholder = "5"
  51. fps.optional = true
  52. yuv = s:taboption(this_tab, Flag, "yuv", translate("Enable YUYV format"), translate("Automatic disabling of MJPEG mode"))
  53. quality = s:taboption(this_tab, Value, "quality", translate("JPEG compression quality"), translate("Set the quality in percent. This setting activates YUYV format, disables MJPEG"))
  54. quality.datatype = "range(0, 100)"
  55. minimum_size = s:taboption(this_tab, Value, "minimum_size", translate("Drop frames smaller then this limit"),translate("Set the minimum size if the webcam produces small-sized garbage frames. May happen under low light conditions"))
  56. minimum_size.datatype = "uinteger"
  57. no_dynctrl = s:taboption(this_tab, Flag, "no_dynctrl", translate("Don't initialize dynctrls"), translate("Do not initialize dynctrls of Linux-UVC driver"))
  58. led = s:taboption(this_tab, ListValue, "led", translate("Led control"))
  59. led:value("on", translate("On"))
  60. led:value("off", translate("Off"))
  61. led:value("blink", translate("Blink"))
  62. led:value("auto", translate("Auto"))
  63. led.optional = true
  64. --- Output HTTP settings ---
  65. this_tab = "output_http"
  66. port=s:taboption(this_tab, Value, "port", translate("Port"), translate("TCP port for this HTTP server"))
  67. port.datatype = "port"
  68. port.placeholder = "8080"
  69. enable_auth = s:taboption(this_tab, Flag, "enable_auth", translate("Authentication required"), translate("Ask for username and password on connect"))
  70. enable_auth.default = false
  71. username = s:taboption(this_tab, Value, "username", translate("Username"))
  72. username:depends("enable_auth", "1")
  73. username.optional = false
  74. password = s:taboption(this_tab, Value, "password", translate("Password"))
  75. password:depends("enable_auth", "1")
  76. password.password = true
  77. password.optional = false
  78. password.default = false
  79. www = s:taboption(this_tab, Value, "www", translate("WWW folder"), translate("Folder that contains webpages"))
  80. www.datatype = "directory"
  81. www.default = "/www/webcam/"
  82. www.optional = false
  83. --- HTTP preview ---
  84. html = [[
  85. <style media="screen" type="text/css">
  86. .img-preview {
  87. display: inline-block;
  88. height: auto;
  89. width: 640px;
  90. padding: 4px;
  91. line-height: 1.428571429;
  92. background-color: #fff;
  93. border: 1px solid #ddd;
  94. border-radius: 4px;
  95. -webkit-transition: all .2s ease-in-out;
  96. transition: all .2s ease-in-out;
  97. margin-bottom: 5px;
  98. display: none;
  99. }
  100. </style>
  101. <div id="videodiv">
  102. <img id="video_preview" class="img-preview" onerror="on_error()" onload="on_load()"/>
  103. <p id="stream_status" style="text-align: center; color: orange; font-weight:bold;">Stream unavailable</p>
  104. </div>
  105. <script type="text/javascript">
  106. function init_stream() {
  107. console.log('init_stream');
  108. start_stream()
  109. }
  110. function _start_stream() {
  111. console.log('_start_stream');
  112. port = document.getElementById('cbid.mjpg-streamer.core.port').value
  113. if (document.getElementById('cbid.mjpg-streamer.core.enable_auth').checked) {
  114. user = document.getElementById('cbid.mjpg-streamer.core.username').value
  115. pass = document.getElementById('cbid.mjpg-streamer.core.password').value
  116. login = user + ":" + pass + "@"
  117. } else {
  118. login = ""
  119. }
  120. img = document.getElementById('video_preview');
  121. img.src = 'http://' + login + location.hostname + ':' + port + '/?action=snapshot';
  122. }
  123. function start_stream() {
  124. console.log('start_stream');
  125. setTimeout(function() { _start_stream(); }, 500);
  126. }
  127. function on_error() {
  128. console.log('on_error');
  129. img = document.getElementById('video_preview');
  130. img.style.display = 'none';
  131. stream_stat = document.getElementById('stream_status');
  132. stream_stat.style.display = 'block';
  133. start_stream();
  134. }
  135. function on_load() {
  136. console.log('on_load');
  137. img = document.getElementById('video_preview');
  138. img.style.display = 'block';
  139. stream_stat = document.getElementById('stream_status');
  140. stream_stat.style.display = 'none';
  141. }
  142. init_stream()
  143. </script>
  144. ]]
  145. preview = s:taboption(this_tab, DummyValue, "_dummy", html)
  146. preview:depends("output", "http")
  147. --- Output file settings ---
  148. this_tab = "output_file"
  149. folder=s:taboption(this_tab, Value, "folder", translate("Folder"), translate("Set folder to save pictures"))
  150. folder.placeholder="/tmp/images"
  151. folder.datatype = "directory"
  152. --mjpeg=s:taboption(this_tab, Value, "mjpeg", translate("Mjpeg output"), translate("Check to save the stream to an mjpeg file"))
  153. delay=s:taboption(this_tab, Value, "delay", translate("Interval between saving pictures"), translate("Set the interval in millisecond"))
  154. delay.placeholder="5000"
  155. delay.datatype = "uinteger"
  156. ringbuffer=s:taboption(this_tab, Value, "ringbuffer", translate("Ring buffer size"), translate("Max. number of pictures to hold"))
  157. ringbuffer.placeholder="10"
  158. ringbuffer.datatype = "uinteger"
  159. exceed=s:taboption(this_tab, Value, "exceed", translate("Exceed"), translate("Allow ringbuffer to exceed limit by this amount"))
  160. exceed.datatype = "uinteger"
  161. command=s:taboption(this_tab, Value, "command", translate("Command to run"), translate("Execute command after saving picture. Mjpg-streamer parse the filename as first parameter to your script."))
  162. return m