未验证 提交 b98211a3 编写于 作者: D dinatih 提交者: GitHub

Add quotes to pathname arguments for `ffmpeg` and `mv` command in videoSaver.cpp (#1450)

上级 28d14069
...@@ -86,7 +86,7 @@ namespace op ...@@ -86,7 +86,7 @@ namespace op
if (upImpl->mUseFfmpeg) if (upImpl->mUseFfmpeg)
error("MP4 recording requires an Ubuntu or Mac machine.", __LINE__, __FUNCTION__, __FILE__); error("MP4 recording requires an Ubuntu or Mac machine.", __LINE__, __FUNCTION__, __FILE__);
#endif #endif
if (upImpl->mUseFfmpeg && system("ffmpeg --help") != 0) if (upImpl->mUseFfmpeg && system("ffmpeg -version") != 0)
error("In order to save the video in MP4 format, FFmpeg must be installed on your system." error("In order to save the video in MP4 format, FFmpeg must be installed on your system."
" Please, use an `avi` output format (e.g., `--write_video output.avi`) or install FFmpeg" " Please, use an `avi` output format (e.g., `--write_video output.avi`) or install FFmpeg"
" by running `sudo apt-get install ffmpeg` (Ubuntu) or an analogous command.", " by running `sudo apt-get install ffmpeg` (Ubuntu) or an analogous command.",
...@@ -116,16 +116,16 @@ namespace op ...@@ -116,16 +116,16 @@ namespace op
// Very important: Either FPS flag must go before `-i`!!! Otherwise, it would either not work (`-r`) // Very important: Either FPS flag must go before `-i`!!! Otherwise, it would either not work (`-r`)
// or do a weird resample (`-framerate`) // or do a weird resample (`-framerate`)
const std::string imageToVideoCommand = "ffmpeg -y -framerate " + std::to_string(upImpl->mFps) const std::string imageToVideoCommand = "ffmpeg -y -framerate " + std::to_string(upImpl->mFps)
+ " -i " + upImpl->mTempImageFolder + "/%12d_rendered.jpg" + " -i '" + upImpl->mTempImageFolder + "/%12d_rendered.jpg'"
+ " -c:v libx264 -pix_fmt yuv420p " + " -c:v libx264 -pix_fmt yuv420p '"
+ upImpl->mVideoSaverPath; + upImpl->mVideoSaverPath + "'";
opLog("Creating MP4 video out of JPG images by running:\n" + imageToVideoCommand + "\n", opLog("Creating MP4 video out of JPG images by running:\n" + imageToVideoCommand + "\n",
op::Priority::High); op::Priority::High);
auto codeAnswerVideo = system(imageToVideoCommand.c_str()); auto codeAnswerVideo = system(imageToVideoCommand.c_str());
// Remove temporary images // Remove temporary images
if (codeAnswerVideo == 0) if (codeAnswerVideo == 0)
{ {
codeAnswerVideo = system(("rm -rf " + upImpl->mTempImageFolder).c_str()); codeAnswerVideo = system(("rm -rf '" + upImpl->mTempImageFolder + "'").c_str());
opLog("Video saved and temporary image folder removed.", op::Priority::High); opLog("Video saved and temporary image folder removed.", op::Priority::High);
} }
// Sanity check // Sanity check
...@@ -137,13 +137,13 @@ namespace op ...@@ -137,13 +137,13 @@ namespace op
if (!upImpl->mAddAudioFromThisVideo.empty()) if (!upImpl->mAddAudioFromThisVideo.empty())
{ {
const auto tempOutput = upImpl->mVideoSaverPath + RANDOM_TEXT + ".mp4"; const auto tempOutput = upImpl->mVideoSaverPath + RANDOM_TEXT + ".mp4";
const auto audioCommand = "ffmpeg -y -i " + upImpl->mVideoSaverPath const auto audioCommand = "ffmpeg -y -i '" + upImpl->mVideoSaverPath
+ " -i " + upImpl->mAddAudioFromThisVideo + " -codec copy -shortest " + tempOutput; + "' -i '" + upImpl->mAddAudioFromThisVideo + "' -codec copy -shortest '" + tempOutput + "'";
opLog("Adding audio to video by running:\n" + audioCommand, op::Priority::High); opLog("Adding audio to video by running:\n" + audioCommand, op::Priority::High);
auto codeAnswerAudio = system(audioCommand.c_str()); auto codeAnswerAudio = system(audioCommand.c_str());
// Move temp output to real output // Move temp output to real output
if (codeAnswerAudio == 0) if (codeAnswerAudio == 0)
codeAnswerAudio = system(("mv " + tempOutput + " " + upImpl->mVideoSaverPath).c_str()); codeAnswerAudio = system(("mv '" + tempOutput + "' '" + upImpl->mVideoSaverPath + "'").c_str());
// Sanity check // Sanity check
if (codeAnswerAudio != 0) if (codeAnswerAudio != 0)
opLog("\nVideo " + upImpl->mVideoSaverPath + " could not be saved with audio (exit code: " opLog("\nVideo " + upImpl->mVideoSaverPath + " could not be saved with audio (exit code: "
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册