13
0

Fix ffmpeg-5+ encoding drop-frame framerates

This commit is contained in:
Robin Gareus 2023-12-13 06:41:33 +01:00
parent 9f3438b2bc
commit 1434c624ff
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 8 additions and 5 deletions

View File

@ -183,8 +183,10 @@ TranscodeFfmpeg::probe ()
} }
m_codec += "(" + value + ")"; m_codec += "(" + value + ")";
} else if (key == X_("r_frame_rate")) { } else if (key == X_("r_frame_rate")) {
m_fps_str = value;
PARSE_FRACTIONAL_FPS (m_fps) PARSE_FRACTIONAL_FPS (m_fps)
} else if (key == X_("avg_frame_rate") && m_fps == 0) { } else if (key == X_("avg_frame_rate") && m_fps == 0) {
m_fps_str = value;
PARSE_FRACTIONAL_FPS (m_fps) PARSE_FRACTIONAL_FPS (m_fps)
} else if (key == X_("time_base")) { } else if (key == X_("time_base")) {
PARSE_FRACTIONAL_FPS (timebase) PARSE_FRACTIONAL_FPS (timebase)
@ -338,7 +340,7 @@ TranscodeFfmpeg::encode (std::string outfile, std::string inf_a, std::string inf
argp[a++] = SystemExec::format_key_value_parameter (it->first.c_str (), it->second.c_str ()); argp[a++] = SystemExec::format_key_value_parameter (it->first.c_str (), it->second.c_str ());
} }
if (m_fps > 0) { if (m_fps > 0 && !m_fps_str.empty ()) {
m_lead_in = rint (m_lead_in * m_fps) / m_fps; m_lead_in = rint (m_lead_in * m_fps) / m_fps;
m_lead_out = rint (m_lead_out * m_fps) / m_fps; m_lead_out = rint (m_lead_out * m_fps) / m_fps;
} }
@ -346,12 +348,12 @@ TranscodeFfmpeg::encode (std::string outfile, std::string inf_a, std::string inf
if (m_lead_in != 0 && m_lead_out != 0) { if (m_lead_in != 0 && m_lead_out != 0) {
std::ostringstream osstream; std::ostringstream osstream;
argp[a++] = strdup ("-vf"); argp[a++] = strdup ("-vf");
osstream << "color=c=black:s=" << m_width << "x" << m_height << ":r=" << m_fps << ":d=" << m_lead_in; osstream << "color=c=black:s=" << m_width << "x" << m_height << ":r=" << m_fps_str << ":d=" << m_lead_in;
if (!m_sar.empty ()) { if (!m_sar.empty ()) {
osstream << ":sar=" << m_sar; osstream << ":sar=" << m_sar;
} }
osstream << " [pre]; "; osstream << " [pre]; ";
osstream << "color=c=black:s=" << m_width << "x" << m_height << ":r=" << m_fps << ":d=" << m_lead_out; osstream << "color=c=black:s=" << m_width << "x" << m_height << ":r=" << m_fps_str << ":d=" << m_lead_out;
if (!m_sar.empty ()) { if (!m_sar.empty ()) {
osstream << ":sar=" << m_sar; osstream << ":sar=" << m_sar;
} }
@ -361,7 +363,7 @@ TranscodeFfmpeg::encode (std::string outfile, std::string inf_a, std::string inf
} else if (m_lead_in != 0) { } else if (m_lead_in != 0) {
std::ostringstream osstream; std::ostringstream osstream;
argp[a++] = strdup ("-vf"); argp[a++] = strdup ("-vf");
osstream << "color=c=black:s=" << m_width << "x" << m_height << ":r=" << m_fps << ":d=" << m_lead_in; osstream << "color=c=black:s=" << m_width << "x" << m_height << ":r=" << m_fps_str << ":d=" << m_lead_in;
if (!m_sar.empty ()) { if (!m_sar.empty ()) {
osstream << ":sar=" << m_sar; osstream << ":sar=" << m_sar;
} }
@ -371,7 +373,7 @@ TranscodeFfmpeg::encode (std::string outfile, std::string inf_a, std::string inf
} else if (m_lead_out != 0) { } else if (m_lead_out != 0) {
std::ostringstream osstream; std::ostringstream osstream;
argp[a++] = strdup ("-vf"); argp[a++] = strdup ("-vf");
osstream << "color=c=black:s=" << m_width << "x" << m_height << ":r=" << m_fps << ":d=" << m_lead_out; osstream << "color=c=black:s=" << m_width << "x" << m_height << ":r=" << m_fps_str << ":d=" << m_lead_out;
if (!m_sar.empty ()) { if (!m_sar.empty ()) {
osstream << ":sar=" << m_sar; osstream << ":sar=" << m_sar;
} }

View File

@ -183,6 +183,7 @@ protected:
std::string infile; std::string infile;
ARDOUR::SystemExec* ffcmd; ARDOUR::SystemExec* ffcmd;
double m_fps; double m_fps;
std::string m_fps_str;
double m_aspect; double m_aspect;
std::string m_sar; std::string m_sar;
ARDOUR::samplecnt_t m_duration; ARDOUR::samplecnt_t m_duration;