Skip to content

Instantly share code, notes, and snippets.

@phanirithvij
Created February 19, 2021 17:22
Show Gist options
  • Save phanirithvij/a23c388245ac54462d9d9dccf756dc62 to your computer and use it in GitHub Desktop.
Save phanirithvij/a23c388245ac54462d9d9dccf756dc62 to your computer and use it in GitHub Desktop.
lrc to srt conversion backup

album art extraction, image2vector hack, lyric sync

  • audio files genereated from ffmpeg from the video, trimming first 9 secs
ffmpeg.exe -i input.mkv -acodec flac -bits_per_raw_sample 16 -ar 44100 output.flac
ffmpeg -i input.mkv output.wav
ffmpeg.exe -i output.wav -vn -ar 44100 -ac 2 -b:a 320k output_320k.mp3
ffmpeg.exe -i output.wav -vn -ar 44100 -ac 2 -b:a 128k output_128k.mp3

# Trim
ffmpeg -i output.wav -ss 9 -acodec copy output_trim.wav
ffmpeg -i output.flac -ss 9 -acodec copy output_trim.flac
ffmpeg -i output_320k.mp3 -ss 9 -acodec copy output_trim_320k.mp3
ffmpeg -i output_128k.mp3 -ss 9 -acodec copy output_trim_128k.mp3

map lyrics to timestamps

https://www.megalobiz.com/lrc/maker https://www.compuphase.com/software_sylteditor.htm

make a album cover

vectormagic to get the vectorized logo from the low res logo image

https://picsvg.com/ is easier to use and decent with Great, Invert #4 config. but colors WILL be compromised

https://gist.github.com/cppio/9cee96641b49796c310024da70140e2d

// set breakpoints to get xt which has the data

/* 
  t.resultUpdated = function(t) {
// > set breakpoint here c = t
// then Scope > add to global variables
    c = t,
    g.vector.setResult(t)
  }

*/

// paste the following in console

var toSVG = function (xt) {
  let paths = [];

  xt.pieces.forEach((piece) => {
    let index = 0;

    piece.shapes.forEach((shape) => {
      let commands = [];

      shape.lenghts.forEach((length) => {
        commands.push(`M ${piece.floats[index++]} ${piece.floats[index++]}`);

        for (let i = 0; i < (length - 2) / 6; i++) {
          commands.push(
            `C ${piece.floats[index++]} ${piece.floats[index++]} ${
              piece.floats[index++]
            } ${piece.floats[index++]} ${piece.floats[index++]} ${
              piece.floats[index++]
            }`
          );
        }

        commands.push("Z");
      });

      paths.push(`    <path d="${commands.join(" ")}" fill="${shape.color}"/>`);
    });
  });

  return `<svg width="${xt.imageWidth}" height="${
    xt.imageHeight
  }" xmlns="http://www.w3.org/2000/svg">
${paths.join("\n")}
</svg>
`;
};


var textFile = null,
  makeTextFile = function (text) {
    var data = new Blob([text], {type: 'text/plain'});

    // If we are replacing a previously generated file we need to
    // manually revoke the object URL to avoid memory leaks.
    if (textFile !== null) {
      window.URL.revokeObjectURL(textFile);
    }

    textFile = window.URL.createObjectURL(data);

    // returns a URL you can use as a href
    return textFile;
  };


var svg = toSVG(temp1);
var link = document.createElement('a');
link.setAttribute('download', 'vectormagic.svg');
link.href = makeTextFile(svg);
// link.style.width = "20px";
style = `font-size: 17px;
z-index: 1000;
position: fixed;
right: 25px;
bottom: 22px;
background: aquamarine;
`
link.setAttribute("style", style);
link.innerText = "Download vectormagic.svg";
document.body.appendChild(link);

Then stripped a frame from the video

make album art

Then used

embed album cover to audio

For flac embed

https://stackoverflow.com/a/59728189/8608146

ffmpeg -i output_trim.flac -i dil-hai-jawan-velvet-50.png -c copy -disposition:v attached_pic -vsync 0 -c:v png output_trim_final.flac

For mp3 embed

https://stackoverflow.com/a/18718265/8608146

ffmpeg -i output_trim_128k.mp3 -i dil-hai-jawan-velvet-50.png -map 0:0 -map 1:0 -codec copy -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" output_trim_final_128k.mp3
ffmpeg -i output_trim_320k.mp3 -i dil-hai-jawan-velvet-50.png -map 0:0 -map 1:0 -codec copy -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" output_trim_final_320k.mp3

TODO m4a (Itunes)

#!/usr/bin/env python
# a script can help u to convert the lyrics file to .srt
# created by wOOL, [email protected]
# edited by eadmaster http://eadmaster.tk
# http://eadmaster.altervista.org/pub/prj/lrc2srt.py
import sys
import re
import os
from datetime import datetime
from datetime import timedelta
# args checking
if(len(sys.argv) == 1 or sys.argv[1] == '-h' or sys.argv[1] == '--help' or not os.path.isfile(sys.argv[1])):
print("usage: lrc2srt FILE.SRT")
exit(0)
p = re.compile("[0-9]+")
filename = sys.argv[1]
#interval = str(sys.argv[2])
lrc = open(filename)
listtime = []
listlyrics = []
for line in lrc.readlines():
if p.match(line.split(":")[0].replace("[", "")):
listtime.append("00:" + line.split("]")[0].replace("[", "")+"0")
listlyrics.append(line.split("]")[1])
# read file and delete empty&useless lines
o = ""
i = 0
# listtime[i].replace(".",",")+\
while i <= listtime.__len__()-2:
start_time = (datetime.strptime(
listtime[i], "%H:%M:%S.%f")-datetime.strptime("1", "%S"))
if (start_time.days < 0):
start_time = (datetime.strptime(
listtime[i], "%H:%M:%S.%f")-datetime.strptime("0", "%S"))
if (start_time.microseconds == 0):
# add 1 msec to avoid empty msec field
start_time = start_time+timedelta(microseconds=1)
o = o +\
str(i+1) +\
"\n" +\
"0" + str(start_time).replace("000", "").replace(".", ",") +\
" --> " +\
listtime[i+1].replace(".", ",") +\
"\n"+listlyrics[i] +\
"\n"
i = i+1
o = o + str(i+1) + "\n" + listtime[-1].replace(".",
",") + " --> " + "\n" + listlyrics[-1] + "\n"
srt = open(filename.replace("lrc", "srt"), "w")
srt.write(o)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment