Revision | 7bc6626b5a35369008ae9d1194ac808d44739c65 (tree) |
---|---|
Time | 2017-03-14 21:59:20 |
Author | dyknon <dyknon@user...> |
Commiter | dyknon |
主に、再生同期をマシにした。他にも小変更
解像度デフォをwvgaに
次の配信開始待機の開始までの時間を伸ばした
プレイヤーがブラウザ窓の幅より大きくならないように
ボリュームが毎回100%になるのをどうにかした
@@ -51,11 +51,14 @@ if(!$ENV{QUERY_STRING}){ | ||
51 | 51 | <script> |
52 | 52 | function live_streamer(videoelm, controlbox, statbox, url){ |
53 | 53 | this.velm = videoelm; |
54 | + var defvol = this.velm.volume; | |
54 | 55 | this.cont = controlbox; |
55 | 56 | this.statbox = statbox; |
56 | 57 | this.serv = url; |
57 | 58 | this.media_mime = "video/webm; codecs=\\\"vp8, vorbis\\\""; |
58 | 59 | this.started = false; |
60 | + this.cache_len = 5; | |
61 | + this.skip_delay = 10; | |
59 | 62 | |
60 | 63 | if(!MediaSource |
61 | 64 | || !MediaSource.isTypeSupported(this.media_mime)){ |
@@ -64,6 +67,7 @@ if(!$ENV{QUERY_STRING}){ | ||
64 | 67 | } |
65 | 68 | this.ms = new MediaSource(); |
66 | 69 | this.velm.src = URL.createObjectURL(this.ms); |
70 | + this.velm.volume = defvol; | |
67 | 71 | this.nexcb = null; |
68 | 72 | var lsobj = this; |
69 | 73 | this.ms.addEventListener("sourceopen", function(){ |
@@ -79,7 +83,7 @@ if(!$ENV{QUERY_STRING}){ | ||
79 | 83 | this.vol_bar.max = 1; |
80 | 84 | this.vol_bar.min = 0; |
81 | 85 | this.vol_bar.step = 0.01; |
82 | - this.vol_bar.value = 1; | |
86 | + this.vol_bar.value = defvol; | |
83 | 87 | this.velm.volume = this.vol_bar.value; |
84 | 88 | this.vol_bar.addEventListener("change", this); |
85 | 89 | this.cont.innerHTML = "volume: "; |
@@ -100,6 +104,10 @@ if(!$ENV{QUERY_STRING}){ | ||
100 | 104 | this.statbox.textContent = "配信なしだよ。"; |
101 | 105 | window.setTimeout(function(t){t.keyretrycb()}, 300, this); |
102 | 106 | return; |
107 | + }else if(resp.flags & 2){ | |
108 | + this.statbox.textContent = "配信終了だよ"; | |
109 | + window.setTimeout(function(t){t.keyretrycb()}, 300, this); | |
110 | + return; | |
103 | 111 | } |
104 | 112 | this.sindex = resp.key; |
105 | 113 | this.cindex = resp.key; |
@@ -118,7 +126,7 @@ if(!$ENV{QUERY_STRING}){ | ||
118 | 126 | this.ms.endOfStream(); |
119 | 127 | window.setTimeout(function(t){ |
120 | 128 | new live_streamer(t.velm, t.cont, t.statbox, t.serv); |
121 | - }, (1000*this.bufremain()+1)|0, this); | |
129 | + }, (1000*this.bufremain()+500)|0, this); | |
122 | 130 | return; |
123 | 131 | }else if(resp.status == "nostreams"){ |
124 | 132 | this.statbox.textContent = "配信なしだよ。"; |
@@ -131,7 +139,7 @@ if(!$ENV{QUERY_STRING}){ | ||
131 | 139 | live_streamer.prototype.updatecb = function(ev){ |
132 | 140 | this.nexcb = this.datacb; |
133 | 141 | this.request("dat", this.cindex); |
134 | - if(!this.started && this.buftail() > 4){ | |
142 | + if(!this.started && this.buftail() >= this.cache_len){ | |
135 | 143 | this.started = true; |
136 | 144 | this.velm.play(); |
137 | 145 | } |
@@ -139,10 +147,22 @@ if(!$ENV{QUERY_STRING}){ | ||
139 | 147 | stat += "time:"+this.velm.currentTime+"<br>"; |
140 | 148 | stat += "buffered:"+this.bufremain()+"<br>"; |
141 | 149 | this.statbox.innerHTML = stat; |
142 | - if(this.bufremain() > 5){ | |
143 | - this.cindex += 2; | |
144 | - }else{ | |
145 | - this.cindex++; | |
150 | + this.cindex++; | |
151 | + if(this.bufremain() > this.skip_delay){ | |
152 | + this.velm.currentTime += this.bufremain() - this.cache_len; | |
153 | + }else if(this.bufremain() > this.cache_len + 1.5){ | |
154 | + this.velm.playbackRate = 1 | |
155 | + + (this.bufremain() - this.cache_len) / 10; | |
156 | + }else if(this.bufremain() < this.cache_len - 1.5){ | |
157 | + this.velm.playbackRate = 1 | |
158 | + - (this.cache_len - this.bufremain()) | |
159 | + / (this.cache_len * 2); | |
160 | + }else if(this.velm.playbackRate > 1 && | |
161 | + this.bufremain() <= this.cache_len){ | |
162 | + this.velm.playbackRate = 1; | |
163 | + }else if(this.velm.playbackRate < 1 && | |
164 | + this.bufremain() >= this.cache_len){ | |
165 | + this.velm.playbackRate = 1; | |
146 | 166 | } |
147 | 167 | }; |
148 | 168 | live_streamer.prototype.request = function(com, n){ |
@@ -224,7 +244,7 @@ if(!$ENV{QUERY_STRING}){ | ||
224 | 244 | </script> |
225 | 245 | </head> |
226 | 246 | <body> |
227 | - <video id="mainvideo"></video> | |
247 | + <video id="mainvideo" style="max-width:100%;max-height:100%"></video> | |
228 | 248 | <div id="controls"></div> |
229 | 249 | <div id="statbox"></div> |
230 | 250 | </body> |
@@ -662,7 +662,7 @@ my $in_handle = new IO::Pipe; | ||
662 | 662 | #$in_handle->reader(qw{ffmpeg -loglevel panic -f video4linux2 -r:v 10 -s vga -i /dev/video0 -map 0:v -c:v vp8 -deadline:v good -cpu-used:v 16 -g:v 10 -q:v 25 -qmax:v 28 -pix_fmt yuv420p -live 1 -vf realtime -cluster_size_limit 10000000 -cluster_time_limit 1000000 -f webm -}); |
663 | 663 | #$in_handle->reader(qw{ffmpeg -loglevel panic -s 1366x768 -r:v 20 -f x11grab -i :0+1080,880 -map 0:v -c:v vp8 -deadline:v good -cpu-used:v 8 -g:v 10 -q:v 25 -qmax:v 28 -pix_fmt yuv420p -live 1 -cluster_size_limit 10000000 -cluster_time_limit 1000000 -s wvga -vf realtime -f webm -}); |
664 | 664 | defined($ARGV[0]) || die; |
665 | -$in_handle->reader(qw{ffmpeg -loglevel panic -i}, $ARGV[0], qw{-map 0:v:0 -map 0:a:0 -c:v vp8 -deadline:v realtime -cpu-used:v 8 -g:v 20 -q:v 28 -qmax:v 30 -live 1 -vf realtime -c:a libvorbis -b:a 64k -cluster_size_limit 10000000 -cluster_time_limit 1000000 -s hd720 -f webm -}); | |
665 | +$in_handle->reader(qw{ffmpeg -loglevel panic -i}, $ARGV[0], qw{-map 0:v:0 -map 0:a:0 -c:v vp8 -deadline:v realtime -cpu-used:v 8 -g:v 20 -q:v 28 -qmax:v 30 -live 1 -vf realtime -c:a libvorbis -ac 2 -ar 44.1k -b:a 64k -cluster_size_limit 10000000 -cluster_time_limit 1000000 -s wvga -f webm -}); | |
666 | 666 | binmode($in_handle, ":raw"); |
667 | 667 | StreamInHandler->new($in_handle); |
668 | 668 |