1
0
Fork 0

src/Viewer/viewmgr.*: fixed bug when /sim/aircraft contains '.' chars.

We were not appending the video container suffix if there was already a '.' in
the name.

Part of this fix is also to simplify the code - if name_in is not "" we don't
attempt to create softlink or append /sim/video/container.
This commit is contained in:
Julian Smith 2022-06-05 18:42:34 +01:00
parent 55c9c61fc3
commit 28d7308985
2 changed files with 43 additions and 32 deletions

View file

@ -413,42 +413,46 @@ bool FGViewMgr::video_start(
<< " bitrate=" << bitrate << " bitrate=" << bitrate
); );
globals->get_props()->setIntValue("/sim/video/error", 0); globals->get_props()->setIntValue("/sim/video/error", 0);
std::string name = name_in;
std::string codec = codec_in;
std::string name_link = std::string("fgvideo-") + fgGetString("/sim/aircraft"); std::string name;
std::string name_link;
if (name == "") if (name_in == "")
{ {
/* Use a default name containing current date and time. */ /* Use a default name containing aircraft-name, current date and time
and the configured video container. */
time_t calendar_time = time(NULL); time_t calendar_time = time(NULL);
struct tm* local_tm = localtime(&calendar_time); struct tm* local_tm = localtime(&calendar_time);
char buffer[256]; char time_string[256];
strftime(buffer, sizeof(buffer), "-%Y%m%d-%H%M%S", local_tm); strftime(time_string, sizeof(time_string), "-%Y%m%d-%H%M%S", local_tm);
name = name_link + buffer;
} std::string suffix = "." + fgGetString("/sim/video/container", "mpeg");
size_t dot = name.find(".");
if (dot == std::string::npos) name = std::string("fgvideo-") + fgGetString("/sim/aircraft");
{ name_link = name + suffix;
/* No suffix specified. We need one because it determines the video name += time_string + suffix;
container format. */
std::string container = fgGetString("/sim/video/container", "mpeg");
name += "." + container;
name_link += "." + container;
} }
else else
{ {
// Give link the same suffix. /* We assume <name_in> already has the desired suffix. We leave
name_link += name.substr(dot); name_link empty so we don't attempt to create a link. */
name = name_in;
} }
SGPath path = SGPath(fgGetString("/sim/video/directory"));
SGPath path_link = path; std::string codec = codec_in;
string directory = fgGetString("/sim/video/directory");
SGPath path = SGPath(directory);
path.append(name); path.append(name);
if (path.exists()) if (path.exists())
{ {
videoEncodingError("Video encoding failure, output file already exists: " + path.str()); videoEncodingError("Video encoding failure, output file already exists: " + path.str());
return false; return false;
} }
SGPath path_link;
if (name_link != "")
{
path_link = SGPath(directory);
path_link.append(name_link); path_link.append(name_link);
path_link.remove(); path_link.remove();
bool ok = path_link.makeLink(path.file()); bool ok = path_link.makeLink(path.file());
@ -458,7 +462,7 @@ bool FGViewMgr::video_start(
<< path_link.c_str() << " => " << path.file() << path_link.c_str() << " => " << path.file()
); );
} }
}
if (codec == "") codec = fgGetString("/sim/video/codec"); if (codec == "") codec = fgGetString("/sim/video/codec");
if (quality == -1) quality = fgGetDouble("/sim/video/quality"); if (quality == -1) quality = fgGetDouble("/sim/video/quality");
if (speed == -1) speed = fgGetDouble("/sim/video/speed"); if (speed == -1) speed = fgGetDouble("/sim/video/speed");

View file

@ -97,9 +97,16 @@ public:
// Start video encoding of main window. // Start video encoding of main window.
// //
// name // name
// Name of output file or "" to generate a name containing current // If "", we generate a name containing aircraft name, date and
// date and time and /sim/video/container. List of supported // time and with suffix /sim/video/container, and we also create a
// containers can be found with 'ffmpeg -formats'. // softlink with the same name excluding date and time. Both names are
// converted into paths by prepending with /sim/video/directory.
//
// Otherwise we prepend with /sim/video/directory, and do not create
// a softlink. In this case, <name> should end with a name that is a
// recognised video container, such as '.mp4'.
//
// List of supported containers can be found with 'ffmpeg -formats'.
// codec_name // codec_name
// Name of codec or "" to use /sim/video/codec. Passed to // Name of codec or "" to use /sim/video/codec. Passed to
// avcodec_find_encoder_by_name(). List of supported codecs can be // avcodec_find_encoder_by_name(). List of supported codecs can be