Skip to content

Commit

Permalink
ライブラリーで総再生時間を取得可能に
Browse files Browse the repository at this point in the history
要ffprobe.exe
ffmpeg.exeに同梱
  • Loading branch information
EMWUI committed Oct 8, 2018
1 parent d877e6f commit 2b4644f
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 34 deletions.
74 changes: 52 additions & 22 deletions HttpPublic/EMWUI/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function playMovie(obj){
hideBar(2000);
}else{
$('#seek').get(0).MaterialSlider.change(0);
$('.currentTime,.duration').text('0:00');
loadMovie(obj);
}
video.play();
Expand Down Expand Up @@ -166,40 +167,69 @@ $(function(){
'canplay': function(){
hideBar(2000);
$(this).removeClass('is-loadding');
$('#seek').prop('disabled', false);

xcode = $(this).data('xcode');
duration= $(this).data('duration') || this.duration;


if ($(this).data('cast')){
this.play();

var data = $('.is_cast').data();
$('#seek').prop('disabled', true);
$('.duration').text(getVideoTime(data.duration));

$(this).on('timeupdate', function(){
var currentTime = (Date.now() - data.start)/1000;
$('.currentTime').text(getVideoTime(currentTime));
$('#seek').get(0).MaterialProgress.setProgress(currentTime / data.duration * 100);
});
}else if (xcode && !$(this).data('rec')){
$(this).off('timeupdate');
$('#seek').attr('max', 99).attr('step', 1);
$('.Time-wrap').addClass('is-disabled');
$('.currentTime,.duration').text('0:00');
}else{
$(this).on('timeupdate', function(){
if (!$(this).data('touched')){
var currentTime = video.currentTime + seek * (duration / 99);
$('.currentTime').text(getVideoTime(currentTime));
$('#seek').get(0).MaterialSlider.change(currentTime / duration * 100);
var self = $(this);
function timeupdate(duration){
self.on('timeupdate', function(){
if (!self.data('touched')){
var currentTime = video.currentTime + seek * (duration / 99);
$('.currentTime').text(getVideoTime(currentTime));
$('#seek').get(0).MaterialSlider.change(currentTime / duration * 100);
}
});
$('.Time-wrap').removeClass('is-disabled');
$('.duration').text(getVideoTime(duration));
};

xcode = $(this).data('xcode');
if (xcode){
$('#seek').attr('max', 99);
$('#audio').prop('disabled', false);
duration = $(this).data('duration');
if (duration){
timeupdate(duration);
}else{
$.get(root + 'api/Movie?fname=' + $(this).data('path') + '&meta=', function(result, textStatus, xhr){
var xml = $(xhr.responseXML);
if (xml.find('duration').length > 0){
duration = xml.find('duration').text();
timeupdate(duration);
}else{
duration = false;
$(this).off('timeupdate');
$('.Time-wrap').addClass('is-disabled');
}
if (xml.find('audio').length > 0){
if (xml.find('audio').text() == 1){
$('#RAW').prop('checked', true);
$('.dual').show();
$('.multi').hide();
}else{
$('#multi1').prop('checked', true);
$('.multi').show();
$('.dual').hide();
}
}
});
}
});
$('#seek').attr('max', 100).attr('step', 0.01);
$('.Time-wrap').removeClass('is-disabled');
$('.duration').text(getVideoTime(duration));
//if (!$(this).data('public') && !$(this).data('duration')) $('#seek').prop('disabled', true); //Firefoxだとシークできたので
}else{
$('#seek').attr('max', 100);
$('#audio').prop('disabled', true);
duration = this.duration;
timeupdate(duration);
}
}
}
});
Expand Down Expand Up @@ -227,7 +257,7 @@ $(function(){
}
},
'input': function(){
if (!xcode || $('#video').data('rec')){
if (duration){
var currentTime = video.currentTime + $(this).val() * (duration / 99);
$('.currentTime').text(getVideoTime(currentTime));
}
Expand Down
10 changes: 9 additions & 1 deletion HttpPublic/EMWUI/recinfodesc.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- vim:set ft=lua:
dofile(mg.script_name:gsub('[^\\/]*$','')..'util.lua')
dir=edcb.GetPrivateProfile('SET', 'ModulePath', '', 'Common.ini')..'\\Tools\\'
ffprobe=edcb.GetPrivateProfile('SET','ffprobe',dir..'ffprobe.exe',ini)

ct={title='録画結果'}

Expand All @@ -16,19 +18,25 @@
f=edcb.FindFile and edcb.FindFile(mg.document_root..'\\video\\'..fname..ext, 1)
if f then
video=PathToRoot()..'video/'..mg.url_encode(fname)..ext
fpath=mg.document_root..'\\video\\'..fname..ext
break
end
end
if not video then
f=edcb.FindFile and edcb.FindFile(w.recFilePath, 1)
if f then
video=PathToRoot()..'api/Movie?id='..v.id
fpath=w.recFilePath
ori=true
end
end

if video then
ct.js='<script src="js/player.js"></script>\n'
f=edcb.FindFile and edcb.FindFile(ffprobe, 1)
if f then
duration=edcb.io.popen('""'..ffprobe..'" -i "'..fpath..'" -v quiet -show_entries format=duration -of ini 2>&1"', 'rb'):read('*a'):match('=(.+)\n')
end
end

title=ConvertTitle(v.title)
Expand Down Expand Up @@ -60,7 +68,7 @@
..'</ul></section>'

..(video and '<section class="mdl-layout__tab-panel" id="movie">\n<div class="mdl-grid mdl-grid--no-spacing">\n'
..player('<video id="video" preload="none" '..(ori and 'data-path="'..video..'" data-duration="'..v.durationSecond or 'src="'..video..'" data-public="true')..'" data-rec="true"></video>\n', audio, not ori)
..player('<video id="video" preload="none" '..(ori and 'data-path="'..video..'" data-duration="'..(duration or v.durationSecond) or 'src="'..video..'" data-public="true')..'" data-rec="true"></video>\n', audio, not ori)
..'</div>\n</section>\n' or '')

..(#v.errInfo>0 and '<section class="mdl-layout__tab-panel" id="error">\n<div>\n<pre>'..v.errInfo..'</pre>\n</div>\n</section>\n' or '')
Expand Down
4 changes: 2 additions & 2 deletions HttpPublic/EMWUI/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ if temp.video then
'<div id="center"><i id="playprev" class="ctl-button material-icons">skip_previous</i><i id="play" class="ctl-button material-icons">play_arrow</i><i id="playnext" class="ctl-button material-icons">skip_next</i></div>\n' or '')..[=[
<div id="titlebar" class="bar"></div>
<div id="control" class="ext bar">
<div id="seek-container">]=]..(temp.video=='onair' and '<div class="progress mdl-slider__container"><div id="seek" class="mdl-progress mdl-js-progress"></div></div>' or '<input class="mdl-slider mdl-js-slider" type="range" id="seek" min="0" max="99" value="0" step="1">')..'</div>\n'
<div id="seek-container">]=]..(temp.video=='onair' and '<div class="progress mdl-slider__container"><div id="seek" class="mdl-progress mdl-js-progress"></div></div>' or '<input class="mdl-slider mdl-js-slider" type="range" id="seek" min="0" max="99" value="0" step="0.01">')..'</div>\n'
..(not sp and '<i id="playprev" class="ctl-button material-icons">skip_previous</i><i id="play" class="ctl-button material-icons">play_arrow</i><i id="playnext" class="ctl-button material-icons">skip_next</i>\n' or '')..[=[
<div id="volume-wrap"><i id="volume-icon" class="ctl-button material-icons">volume_up</i>]=]..(not sp and '<p id="volume-container"><input class="mdl-slider mdl-js-slider" type="range" id="volume" min="0" max="1" value="0" step="0.01"></p>' or '')..[=[</div>
<div class="Time-wrap"><span class="currentTime videoTime">0:00</span><span> / </span><span class="duration videoTime">0:00</span></div>
Expand Down Expand Up @@ -836,7 +836,7 @@ function player(video, audio, xcode)
<div id="playerUI" class="is-visible]=]..(sp and ' sp' or '')..[=[">
<div></div>
<div id="control" class="ext bar">
<div id="seek-container"><input class="mdl-slider mdl-js-slider" type="range" id="seek" min="0" max="99" value="0" step="1"></div>
<div id="seek-container"><input class="mdl-slider mdl-js-slider" type="range" id="seek" min="0" max="99" value="0" step="0.01"></div>
]=]..(not sp and '<i id="play" class="ctl-button material-icons">play_arrow</i>' or '')..[=[
<div id="volume-wrap"><i id="volume-icon" class="ctl-button material-icons">volume_up</i>]=]..(not sp and '<p id="volume-container"><input class="mdl-slider mdl-js-slider" type="range" id="volume" min="0" max="1" value="0" step="0.01"></p>' or '')..[=[</div>
<div class="Time-wrap"><span class="currentTime videoTime">0:00</span><span> / </span><span class="duration videoTime">0:00</span></div>
Expand Down
35 changes: 26 additions & 9 deletions HttpPublic/api/Movie
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dofile(mg.document_root..'\\api\\util.lua')
ini='Setting\\HttpPublic.ini'
dir=edcb.GetPrivateProfile('SET', 'ModulePath', '', 'Common.ini')..'\\Tools\\'
ffmpeg=edcb.GetPrivateProfile('SET','ffmpeg',dir..'ffmpeg.exe',ini)
ffprobe=edcb.GetPrivateProfile('SET','ffprobe',dir..'ffprobe.exe',ini)
readex=edcb.GetPrivateProfile('SET','readex',dir..'readex.exe',ini)

mp4=tonumber(edcb.GetPrivateProfile('SET','mp4',0,ini))~=0
Expand Down Expand Up @@ -82,22 +83,38 @@ if fpath then
if mg.get_mime_type(fname):find('^video/') or fname:lower():find('%.ts$') or fname:lower():find('%.m2ts$') then
f=edcb.io.open(fpath, 'rb')
if f then
offset=math.floor((f:seek('end', 0) or 0) * offset / 99 / 188) * 188
if XCODE then
meta=mg.get_var(mg.request_info.query_string,'meta')
if meta then
f:close()
-- 容量確保の可能性があるときは周期188+同期語0x47(188*256+0x47=48199)で対象ファイルを終端判定する
sync=fname:lower():find('%.ts$') and edcb.GetPrivateProfile('SET','KeepDisk',0,'EpgTimerSrv.ini')~='0'
f=edcb.io.popen('""'..readex..'" '..offset..(sync and ' 4p48199' or ' 4')..' "'..fpath..'" | '..XCMD..'"', 'rb')
fname='xcode'..XEXT
f=edcb.FindFile and edcb.FindFile(ffprobe, 1)
if f then
f=edcb.io.popen('""'..ffprobe..'" -i "'..fpath..'" -hide_banner -show_format -show_entries format=duration 2>&1"', 'rb'):read('*a')
meta={duration=f:match('duration=(.-)\r\n'), audio={}}
for w in f:gmatch(':%sAudio:%s(.-)\r\n') do
table.insert(meta.audio,w)
end
end
else
f:seek('set', offset)
XPREPARE=nil
offset=math.floor((f:seek('end', 0) or 0) * offset / 99 / 188) * 188
if XCODE then
f:close()
-- 容量確保の可能性があるときは周期188+同期語0x47(188*256+0x47=48199)で対象ファイルを終端判定する
sync=fname:lower():find('%.ts$') and edcb.GetPrivateProfile('SET','KeepDisk',0,'EpgTimerSrv.ini')~='0'
f=edcb.io.popen('""'..readex..'" '..offset..(sync and ' 4p48199' or ' 4')..' "'..fpath..'" | '..XCMD..'"', 'rb')
fname='xcode'..XEXT
else
f:seek('set', offset)
XPREPARE=nil
end
end
end
end
end

if not f then
if meta then
ct='<?xml version="1.0" encoding="UTF-8" ?><entry>'..(type(meta)=='table' and (meta.duration~='N/A' and '<duration>'..meta.duration..'</duration>' or '')..'<audio>'..#meta.audio..'</audio>' or '<err>なし</err>')..'</entry>'
mg.write('HTTP/1.1 200 OK\r\nContent-Type: text/xml\r\nContent-Length: '..#ct..'\r\nConnection: close\r\n\r\n', ct)
elseif not f then
mg.write('HTTP/1.1 404 Not Found\r\nConnection: close\r\n\r\n')
else
mg.write('HTTP/1.1 200 OK\r\nContent-Type: '..mg.get_mime_type(fname)..'\r\nContent-Disposition: filename='..mg.url_encode(fname)..'\r\nConnection: close\r\n\r\n')
Expand Down

0 comments on commit 2b4644f

Please sign in to comment.