mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-25 04:11:44 +00:00
Split the --split parser function into separate onces for duration and size type arguments. Another preparation for splitting by other criteria.
This commit is contained in:
parent
62f78d92fb
commit
45ace4b5ea
@ -642,36 +642,35 @@ parse_cropping(const string &s,
|
|||||||
ti.pixel_crop_list.push_back(crop);
|
ti.pixel_crop_list.push_back(crop);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Parse the \c --split argument
|
/** \brief Parse the duration formats to \c --split
|
||||||
|
|
||||||
The \c --split option takes several formats.
|
This function is called by ::parse_split if the format specifies
|
||||||
|
a duration after which a new file should be started.
|
||||||
\arg size based: If only a number is given or the number is
|
|
||||||
postfixed with '<tt>K</tt>', '<tt>M</tt>' or '<tt>G</tt>' this is
|
|
||||||
interpreted as the size after which to split.
|
|
||||||
|
|
||||||
\arg time based: If a number postfixed with '<tt>s</tt>' or in a
|
|
||||||
format matching '<tt>HH:MM:SS</tt>' or '<tt>HH:MM:SS.mmm</tt>' is
|
|
||||||
given then this is interpreted as the time after which to split.
|
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
parse_split(const string &arg) {
|
parse_split_duration(const string &arg) {
|
||||||
int64_t split_after, modifier;
|
int secs, mins, hours, msecs;
|
||||||
char mod;
|
int64_t split_after;
|
||||||
string s;
|
string s = arg;
|
||||||
|
|
||||||
if (arg.size() < 2)
|
if (starts_with_case(s, "duration:"))
|
||||||
mxerror(_("Invalid format for '--split' in '--split %s'.\n"), arg.c_str());
|
s.erase(0, strlen("duration:"));
|
||||||
|
|
||||||
s = arg;
|
// Number of seconds postfixed by 's'.
|
||||||
|
if (!s.empty() && ('s' == s[s.length() - 1])) {
|
||||||
|
s.erase(s.length() - 1);
|
||||||
|
if (!parse_int(s, split_after))
|
||||||
|
mxerror(_("Invalid time for '--split' in '--split %s'.\n"),
|
||||||
|
arg.c_str());
|
||||||
|
|
||||||
|
split_after *= 1000;
|
||||||
|
cluster_helper->add_split_point(split_point_t(split_after,
|
||||||
|
split_point_t::SPT_DURATION,
|
||||||
|
false));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// HH:MM:SS
|
// HH:MM:SS
|
||||||
if (((s.size() == 8) || (s.size() == 12)) &&
|
|
||||||
(s[2] == ':') && (s[5] == ':') &&
|
|
||||||
isdigit(s[0]) && isdigit(s[1]) && isdigit(s[3]) &&
|
|
||||||
isdigit(s[4]) && isdigit(s[6]) && isdigit(s[7])) {
|
|
||||||
int secs, mins, hours, msecs;
|
|
||||||
|
|
||||||
if (s.size() == 12) {
|
if (s.size() == 12) {
|
||||||
if ((s[8] != '.') || !parse_int(s.substr(9), msecs))
|
if ((s[8] != '.') || !parse_int(s.substr(9), msecs))
|
||||||
mxerror(_("Invalid time for '--split' in '--split %s'.\n"),
|
mxerror(_("Invalid time for '--split' in '--split %s'.\n"),
|
||||||
@ -689,26 +688,27 @@ parse_split(const string &arg) {
|
|||||||
cluster_helper->add_split_point(split_point_t(split_after,
|
cluster_helper->add_split_point(split_point_t(split_after,
|
||||||
split_point_t::SPT_DURATION,
|
split_point_t::SPT_DURATION,
|
||||||
false));
|
false));
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mod = tolower(s[s.size() - 1]);
|
/** \brief Parse the size format to \c --split
|
||||||
|
|
||||||
// Number of seconds: e.g. 1000s or 4254S
|
This function is called by ::parse_split if the format specifies
|
||||||
if (mod == 's') {
|
a size after which a new file should be started.
|
||||||
s.erase(s.size() - 1);
|
*/
|
||||||
if (!parse_int(s, split_after))
|
static void
|
||||||
mxerror(_("Invalid time for '--split' in '--split %s'.\n"),
|
parse_split_size(const string &arg) {
|
||||||
arg.c_str());
|
int64_t modifier, split_after;
|
||||||
|
string s = arg;
|
||||||
|
char mod;
|
||||||
|
|
||||||
split_after *= 1000;
|
if (starts_with_case(s, "size:"))
|
||||||
cluster_helper->add_split_point(split_point_t(split_after,
|
s.erase(0, strlen("size:"));
|
||||||
split_point_t::SPT_DURATION,
|
|
||||||
false));
|
if (s.empty())
|
||||||
return;
|
mxerror(_("Invalid split size in '--split %s'.\n"), arg.c_str());
|
||||||
}
|
|
||||||
|
|
||||||
// Size in bytes/KB/MB/GB
|
// Size in bytes/KB/MB/GB
|
||||||
|
mod = s[s.length() - 1];
|
||||||
modifier = 1;
|
modifier = 1;
|
||||||
if (mod == 'k')
|
if (mod == 'k')
|
||||||
modifier = 1024;
|
modifier = 1024;
|
||||||
@ -718,6 +718,7 @@ parse_split(const string &arg) {
|
|||||||
modifier = 1024 * 1024 * 1024;
|
modifier = 1024 * 1024 * 1024;
|
||||||
else if (!isdigit(mod))
|
else if (!isdigit(mod))
|
||||||
mxerror(_("Invalid split size in '--split %s'.\n"), arg.c_str());
|
mxerror(_("Invalid split size in '--split %s'.\n"), arg.c_str());
|
||||||
|
|
||||||
if (modifier != 1)
|
if (modifier != 1)
|
||||||
s.erase(s.size() - 1);
|
s.erase(s.size() - 1);
|
||||||
if (!parse_int(s, split_after))
|
if (!parse_int(s, split_after))
|
||||||
@ -728,6 +729,58 @@ parse_split(const string &arg) {
|
|||||||
false));
|
false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** \brief Parse the \c --split argument
|
||||||
|
|
||||||
|
The \c --split option takes several formats.
|
||||||
|
|
||||||
|
\arg size based: If only a number is given or the number is
|
||||||
|
postfixed with '<tt>K</tt>', '<tt>M</tt>' or '<tt>G</tt>' this is
|
||||||
|
interpreted as the size after which to split.
|
||||||
|
This format is parsed by ::parse_split_size
|
||||||
|
|
||||||
|
\arg time based: If a number postfixed with '<tt>s</tt>' or in a
|
||||||
|
format matching '<tt>HH:MM:SS</tt>' or '<tt>HH:MM:SS.mmm</tt>' is
|
||||||
|
given then this is interpreted as the time after which to split.
|
||||||
|
This format is parsed by ::parse_split_duration
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parse_split(const string &arg) {
|
||||||
|
string s;
|
||||||
|
|
||||||
|
if (arg.size() < 2)
|
||||||
|
mxerror(_("Invalid format for '--split' in '--split %s'.\n"), arg.c_str());
|
||||||
|
|
||||||
|
s = arg;
|
||||||
|
|
||||||
|
// HH:MM:SS
|
||||||
|
if (starts_with_case(s, "duration:"))
|
||||||
|
parse_split_duration(arg);
|
||||||
|
|
||||||
|
else if (starts_with_case(s, "size:"))
|
||||||
|
parse_split_size(arg);
|
||||||
|
|
||||||
|
else if (((s.size() == 8) || (s.size() == 12)) &&
|
||||||
|
(s[2] == ':') && (s[5] == ':') &&
|
||||||
|
isdigit(s[0]) && isdigit(s[1]) && isdigit(s[3]) &&
|
||||||
|
isdigit(s[4]) && isdigit(s[6]) && isdigit(s[7]))
|
||||||
|
// HH:MM:SS
|
||||||
|
parse_split_duration(arg);
|
||||||
|
|
||||||
|
else {
|
||||||
|
char mod = tolower(s[s.size() - 1]);
|
||||||
|
|
||||||
|
if ('s' == mod)
|
||||||
|
parse_split_duration(arg);
|
||||||
|
|
||||||
|
else if (('k' == mod) || ('m' == mod) || ('g' == mod) || isdigit(mod))
|
||||||
|
parse_split_size(arg);
|
||||||
|
|
||||||
|
else
|
||||||
|
mxerror(_("Invalid format for '--split' in '--split %s'.\n"),
|
||||||
|
arg.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** \brief Parse the \c --delay argument
|
/** \brief Parse the \c --delay argument
|
||||||
|
|
||||||
time based: A number that must be postfixed with <tt>s</tt>,
|
time based: A number that must be postfixed with <tt>s</tt>,
|
||||||
|
Loading…
Reference in New Issue
Block a user