This project is read-only.
How to use Xiph Media Encoder to encode PCM Wave files with the FLAC codec

Step 1

Step 1

Step 2

Step 2

Step 3

Step 3

"Filename pattern" allows the user to specify how the filename are built (without the extension of the file) using the corresponding patterns.

Patterns are made of indentificators. Those corresponding to official Vorbis Comment tags are : |artist|, |title|, |date|, |album|, |genre|, |tracknumber|, |contact|, |copyright|, |description|, |isrc|, |license|, |location|, |organization|, |performer| and |version|. Any other tag can be defined by putting its name between |. Finally, the indicator |fake| will allow you to ignore an element in the filename. You can use personalised identificators like |tag_name| and |fake| to ignore an element with no relevant information.

To define the path of a file in the "Folder pattern", just specify the folders where the tags are (you do not need to start at the root of the partition) and go up to where the files are. The different folders must be separated by an anti-slash.

A contextual menu is here to help you to add identificators. The files will be automatically tagged.

Step 4

Step 4

"Folder pattern" is used to specify where the files will be saved. The complete path must be typed, and it can include identificators.

"Filename pattern" is used to specify how filenames will be built, using patterns once more. It is possible to add conditional blocks by surrounding the identificators with < and >. If one of the tags was to be missing, the whole block would be ignored. It is useful to avoid to have characters surrounding a missing tag.

The software will create the directories and sub-directories if needed.

Step 5

Step 5

The generated script

Xiph Media Encoder will generate the following PowerShell script. The PowerShell templates used by the software can be found in the "Templates" folder and customized. The generated script will be saved and can be run immediately or later.

# Scenario : encode Wave PCM files to FLAC
# Copyright 2007-2010, Cyber Sinh, www.luminescence-software.org
# Version 2.0 (2010-09-26)

#################################################################
$source = "D:\Téléchargement\Wave"
$recursive = $true
$input_file = "|artist| - |title| - |album| - |tracknumber| - |genre| - |date|"
$input_folder = ""
$output_file = "|tracknumber| - |title|"
$output_folder = "D:\Téléchargement\FLAC\|artist|\|album|"
$options = "--no-ogg"
$max_encoding = [Environment]::ProcessorCount
$priority = "Normal"
$shutdown = $false
$hibernate = $false
#################################################################

Clear-Host

$bin = Split-Path $MyInvocation.MyCommand.Definition -Parent

[Reflection.Assembly]::LoadFrom("$bin\Functions.dll") | Out-Null

$encoder = "flac"
$flac = "$bin\Encoders\Generic\$encoder.exe"
if ([XiphMediaEncoder.TagProcessor]::IsProcessorFeaturePresent([XiphMediaEncoder.ProcessorFeature]::SSE2)) 
{ $flac = "$bin\Encoders\SSE2\$encoder.exe" }   
 
if ($recursive) { $files = Get-ChildItem $source -Include *.wav -Recurse }
else { $files = Get-ChildItem $source -Include *.wav }

$i = 0
$count = $files.Length

foreach ($file in $files)
{
   $i++
   Write-Progress -Activity "Encoding Wave PCM files to FLAC ($i / $count)..." -Status "$file" -PercentComplete ($i / $count * 100)
   
   $tags = [XiphMediaEncoder.TagProcessor]::TagFromFilename($null, $input_file, $file)
   $tags = [XiphMediaEncoder.TagProcessor]::TagFromPath($tags, $input_folder, $file)
   
   if (![String]::IsNullOrEmpty($output_folder))
   {
      $folder = [XiphMediaEncoder.TagProcessor]::PathFromTags($output_folder, $tags)
      if (![System.IO.Directory]::Exists($folder)) { [System.IO.Directory]::CreateDirectory($folder) | Out-Null }
   }
   else
   {
      $folder = [System.IO.Path]::GetDirectoryName($file)
   }
   
   $filename = [System.IO.Path]::GetFileNameWithoutExtension($file)
   if (![String]::IsNullOrEmpty($output_file))
   {
      $buffer = [XiphMediaEncoder.TagProcessor]::FileNameFromTags($output_file, $tags)
      if ($buffer -ne $null) { $filename = $buffer }
   }
   
   if ($options.Contains("--ogg")) { $filename += ".ogg" }
   else { $filename += ".flac" }
   
   $args_tags = ""
   for ($j = 0; $j -lt $tags.Count; $j++)
   {
      foreach ($value in $tags.Values[$j])
      {
	     $args_tags += "--tag=""$($tags.Keys[$j])=$value"" "
      }
   }
   
   $output = [System.IO.Path]::Combine($folder, $filename)
   
   $startInfo = New-Object -TypeName Diagnostics.ProcessStartInfo
   $startInfo.FileName = $flac
   $startInfo.Arguments="""$file"" --best --force --silent $options $args_tags --output-name=""$output"""   
   $startInfo.UseShellExecute = $false
   $startInfo.RedirectStandardOutput = $true
       
   $proc = [System.Diagnostics.Process]::Start($startInfo)
   $proc.PriorityClass = $priority

   $nb_instance = (Get-Process | Where-Object { $_.ProcessName -eq $encoder }).Length
   while ($nb_instance -ge $max_encoding)
   {
      Start-Sleep -Milliseconds 500
      $nb_instance = (Get-Process | Where-Object { $_.ProcessName -eq $encoder }).Length
   }
}

Write-Host "Encoding completes."

if ($shutdown) 
{ 
    shutdown /s /t 3
    exit 
}

if ($hibernate) 
{ 
    shutdown /h /t 3 
    exit
}

Last edited Nov 13, 2010 at 12:41 AM by Cyber_Sinh, version 8

Comments

No comments yet.