From dd9f4ac890aa4f48068602dd96068ad255a94c4c Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Tue, 7 Dec 2021 09:29:45 +0000 Subject: [PATCH] src/: fail --load-tape-create-video if video encoding fails. Also fail video encoding if output file already exists. --- src/Aircraft/replay-internal.cxx | 15 ++++++++---- src/Viewer/viewmgr.cxx | 9 +++++++- src/Viewer/viewmgr.hxx | 39 +++++++++++++++++++++----------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/Aircraft/replay-internal.cxx b/src/Aircraft/replay-internal.cxx index cb0ae30f5..5d82f7eb0 100644 --- a/src/Aircraft/replay-internal.cxx +++ b/src/Aircraft/replay-internal.cxx @@ -1783,13 +1783,15 @@ bool loadTapeContinuous( { continuous->m_replay_fixed_dt_prev = -1; } - if (continuous->m_replay_create_video) + + bool ok = true; + if (ok && continuous->m_replay_create_video) { SG_LOG(SG_GENERAL, SG_ALERT, "Replaying with create-video"); auto view_mgr = globals->get_subsystem(); if (view_mgr) { - view_mgr->video_start( + ok = view_mgr->video_start( "" /*name*/, "" /*codec*/, -1 /*quality*/, @@ -1797,9 +1799,14 @@ bool loadTapeContinuous( 0 /*bitrate*/ ); } + else + { + SG_LOG(SG_GENERAL, SG_ALERT, "Cannot handle create_video=true because FGViewMgr not available"); + ok = false; + } } - replay_internal.start(true /*new_tape*/); - return true; + if (ok) ok = replay_internal.start(true /*new_tape*/); + return ok; } /** Read a flight recorder tape with given filename from disk. diff --git a/src/Viewer/viewmgr.cxx b/src/Viewer/viewmgr.cxx index 9d0a6b429..1f3a4096e 100644 --- a/src/Viewer/viewmgr.cxx +++ b/src/Viewer/viewmgr.cxx @@ -366,7 +366,7 @@ FGViewMgr::add_view( flightgear::View * v ) v->init(); } -void FGViewMgr::video_start( +bool FGViewMgr::video_start( const std::string& name_in, const std::string& codec_in, double quality, @@ -413,6 +413,11 @@ void FGViewMgr::video_start( SGPath path = SGPath(fgGetString("/sim/video/directory")); SGPath path_link = path; path.append(name); + if (path.exists()) + { + videoEncodingError("Video encoding failure, output file already exists: " + path.str()); + return false; + } path_link.append(name_link); path_link.remove(); bool ok = path_link.makeLink(path.file()); @@ -464,7 +469,9 @@ void FGViewMgr::video_start( catch (std::exception& e) { videoEncodingError(e.what()); + return false; } + return true; } void FGViewMgr::video_stop() diff --git a/src/Viewer/viewmgr.hxx b/src/Viewer/viewmgr.hxx index 464bdfb83..42d520238 100644 --- a/src/Viewer/viewmgr.hxx +++ b/src/Viewer/viewmgr.hxx @@ -94,25 +94,38 @@ public: void add_view( flightgear::View * v ); - // Start video encoding to . + // Start video encoding of main window. // - // If is "" we generate a name containing current date and time. - // - // If is "" we use /sim/video/codec. - // - // If quality is -1 we use /sim/video/quality; similarly for speed. If - // bitrate is 0 we use /sim/video/bitrate. + // name + // Name of output file or "" to generate a name containing current + // date and time and /sim/video/container. List of supported + // containers can be found with 'ffmpeg -formats'. + // codec_name + // Name of codec or "" to use /sim/video/codec. Passed to + // avcodec_find_encoder_by_name(). List of supported codecs can be + // found with 'ffmpeg -codecs'. + // quality + // Encoding quality in range 0..1 or -1 to use /sim/video/quality. + // speed: + // Encoding speed in range 0..1 or -1 to use /sim/video/speed. + // bitrate + // Target bitratae in bits/sec or -1 to use /sim/video/bitrate. // // We show popup warning if values are out of range - quality and speed // must be -1 or 0-1, bitrate must be >= 0. // - void video_start( - const std::string& name, - const std::string& codec, - double quality, - double speed, - int bitrate + // Returns false if we fail to start video encoding. + // + bool video_start( + const std::string& name="", + const std::string& codec="", + double quality=-1, + double speed=-1, + int bitrate=0 ); + + // Stop video encoding of main window. + // void video_stop(); private: