Close

Audio CD to FLAC, VLC media player

A project log for Raspberry PI FLAC audio server

Do you have a bunch of FLAC files, and want to enjoy the music on any device on your network? NO APP REQUIRED! :)

sciencedude1990sciencedude1990 04/07/2021 at 12:120 Comments

VLC Media Player has the capability to create FLAC files from an audio CD.  It has "lua" scripting.  So, place the script below into the directory:

VideoLAN\VLC\lua\extensions

Then, in the View menu, you'll see a new option called "Audio CD to flac".  Enter the number of Tracks in the track field, then press Apply profile, and then press Enqueue converting tracks.

Now, the CD to flac conversion will be in your play list - so click View -> Playlist, and then press the big play button.  The CD will be converted to flac files, and placed in your C:\temp directory.

Here is the listing of the lua script (you could call it cd_flac.lua - is is based off of the post at   https://forum.videolan.org/viewtopic.php?f=29&t=130354    ):

profiles={
{"Audio CD -> flac", " :cdda-track=? :sout=#transcode{vcodec=none,acodec=flac,ab=128,channels=2,samplerate=44100}:file{mux=flac,dst=\"C:\\temp\\Track ?.flac\"}"},
}

-----

function descriptor()
return {
title = "Audio CD to flac",
capabilities={},
}
end

function activate()
create_dialog()
end

function deactivate()
end

function meta_changed()
end

function close()
    vlc.deactivate()
end

-----

function create_dialog()
d = vlc.dialog(descriptor().title)
d:add_label(string.rep(" ",50),1,1,1,1)
d:add_label(string.rep(" ",50),2,1,1,1)
d:add_label(string.rep(" ",50),3,1,1,1)
d:add_label(string.rep(" ",50),4,1,1,1)
d:add_label(string.rep(" ",50),5,1,1,1)
----
d:add_label("Source MRL: ",1,1,1,1)
ti_mrl = d:add_text_input("cdda:///D:/",2,1,1,1)
d:add_label("(Media > Open Disc... > Audio CD)",3,1,2,1)

d:add_label("Tracks: ",1,2,1,1)
ti_tracks = d:add_text_input("15",2,2,1,1)
d:add_label("Then ? in output string represents the counter.",3,2,2,1)

d:add_label("Output options: \\ Profiles:",1,3,1,1)
dd_profile = d:add_dropdown(2,3,1,1)
for i,v in ipairs(profiles) do
dd_profile:add_value(v[1],i)
end
d:add_button("Apply profile", click_Profile, 3,3,1,1)
d:add_label("(Media > Stream... wizard)",4,3,1,1)

ti_sout_string = d:add_text_input(profiles[1][2], 1,4,5,1)

d:add_button("Enqueue converting tracks", click_Convert, 2,5,1,1)
d:add_label("Then start the 1st converting track in playlist (View > Playlist).",3,5,2,1)
end

function click_Profile()
ti_sout_string:set_text(profiles[dd_profile:get_value()][2])
end

function click_Convert()
local j=tonumber(ti_tracks:get_text())
if not j then j=1 ti_tracks:set_text(j) end
local source_string = ti_mrl:get_text()
local options_string = ti_sout_string:get_text()
local table_items={}
table.insert(table_items,{path="vlc://pause:3", name="[Convert! START]", options={}})
for i=1,j do
table.insert(table_items,{path=source_string, name="[Convert!] Audio CD - Track "..i, options=SplitString(string.gsub(options_string,"%?",i), " :")})
end
table.insert(table_items,{path="vlc://pause:3", name="[Convert! END]", options={}})
vlc.playlist.enqueue(table_items)
end

-----

function SplitString(s, d) -- string, delimiter pattern
local t={}
local i=1
local ss, j, k
local b=false
while true do
j,k = string.find(s,d,i)
if j then
ss=string.sub(s,i,j-1)
i=k+1
else
ss=string.sub(s,i)
b=true
end
table.insert(t, ss)
if b then break end
end
return t
end

Discussions