本文主要是介绍LRC转SRT,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
最近看到一首很好的英文MTV原版,没又字幕,自己找字幕,只找到LRC,ffmpeg不支持LRC,网上在线转了SRT。
Subtitle Converter | Free tool | GoTranscript
然后用 ffmpeg 加字幕
ffmpeg -i LoveMeLikeYouDo.mp4 -vf subtitles=LoveMeLikeYouDo.srt LoveMeLikeYouDo1.mp4
打开 LRC 和 SRT 都是纯文本,可以自己做一个。
<html>
<head>
<meta charset="UTF-8">
<title>LRC转SRT</title>
</head>
<body>
LRC:<input id="file" type="file"> <button id="button_srt">SRT</button>
<script>
var file0, s='';
file.addEventListener('change', function(){ read(); });
button_srt.addEventListener('click', function(){ lrc2srt(); });function read() {file0 = file.files[0];var reader = new FileReader();reader.readAsText(file0);reader.onload = function(e){s = reader.result;};
}function lrc2srt() {var s1='', time=[], st=[];var sl = s.split('\n'); for (i=0; i<sl.length; i++) {if (sl[i].indexOf(']') != -1) {var sl1 = sl[i].split(']');time.push(sl1[0].substring(sl1[0].indexOf('[') + 1));st.push(sl1[1].replace(/'/g, "'")); }}//合并时间重复for (i=0; i<time.length; i++) { if (i > 1 && i < time.length - 1 && time[i] == time[i+1]) {st[i-1] = st[i-1] + '\n' + st[i]; //错位合并上一句time.splice(i, 1);st.splice(i, 1);}}for (i=0; i<time.length; i++) {s1 = s1 + (i+1) + '\n';if (i < time.length - 1) {var time1 = '00:' + time[i];if (time1.indexOf('.') == -1)time1 = time1 + '.000';var time2 = '00:' + time[i+1];if (time2.indexOf('.') == -1)time2 = time2 + '.000';s1 = s1 + time1 + ' --> ' + time2 + '\n';} else {var time1 = '00:' + time[i];if (time1.indexOf('.') == -1)time1 = time1 + '.000';s1 = s1 + time1 + ' --> ' + time1 + '\n';} s1 = s1 + st[i] + '\n\n';}var blob = new Blob([s1], { type:'text/plain,charset=UTF-8' });var url = URL.createObjectURL(blob);//查看//window.open(url);//下载var link = document.createElement('a');link.download = file0.name.substring(0,file0.name.indexOf('.')) + '.srt';link.href = url;link.click();
}
</script>
</body>
</html>
视频处理CPU满载,处理时长和视频时间一样长!
有些字幕还是没对上,需要对LRC或者SRT编辑。
这篇关于LRC转SRT的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!