Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ endif (PKG_CONFIG_FOUND AND WITH_HARDSUBX)

add_executable (ccextractor ${SOURCEFILE} ${FREETYPE_SOURCE} ${UTF8PROC_SOURCE})

if (BUILD_TESTING)
add_test(NAME scc_final_frame
COMMAND ${CMAKE_COMMAND} -DCCEXTRACTOR=$<TARGET_FILE:ccextractor>
-P ${CMAKE_CURRENT_SOURCE_DIR}/../tests/scc_final_frame.cmake)
endif()

########################################################
# Build with Rust library
########################################################
Expand Down
8 changes: 4 additions & 4 deletions src/lib_ccx/ccx_encoders_scc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "lib_ccx.h"
#include <stdbool.h>
#include <math.h>

// Adds a parity bit if needed
unsigned char odd_parity(const unsigned char byte)
Expand Down Expand Up @@ -966,12 +967,11 @@ void add_timestamp(const struct encoder_ctx *context, LLONG time, const bool dis

// SMPTE format - use configurable frame rate (issue #1191)
float fps = get_scc_fps(context->scc_framerate);
// Calculate frame number from milliseconds, ensuring it stays in valid range 0 to fps-1
// Use floor to avoid rounding up to fps (e.g., 29.97 -> 30 is invalid)
int max_frames = (int)fps;
// Frame labels are zero-based: 29.97 fps uses 0..29, 23.976 uses 0..23.
int max_frames = (int)ceilf(fps);
int frame = (int)(milli * fps / 1000.0f);
if (frame >= max_frames)
frame = max_frames - 1; // Cap at max valid frame (e.g., 29 for 29.97fps)
frame = max_frames - 1;
fdprintf(context->out->fh, "%02u:%02u:%02u:%02d\t", hour, minute, second, frame);
}

Expand Down
24 changes: 24 additions & 0 deletions tests/scc_final_frame.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# The sample's first caption starts at second 1, frame 12. Shift it
# near the end of the second at each rate and inspect the actual output.
function(check_frame rate delay expected)
foreach(format scc ccd)
set(output "${CMAKE_CURRENT_BINARY_DIR}/scc-final-frame-${rate}.${format}")
execute_process(
COMMAND "${CCEXTRACTOR}" --scc-framerate "${rate}" --delay "${delay}"
"--out=${format}" "${CMAKE_CURRENT_LIST_DIR}/samples/scc_23_976.scc" -o "${output}"
COMMAND_ERROR_IS_FATAL ANY
OUTPUT_QUIET
)
file(STRINGS "${output}" cues REGEX "^00:00:")
list(GET cues 0 first_cue)
if(NOT first_cue MATCHES "^00:00:01:${expected}[ \t]")
message(FATAL_ERROR "${format} at ${rate} fps: expected frame ${expected}, got ${first_cue}")
endif()
endforeach()
endfunction()

check_frame(29.97 590 29)
check_frame(23.976 490 23)
check_frame(30 590 29)
check_frame(25 510 24)
check_frame(24 490 23)
Loading