Skip to content

Commit 9edfca2

Browse files
committed
VideoEncoder: Remove old (24 hours) file segments
This is a workaround to clear previously left video segments files.
1 parent 42e160a commit 9edfca2

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Added
66
- Can now set maximum recording width and height, will is scaled down if the viewport is larger.
7+
- Video segments are now using random names to avoid file conflicts on multiple game instances.
78

89
### Fixes
910

Source/BetaHubBugReporter/Private/BH_VideoEncoder.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ BH_VideoEncoder::BH_VideoEncoder(
7070

7171
stopEvent = FPlatformProcess::GetSynchEventFromPool(false);
7272
pauseEvent = FPlatformProcess::GetSynchEventFromPool(false);
73+
74+
RemoveOldFiles();
7375
}
7476

7577
BH_VideoEncoder::~BH_VideoEncoder()
@@ -399,4 +401,29 @@ void BH_VideoEncoder::RemoveOldSegments()
399401
int32 BH_VideoEncoder::GetSegmentCountToKeep()
400402
{
401403
return RecordingDuration.GetTotalSeconds() / SEGMENT_DURATION_SECONDS;
404+
}
405+
406+
void BH_VideoEncoder::RemoveOldFiles()
407+
{
408+
IFileManager& FileManager = IFileManager::Get();
409+
TArray<FString> Files;
410+
FileManager.FindFiles(Files, *(segmentsDir / TEXT("*.mp4")), true, false);
411+
412+
FDateTime CurrentTime = FDateTime::UtcNow();
413+
FTimespan MaxAge = FTimespan::FromHours(24);
414+
415+
for (const FString& File : Files)
416+
{
417+
FString FilePath = FPaths::Combine(segmentsDir, File);
418+
FFileStatData StatData = FileManager.GetStatData(*FilePath);
419+
if (StatData.bIsValid)
420+
{
421+
FDateTime LastWriteTime = StatData.ModificationTime;
422+
if ((CurrentTime - LastWriteTime) > MaxAge)
423+
{
424+
UE_LOG(LogBetaHub, Log, TEXT("Removing old file: %s"), *FilePath);
425+
FileManager.Delete(*FilePath);
426+
}
427+
}
428+
}
402429
}

Source/BetaHubBugReporter/Private/BH_VideoEncoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ class BH_VideoEncoder : public FRunnable
5959
void EncodeFrame(TSharedPtr<FBH_Frame> frame);
6060

6161
FString MergeSegments(int32 MaxSegments);
62+
void RemoveOldFiles(); // New function declaration
6263
};

0 commit comments

Comments
 (0)