|
From: Lasse Kärkkäi. <tr...@us...> - 2010-09-28 09:52:37
|
Module: performous
Branch: ssxml
Commit: cf4c583dd5d9d559cc4b612aedc95ddd76ab3fbd
Author: Lasse Karkkainen <tro...@tr...>
Date: Tue Sep 28 12:39:19 2010 +0300
-Fixed uppercased "Notes (Singer).txt" (should be "notes (Singer).txt" like "notes.txt" and "notes.xml")
-Fixed and enabled mkv/H.264 compression (not tested on systems with no H.264 support)
-Improved Vorbis quality (was q=3 around 100 kbit/s, now q=5 around 160 kbit/s)
-Prettyprinting filenames now removes question marks rather than substituting with underscores
---
tools/ss_extract.cpp | 21 +++++++++++----------
tools/ss_helpers.hh | 12 ++++++++----
2 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/tools/ss_extract.cpp b/tools/ss_extract.cpp
index dd5162b..43ba7cc 100644
--- a/tools/ss_extract.cpp
+++ b/tools/ss_extract.cpp
@@ -38,7 +38,7 @@ std::ofstream txtfile;
int ts = 0;
int sleepts = -1;
const bool video = true;
-const bool mkvcompress = false;
+const bool mkvcompress = true;
const bool oggcompress = true;
void parseNote(xmlpp::Node* node) {
@@ -91,7 +91,7 @@ void saveTxtFile(xmlpp::NodeSet &sentence, const fs::path &path, const Song &son
file_path = path / "notes.txt";
} else {
file_path = path;
- file_path /= safename(std::string("notes") + " (" + singer + ")" + ".txt");
+ file_path /= "notes (" + safename(singer) + ").txt";
}
txtfile.open(file_path.string().c_str());
if( singer.empty() )
@@ -175,7 +175,7 @@ struct Process {
if (oggcompress) {
if( !song.music.empty() ) {
std::cerr << ">>> Compressing audio into music.ogg" << std::endl;
- std::string cmd = "oggenc \"" + song.music.string() + "\"";
+ std::string cmd = "oggenc -q 5 \"" + song.music.string() + "\"";
std::cerr << cmd << std::endl;
if (std::system(cmd.c_str()) == 0) { // FIXME: std::system return value is not portable
fs::remove(song.music);
@@ -184,7 +184,7 @@ struct Process {
}
if( !song.vocals.empty() ) {
std::cerr << ">>> Compressing audio into vocals.ogg" << std::endl;
- std::string cmd = "oggenc \"" + song.vocals.string() + "\"";
+ std::string cmd = "oggenc -q 5 \"" + song.vocals.string() + "\"";
std::cerr << cmd << std::endl;
if (std::system(cmd.c_str()) == 0) { // FIXME: std::system return value is not portable
fs::remove(song.vocals);
@@ -206,16 +206,17 @@ struct Process {
video_us(song, dataPak[id + "/mus+vid.iav"], dataPak[id + "/mus+vid.ind"], path);
} catch (std::exception& e) {
std::cerr << "!!! Unable to extract video: " << e.what() << std::endl;
- song.video = "";
+ song.video.clear();
}
}
- if (mkvcompress) {
- std::cerr << ">>> Compressing video and audio into music.mkv" << std::endl;
- std::string cmd = "ffmpeg -i \"" + (path / "video.mpg").string() + "\" -vcodec libx264 -vpre hq -crf 25 -threads 0 -metadata album=\"" + song.edition + "\" -metadata author=\"" + song.artist + "\" -metadata comment=\"" + song.genre + "\" -metadata title=\"" + song.title + "\" \"" + (path / "video.m4v\"").string();
+ if (mkvcompress && !song.video.empty()) {
+ std::cerr << ">>> Recompressing video into H.264 mkv" << std::endl;
+ fs::path compressed = path / "video.mkv";
+ std::string cmd = "ffmpeg -i \"" + song.video.string() + "\" -vcodec libx264 -vpre hq -crf 25 \"" + compressed.string() + "\"";
std::cerr << cmd << std::endl;
if (std::system(cmd.c_str()) == 0) { // FIXME: std::system return value is not portable
- fs::remove(path / "video.mpg");
- song.video = path / "video.m4v";
+ fs::remove(song.video);
+ song.video = compressed;
}
}
}
diff --git a/tools/ss_helpers.hh b/tools/ss_helpers.hh
index df447db..ece69cf 100644
--- a/tools/ss_helpers.hh
+++ b/tools/ss_helpers.hh
@@ -89,16 +89,20 @@ Glib::ustring normalize(Glib::ustring const& str) {
/** Sanitize a string into a form that can be safely used as a filename. **/
std::string safename(Glib::ustring const& str) {
Glib::ustring ret;
- Glib::ustring forbidden("\"*/:;<>?\\^`|~");
+ Glib::ustring forbidden("\"*/:;<>\\^`|~"); // Does not include those that have special handling
for (Glib::ustring::const_iterator it = str.begin(); it != str.end(); ++it) {
- bool first = it == str.begin();
+ bool first = (it == str.begin());
+ // Remove various dangerous characters
if (*it < 0x20) continue; // Control characters
if (*it >= 0x7F && *it < 0xA0) continue; // Additional control characters
- if (first && *it == '.') continue;
- if (first && *it == '-') continue;
+ if (first && *it == '.') continue; // Initial '.': a hidden file on UNIX
+ if (first && *it == '-') continue; // Initial '-': looks like a program option
+ // Replace forbidden punctuation with something prettier
+ if (*it == '?') continue;
if (*it == '&') { ret += " and "; continue; }
if (*it == '%') { ret += " percent "; continue; }
if (*it == '$') { ret += " dollar "; continue; }
+ // Replace any other punctuation with underscores
if (forbidden.find(*it) != Glib::ustring::npos) { ret += "_"; continue; }
ret += *it;
}
|