From 1bd70c15a16fa4d4475fb7acabef5afd36fd1762 Mon Sep 17 00:00:00 2001 From: Ravi Mistry Date: Sat, 19 Nov 2022 22:01:34 +0000 Subject: [PATCH] Include recording seconds in SRT file --- srt.cc | 16 ++++++++++------ srt.h | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/srt.cc b/srt.cc index db3f4c1..fb74067 100644 --- a/srt.cc +++ b/srt.cc @@ -28,7 +28,7 @@ SubtitleWriter::SubtitleWriter() : frameRate( 0.0 ), - lastYear( 0 ), lastMonth( 0 ), lastDay( 0 ), lastHour( 0 ), lastMinute( 0 ), + lastYear( 0 ), lastMonth( 0 ), lastDay( 0 ), lastHour( 0 ), lastMinute( 0 ), lastSecond( 0 ), frameCount( 0 ), lastFrameWritten( 0 ), titleNumber( 1 ), timeCodeValid( false ) {} @@ -62,7 +62,7 @@ void SubtitleWriter::newFile ( const char *videoName ) os_tc.close(); frameRate = 0.0; - lastYear = lastMonth = lastDay = lastHour = lastMinute = 0; + lastYear = lastMonth = lastDay = lastHour = lastMinute = lastSecond = 0; frameCount = 0; lastFrameWritten = 0; titleNumber = 1; @@ -146,7 +146,8 @@ void SubtitleWriter::writeSubtitleFrame() os_fr << lastYear << '-' << std::setw( 2 ) << lastMonth << '-' << std::setw( 2 ) << lastDay << ' ' << std::setw( 2 ) << lastHour << ':' << std::setw( 2 ) - << lastMinute << "\n\n"; + << lastMinute << ':' << std::setw( 2 ) + << lastSecond << "\n\n"; os_fr.flush(); } @@ -170,14 +171,15 @@ void SubtitleWriter::writeSubtitleCode() os_tc << lastYear << '-' << std::setw( 2 ) << lastMonth << '-' << std::setw( 2 ) << lastDay << ' ' << std::setw( 2 ) << lastHour << ':' << std::setw( 2 ) - << lastMinute << "\n\n"; + << lastMinute << ':' << std::setw( 2 ) + << lastSecond << "\n\n"; os_tc.flush(); } } void SubtitleWriter::addRecordingDate ( struct tm &rd, const TimeCode &tc ) { - int y, m, d, hh, mm; + int y, m, d, hh, mm, ss; ++frameCount; y = rd.tm_year + 1900; @@ -185,9 +187,10 @@ void SubtitleWriter::addRecordingDate ( struct tm &rd, const TimeCode &tc ) d = rd.tm_mday; hh = rd.tm_hour; mm = rd.tm_min; + ss = rd.tm_sec; if ( y != lastYear || m != lastMonth || d != lastDay || - hh != lastHour || mm != lastMinute ) + hh != lastHour || mm != lastMinute || ss != lastSecond ) { // We must write a new subtitle. if ( lastYear != 0 ) @@ -202,6 +205,7 @@ void SubtitleWriter::addRecordingDate ( struct tm &rd, const TimeCode &tc ) lastDay = d; lastHour = hh; lastMinute = mm; + lastSecond = ss; } codeNow = tc; if ( !timeCodeValid ) diff --git a/srt.h b/srt.h index 5d0276a..ab7a68a 100644 --- a/srt.h +++ b/srt.h @@ -30,7 +30,7 @@ class SubtitleWriter float frameRate; int lastYear, lastMonth, lastDay; - int lastHour, lastMinute; + int lastHour, lastMinute, lastSecond; int frameCount, lastFrameWritten; TimeCode codeNow, nextCodeToWrite; int titleNumber; @@ -50,4 +50,4 @@ class SubtitleWriter void addRecordingDate( struct tm &rd, const TimeCode &tc ); }; -#endif \ No newline at end of file +#endif