Skip to content

Commit

Permalink
Do not speed up performance chapters
Browse files Browse the repository at this point in the history
Made better handling of markers exchanged from Pr to sailvue
  • Loading branch information
sergei committed Aug 14, 2024
1 parent d8e76d4 commit 2dae62f
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 27 deletions.
8 changes: 7 additions & 1 deletion adobe_premiere/MarkerReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ void MarkerReader::read(const std::filesystem::path &markerFile, const std::list

// Name
std::getline(ss, item, ',');
// Trim whitespace
item.erase(std::remove(item.begin(), item.end(), ' '), item.end());
marker->setName(item);

// Type
Expand All @@ -71,10 +73,14 @@ void MarkerReader::read(const std::filesystem::path &markerFile, const std::list

// Uuid
std::getline(ss, item, ',');
// Trim whitespace
item.erase(std::remove(item.begin(), item.end(), ' '), item.end());
marker->setUuid(item);

// Overlay name if any
std::getline(ss, item, ',');
// Trim whitespace
item.erase(std::remove(item.begin(), item.end(), ' '), item.end());
marker->setOverlayName(item);

marker->setClipStartUtc(createTimeUtcMs + m_timeAdjustmentMs);
Expand Down Expand Up @@ -140,7 +146,7 @@ void MarkerReader::makeMarkers(const std::list<Chapter *>& chapters, std::vector
outStream << "Clip filename, In, Out, Description, Type, Uuid, Overlay filename" << std::endl;
for(auto chapter: chapters) {
uint64_t startUtcMs = instrDataVector[chapter -> getStartIdx()].utc.getUnixTimeMs() - m_timeAdjustmentMs;
uint64_t endUtcMs = instrDataVector[chapter -> getEndIdx()].utc.getUnixTimeMs();
uint64_t endUtcMs = instrDataVector[chapter -> getEndIdx()].utc.getUnixTimeMs()- m_timeAdjustmentMs;

// Find clip corresponding to the start UTC
outStream << makeCsvEntry(chapter, startUtcMs, endUtcMs, clips) << std::endl;
Expand Down
36 changes: 29 additions & 7 deletions adobe_premiere/extensions/SailvuePanel/jsx/PPRO/Premiere.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ var BitPrecision_HDR = 3;

var NOT_SET = "-400000";

function makeUUid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}

$._PPP_={

isSailvueTrackAvailable : function (seq) {
Expand Down Expand Up @@ -177,6 +184,7 @@ $._PPP_={
}
$._PPP_.updateEventPanel('Marker ' + marker.name + ' has [' + data[2] + '] overlay path');
var overlayPath = data[2].replace(/^\s+/,'').replace(/\s+$/,'');
var overlayType = Number(data[0]);
var projItemIdx;
if (overlayPath) {

Expand All @@ -189,7 +197,7 @@ $._PPP_={
}
}

if ( overlayProjectItem == null){ // Import it
if ( overlayProjectItem === null) { // Import it
// Import the overlay into the project
app.project.importFiles([overlayPath],
false, sailVueBin, false);
Expand All @@ -203,9 +211,14 @@ $._PPP_={
overlayProjectItem.refreshMedia();
}

var start = trackItemStart - trackItemIn + marker.start.seconds
$._PPP_.updateEventPanel('Inserting overlay ' + overlayProjectItem.name + ' at start ' + start + ' = trackItemStart ' + trackItemStart + ' - trackItemIn ' + trackItemIn + ' + marker.start.seconds ' + marker.start.seconds);
sailVueVideoTrack.overwriteClip(overlayProjectItem, start);
if ( overlayProjectItem != null) {
overlayProjectItem.setColorLabel(overlayType === 1 ? 15 : 8);
var start = trackItemStart - trackItemIn + marker.start.seconds
$._PPP_.updateEventPanel('Inserting overlay ' + overlayProjectItem.name + ' at start ' + start + ' = trackItemStart ' + trackItemStart + ' - trackItemIn ' + trackItemIn + ' + marker.start.seconds ' + marker.start.seconds);
sailVueVideoTrack.overwriteClip(overlayProjectItem, start);
}else{
$._PPP_.updateEventPanel('Failed to import ' + overlayPath );
}
}else{
$._PPP_.updateEventPanel('No overlay path found in marker ' + marker.name);
}
Expand Down Expand Up @@ -297,7 +310,7 @@ $._PPP_={
var markerIn = Number(data[1]);
var markerOut = Number(data[2]);
var markerName = data[3];
var chapterType = data[4];
var chapterType = Number(data[4]);
var uuid = data[5];
var overlayPath = data[6];
$._PPP_.updateEventPanel("clipFileName [" + clipFileName + "]");
Expand All @@ -307,6 +320,7 @@ $._PPP_={
$._PPP_.updateEventPanel("chapterType [" + chapterType + "]");
$._PPP_.updateEventPanel("uuid [" + uuid + "]");
$._PPP_.updateEventPanel("overlayPath [" + overlayPath + "]");
$._PPP_.updateEventPanel("overlayPath.length [" + overlayPath.length + "]");

// Find clip for this marker
for(j =0 ; j < clipList.length; j++){
Expand All @@ -322,7 +336,7 @@ $._PPP_={
newMarker.end = (newMarker.start.seconds + (markerOut - markerIn));
newMarker.comments = chapterType + "," + uuid + "," + overlayPath;
newMarker.setTypeAsSegmentation();
newMarker.setColorByIndex( overlayPath.length === 0 ? 1 : 0);
newMarker.setColorByIndex( chapterType === 1 ? 4 : 2);
break;
}
}
Expand Down Expand Up @@ -367,7 +381,15 @@ $._PPP_={
var sailvueMarkers = [];
for (var i = 0; i < markers.numMarkers; i++) {
if (markers[i].type == "Segmentation") {
var newLine = clip.getMediaPath() + "," + markers[i].start.seconds + "," + markers[i].end.seconds + "," + markers[i].name + "," + markers[i].comments + "\n";
var newLine;
if( markers[i].comments.length > 0) {
newLine = clip.getMediaPath() + "," + markers[i].start.seconds + "," + markers[i].end.seconds + "," + markers[i].name + "," + markers[i].comments + "\n";
}else{
var uuid = makeUUid();
var chapterType = 0;
newLine = clip.getMediaPath() + "," + markers[i].start.seconds + "," + markers[i].end.seconds + "," + markers[i].name + "," + chapterType + "," + uuid + ",\n";

}
$._PPP_.updateEventPanel(newLine);
fileToOpen.write(newLine);
}
Expand Down
12 changes: 8 additions & 4 deletions ffmpeg/FFMpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,15 @@ void FFMpeg::makeClip(const std::string &clipPath, FfmpegProgressListener &progr
std::cout << "[" << ffmpegArgs << "]" << std::endl;

// Execute ffmpeg
executeFfmpeg(ffmpegArgs, progress);
if( ! executeFfmpeg(ffmpegArgs, progress) ){
std::cout << "Deleting ffmpeg output file" << std::endl;
std::filesystem::remove(clipPath);
}

std::cout << "FFMpeg::makeClip: done " << std::endl;
}

void FFMpeg::executeFfmpeg(const std::string &ffmpegArgs, FfmpegProgressListener &progress) {
bool FFMpeg::executeFfmpeg(const std::string &ffmpegArgs, FfmpegProgressListener &progress) {
int outfp;
int pid = popen2((const char *)ffmpegArgs.c_str(), nullptr, &outfp);
if (pid == -1) {
Expand Down Expand Up @@ -150,7 +153,7 @@ void FFMpeg::executeFfmpeg(const std::string &ffmpegArgs, FfmpegProgressListener
std::cout << "FFMpeg::makeClip: killing PID " << pid << std::endl;
kill(pid, SIGINT);
fclose(outStream);
break;
return false;
}
} else if( keyword == "progress" ){
if ( value == "end" ){
Expand All @@ -164,8 +167,9 @@ void FFMpeg::executeFfmpeg(const std::string &ffmpegArgs, FfmpegProgressListener
}
} catch (...) {
fclose(outStream);
throw;
return false;
}
return true;
}

std::string FFMpeg::makeClipFfmpegArgs(const std::string &clipPath) {
Expand Down
2 changes: 1 addition & 1 deletion ffmpeg/FFMpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class FFMpeg {
std::string makeClipFfmpegArgs(const std::string &clipPath);
static std::string makeJoinChaptersFfmpegArgs(std::list<std::string> &chaptersList,const std::basic_string<char> &outPath);

static void executeFfmpeg( const std::string &ffmpegArgs, FfmpegProgressListener &progress) ;
static bool executeFfmpeg( const std::string &ffmpegArgs, FfmpegProgressListener &progress) ;

};

Expand Down
70 changes: 63 additions & 7 deletions gui/RaceTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,18 +1114,59 @@ void RaceTreeModel::importAdobeMarkers(const QString &markersFile) {
markerReader.setTimeAdjustmentMs(cameraUtcOffsetMs());
markerReader.read(markersCsv, m_CameraClipsList);

std::list<Chapter *> chapters;
markerReader.makeChapters(chapters, m_InstrDataVector);
std::list<Chapter *> importedChapters;
markerReader.makeChapters(importedChapters, m_InstrDataVector);

for( auto chapter : chapters){
// If chapter has empty UUID, this is a new chapter, so we need to add it
if ( chapter->getChapterClipFileName() == "" ) {
auto existingChapters = m_pCurrentRace->getChapters();

std::set<QString> existingUuids;
for( auto chapter : existingChapters){
const QString &uuid = chapter->getUuid();
std::cout << "Existing chapter " << chapter->getName() << " uuid " << uuid.toStdString() << std::endl;
existingUuids.emplace(uuid);
}

std::set<QString> importedUuids;
for( auto chapter : importedChapters){
const QString &uuid = chapter->getUuid();
std::cout << "Imported chapter " << chapter->getName() << " uuid " << uuid.toStdString() << std::endl;
importedUuids.emplace(uuid);
}

// Set of new uuids to be added
std::set<QString> newUuids;
std::set_difference(importedUuids.begin(), importedUuids.end(), existingUuids.begin(), existingUuids.end(),
std::inserter(newUuids, newUuids.end()));

// Set of uuids to be updated
std::set<QString> updateUuids;
std::set_intersection(importedUuids.begin(), importedUuids.end(), existingUuids.begin(), existingUuids.end(),
std::inserter(updateUuids, updateUuids.end()));

// Set of uuids to be deleted
std::set<QString> deleteUuids;
std::set_difference(existingUuids.begin(), existingUuids.end(), importedUuids.begin(), importedUuids.end(),
std::inserter(deleteUuids, deleteUuids.end()));

// Delete chapters
for( auto chapter : existingChapters){
if ( deleteUuids.find(chapter->getUuid()) != deleteUuids.end() ) {
std::cout << "Delete chapter " << chapter->getName() << std::endl;
deleteChapterByUUid(chapter->getUuid());
}
}

// Add or update chapters
for( auto chapter : importedChapters){
if ( newUuids.find(chapter->getUuid()) != newUuids.end() ) {
std::cout << "Add chapter " << chapter->getName() << std::endl;
addChapter(chapter);
}else{
// If chapter has UUID, this is an existing chapter, so we need to update it
}else{ // Just update the chapter
std::cout << "Update chapter " << chapter->getName() << std::endl;
updateChapter(chapter);
}
}

}

void RaceTreeModel::exportAdobeMarkers(const QString &path) {
Expand All @@ -1137,3 +1178,18 @@ void RaceTreeModel::exportAdobeMarkers(const QString &path) {

}

void RaceTreeModel::deleteChapterByUUid(const QString& uuid) {
for( auto race : m_RaceDataList) {
for (auto chapter: race->getChapters()) {
if (chapter->getUuid() == uuid) {
race->getChapters().remove(chapter);
std::cout << "deleteChapterByUUid Chapter: " << chapter->getName() << std::endl;
m_project.raceDataChanged();
emit isDirtyChanged();
emit chapterDeleted(chapter->getUuid());
return;
}
}
}
}

2 changes: 2 additions & 0 deletions gui/RaceTreeModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ public slots:
void computeStats();
void startNetworkSimulator();
void selectFirstChapter();

void deleteChapterByUUid(const QString& uuid);
};


Expand Down
20 changes: 13 additions & 7 deletions movie/MovieProducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,12 @@ std::string MovieProducer::produceChapter(OverlayMaker &overlayMaker, Chapter &c


auto duration = float(stopUtcMs - startUtcMs) / 1000;
float presentationDuration;
float presentationDuration = duration;
bool changeDuration = false;
if( chapter.getChapterType() == ChapterTypes::ChapterType::SPEED_PERFORMANCE) {
presentationDuration = 60;
changeDuration = true;
}else{
presentationDuration = duration;
}
// if( chapter.getChapterType() == ChapterTypes::ChapterType::SPEED_PERFORMANCE) {
// presentationDuration = 60;
// changeDuration = true;
// }

m_totalRaceDuration += presentationDuration * 1000;

Expand All @@ -224,6 +222,14 @@ std::string MovieProducer::produceChapter(OverlayMaker &overlayMaker, Chapter &c
overlaysFps = float(totalCount / ulEpochStep) / presentationDuration;
}

if( chapter.getChapterType() == ChapterTypes::ChapterType::SPEED_PERFORMANCE && totalCount > 1200 ){
// We don't want to have too many frames
// let's skip some epochs
ulEpochStep = totalCount / 1000;
// Recompute overlay FPS
overlaysFps = float(totalCount / ulEpochStep) / presentationDuration;
}

std::list<InstrumentInput> chapterEpochs;
for(auto epochIdx = chapter.getStartIdx(); epochIdx < chapter.getEndIdx(); epochIdx += ulEpochStep) {

Expand Down

0 comments on commit 2dae62f

Please sign in to comment.