SRT packetizer: add hack for disabling stripping whitespaces

The hack is called `keep_whitespaces_in_text_subtitles`.

Part of the implementation of #3470.
This commit is contained in:
Moritz Bunkus 2023-01-15 19:15:41 +01:00
parent 4139dba750
commit 95fc41c833
No known key found for this signature in database
GPG Key ID: 74AF00ADF2E32C85
5 changed files with 20 additions and 5 deletions

View File

@ -1,5 +1,12 @@
# Version ?
## New features and enhancements
* mkvmerge: SRT handling: added a hack called `--engage
keep_whitespaces_in_text_subtitles` which disables stripping whitespaces
from the start & end of each line of SRT entries during muxing. Part of the
implementation of #3470.
## Bug fixes
* build system: fixed compatibility with Ruby 3.2.0 by using `FileTest.exist?`

View File

@ -65,6 +65,8 @@ get_list() {
Y("The resulting tracks will be broken: the official FLAC tools will not be able to decode them and seeking will not work as expected.") });
hacks.emplace_back("dont_normalize_parameter_sets", svec{ Y("Normally the HEVC/H.265 code in mkvmerge and mkvextract normalizes parameter sets by prefixing all key frames with all currently active parameter sets and removes duplicates that might already be present."),
Y("If this hack is enabled, the code will leave the parameter sets as they are.") });
hacks.emplace_back("keep_whitespaces_in_text_subtitles", svec{ Y("Normally spaces & tabs are removed from the beginning & the end of each line in text subtitles."),
Y("If this hack is enabled, they won't be removed.") });
hacks.emplace_back("cow", svec{ Y("No help available.") });

View File

@ -45,7 +45,8 @@ constexpr unsigned int KEEP_TRACK_STATISTICS_TAGS = 20;
constexpr unsigned int ALL_I_SLICES_ARE_KEY_FRAMES = 21;
constexpr unsigned int APPEND_AND_SPLIT_FLAC = 22;
constexpr unsigned int DONT_NORMALIZE_PARAMETER_SETS = 23;
constexpr unsigned int MAX_IDX = 23;
constexpr unsigned int KEEP_WHITESPACES_IN_TEXT_SUBTITLES = 24;
constexpr unsigned int MAX_IDX = 24;
}
struct hack_t {

View File

@ -17,6 +17,7 @@
#include "common/codec.h"
#include "common/debugging.h"
#include "common/hacks.h"
#include "common/qt.h"
#include "common/strings/editing.h"
#include "common/strings/parsing.h"
@ -33,6 +34,7 @@ textsubs_packetizer_c::textsubs_packetizer_c(generic_reader_c *p_reader,
const char *codec_id,
bool recode)
: generic_packetizer_c(p_reader, p_ti)
, m_strip_whitespaces{!mtx::hacks::is_engaged(mtx::hacks::KEEP_WHITESPACES_IN_TEXT_SUBTITLES)}
, m_codec_id{codec_id}
{
if (recode) {
@ -91,9 +93,12 @@ textsubs_packetizer_c::process_impl(packet_cptr const &packet) {
subs = mtx::string::normalize_line_endings(subs, m_line_ending_style);
auto q_subs = Q(subs);
q_subs.replace(QRegularExpression{Q("^[ \t]+|[ \t]+$"), QRegularExpression::MultilineOption}, {});
q_subs.replace(QRegularExpression{Q("[ \t]+\r")}, Q("\r"));
q_subs.replace(QRegularExpression{Q("[\r\n]+\\z")}, {});
if (m_strip_whitespaces) {
q_subs.replace(QRegularExpression{Q("^[ \t]+|[ \t]+$"), QRegularExpression::MultilineOption}, {});
q_subs.replace(QRegularExpression{Q("[ \t]+\r")}, Q("\r"));
q_subs.replace(QRegularExpression{Q("[\r\n]+\\z")}, {});
}
if (q_subs.isEmpty())
return;

View File

@ -23,7 +23,7 @@ protected:
unsigned int m_packetno{};
std::optional<unsigned int> m_force_rerender_track_headers_on_packetno;
charset_converter_cptr m_cc_utf8;
bool m_try_utf8{}, m_invalid_utf8_warned{}, m_converter_is_utf8{};
bool m_try_utf8{}, m_invalid_utf8_warned{}, m_converter_is_utf8{}, m_strip_whitespaces{};
std::string m_codec_id;
mtx::string::line_ending_style_e m_line_ending_style{mtx::string::line_ending_style_e::cr_lf};
packet_cptr m_buffered_packet;