From 2734cab745f95e0e7c7b8a78beb46b80b43c69cc Mon Sep 17 00:00:00 2001 From: Alastair Porter Date: Wed, 9 May 2012 23:54:30 -0400 Subject: [PATCH 1/2] Quote filenames with single quotes on POSIX systems --- src/AudioStreamInput.h | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/AudioStreamInput.h b/src/AudioStreamInput.h index 47b9227..6a534d0 100644 --- a/src/AudioStreamInput.h +++ b/src/AudioStreamInput.h @@ -10,6 +10,7 @@ #include "Params.h" #include #include +#include #include #include "File.h" #if defined(_WIN32) && !defined(__MINGW32__) @@ -60,15 +61,29 @@ class FfmpegStreamInput : public AudioStreamInput { protected: std::string GetCommandLine(const char* filename) { // TODO: Windows - char message[4096] = {0}; - if (_Offset_s == 0 && _Seconds == 0) - snprintf(message, NELEM(message), "ffmpeg -i \"%s\" -ac %d -ar %d -f s16le - 2>%s", - filename, Params::AudioStreamInput::Channels, (uint) Params::AudioStreamInput::SamplingRate, DEVNULL); - else - snprintf(message, NELEM(message), "ffmpeg -i \"%s\" -ac %d -ar %d -f s16le -t %d -ss %d - 2>%s", - filename, Params::AudioStreamInput::Channels, (uint) Params::AudioStreamInput::SamplingRate, _Seconds, _Offset_s, DEVNULL); - - return std::string(message); + std::string filestr = std::string(filename); +#if defined(_WIN32) && !defined(__MINGW32__) +#else + std::string::size_type next; + std::string search = "'"; + std::string replace = "'\\''"; + for (next = filestr.find(search); next != std::string::npos; next = filestr.find(search, next)) { + filestr.replace(next, search.length(), replace); + next += replace.length(); + } +#endif + std::ostringstream message; + // ffmpeg -i '%s' -ac %d -ar %d -f s16le (-t %d -ss %d) - 2>DEVNULL + message << "ffmpeg -i '" << filestr << "' "; + message << "-ac " << Params::AudioStreamInput::Channels << " "; + message << "-ar " << (uint) Params::AudioStreamInput::SamplingRate << " "; + message << "-f s16le "; + if (_Offset_s > 0 && _Seconds > 0) { + message << "-t " << _Seconds << " "; + message << "-ss " << _Offset_s << " "; + } + message << "- 2> " << DEVNULL; + return message.str(); } }; From 44ab1d7c74bbb7c548c55de27a1fcb85a3cf13b7 Mon Sep 17 00:00:00 2001 From: Alastair Porter Date: Thu, 10 May 2012 15:30:12 -0400 Subject: [PATCH 2/2] Use double quotes on Windows, single on posix --- src/AudioStreamInput.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/AudioStreamInput.h b/src/AudioStreamInput.h index 6a534d0..4babf24 100644 --- a/src/AudioStreamInput.h +++ b/src/AudioStreamInput.h @@ -63,7 +63,9 @@ class FfmpegStreamInput : public AudioStreamInput { // TODO: Windows std::string filestr = std::string(filename); #if defined(_WIN32) && !defined(__MINGW32__) + std::string quote = "\""; #else + std::string quote = "'"; std::string::size_type next; std::string search = "'"; std::string replace = "'\\''"; @@ -74,7 +76,7 @@ class FfmpegStreamInput : public AudioStreamInput { #endif std::ostringstream message; // ffmpeg -i '%s' -ac %d -ar %d -f s16le (-t %d -ss %d) - 2>DEVNULL - message << "ffmpeg -i '" << filestr << "' "; + message << "ffmpeg -i " << quote << filestr << quote << " "; message << "-ac " << Params::AudioStreamInput::Channels << " "; message << "-ar " << (uint) Params::AudioStreamInput::SamplingRate << " "; message << "-f s16le ";