Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fps #635

Merged
merged 6 commits into from
Feb 3, 2021
Merged
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
3 changes: 3 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@
"sortOptionCreatedMoreInfo": "Show the time created order option in the sorting dropdown",
"sortOptionFolderSizeDescription": "Number of Videos",
"sortOptionFolderSizeMoreInfo": "Show the Number of Videos order option in the sorting dropdown",
"sortOptionFpsDescription": "FPS",
"sortOptionFpsMoreInfo": "Show the frames per second order option in the sorting dropdown",
"sortOptionModifiedDescription": "Date Modified",
"sortOptionModifiedMoreInfo": "Show the time modified order option in the sorting dropdown",
"sortOptionsHeading": "Sorting options in the dropdown",
Expand Down Expand Up @@ -338,6 +340,7 @@
"sortCreated": "Date Created",
"sortDefault": "Default",
"sortFolderSize": "Number of Videos",
"sortFps": "FPS",
"sortModified": "Date Modified",
"sortRandom": "Random",
"sortSize": "Size",
Expand Down
2 changes: 2 additions & 0 deletions interfaces/final-object.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface ImageElement {
stars: StarRating; // star rating 0 = n/a, otherwise 1, 2, 3
timesPlayed: number; // number of times the file has been launched by VHA
width: number; // width of the video (px)
fps: number; // base frame rate of the video in fps
// ========================================================================
// OPTIONAL
// ------------------------------------------------------------------------
Expand Down Expand Up @@ -84,6 +85,7 @@ export function NewImageElement(): ImageElement {
stars: 0.5,
timesPlayed: 0,
width: 0,
fps: 0,
};
}

Expand Down
23 changes: 23 additions & 0 deletions node/main-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function getDurationDisplay(numOfSec: number): string {
}
}


/**
* Count the number of unique folders in the final array
*/
Expand Down Expand Up @@ -313,6 +314,26 @@ function getFileDuration(metadata): number {
}
}

/**
* Return the average frame rate of files
* ===========================================================================================
* TO SWITCH TO AVERAGE FRAME RATE,
* replace both instances of r_frame_rate with avg_frame_rate
* only in this method
* ===========================================================================================
* @param metadata
*/
function getFps(metadata): number {
if(metadata?.streams?.[0]?.r_frame_rate) {
let fps = metadata.streams[0].r_frame_rate
let evalFps = eval(fps.toString());
return Math.round(evalFps);
}
else {
return 0;
}
}

// ===========================================================================================
// Other supporting methods
// ===========================================================================================
Expand Down Expand Up @@ -415,6 +436,7 @@ export function extractMetadataAsync(
const metadata = JSON.parse(data);
const stream = getBestStream(metadata);
const fileDuration = getFileDuration(metadata);
const realFps = getFps(metadata);

const duration = Math.round(fileDuration) || 0;
const origWidth = stream.width || 0; // ffprobe does not detect it on some MKV streams
Expand All @@ -433,6 +455,7 @@ export function extractMetadataAsync(
imageElement.mtime = Math.round(fileStat.mtimeMs);
imageElement.screens = computeNumberOfScreenshots(screenshotSettings, duration);
imageElement.width = origWidth;
imageElement.fps = realFps;

hashFileAsync(filePath, fileStat).then((hash) => {
imageElement.hash = hash;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/app/common/settings-buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type SettingsButtonKey = 'autoFileTags'
| 'sortOptionAspectRatio'
| 'sortOptionCreated'
| 'sortOptionFolderSize'
| 'sortOptionFps'
| 'sortOptionModified'
| 'sortOptionSize'
| 'sortOptionStar'
Expand Down Expand Up @@ -724,6 +725,14 @@ export const SettingsButtons: SettingsButtonsType = {
title: '',
toggled: false
},

'sortOptionFps': {
description: 'BUTTONS.sortOptionFpsDescription',
hidden: false,
moreInfo: 'BUTTONS.sortOptionFpsMoreInfo',
title: '',
toggled: true
},
'sortOptionModified': {
description: 'BUTTONS.sortOptionModifiedDescription',
hidden: false,
Expand Down
2 changes: 2 additions & 0 deletions src/app/components/meta/meta.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

| {{ video.fileSizeDisplay }}

| {{ video.fps }} fps

| <input
#yearInput
(change)="validateYear($event)"
Expand Down
6 changes: 6 additions & 0 deletions src/app/components/sort-order/sort-order.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
<option *ngIf="settingsButtons['sortOptionFolderSize'].toggled" value="folderSizeDesc">
&#x25BC; {{ 'SIDEBAR.sortFolderSize' | translate }}
</option>
<option *ngIf="settingsButtons['sortOptionFps'].toggled" value="fpsAsc">
&#x25B2; {{ 'SIDEBAR.sortFps' | translate }}
</option>
<option *ngIf="settingsButtons['sortOptionFps'].toggled" value="fpsDesc">
&#x25BC; {{ 'SIDEBAR.sortFps' | translate }}
</option>
<option value="random">
{{ 'SIDEBAR.sortRandom' | translate }}
</option>
Expand Down
14 changes: 12 additions & 2 deletions src/app/pipes/sorting.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export type SortType = 'default'
| 'timesPlayedAsc'
| 'timesPlayedDesc'
| 'yearAsc'
| 'yearDesc';
| 'yearDesc'
| 'fpsAsc'
| 'fpsDesc';

@Pipe({
name: 'sortingPipe'
Expand Down Expand Up @@ -296,7 +298,15 @@ export class SortingPipe implements PipeTransform {
return galleryArray.slice().sort((x: ImageElement, y: ImageElement): any => {
return this.sortFunctionLol(x, y, 'folderSize', true);
});
} else {
} else if (sortingType === 'fpsAsc') {
return galleryArray.slice().sort((x: ImageElement, y: ImageElement): any => {
return this.sortFunctionLol(x, y, 'fps', true);
});
} else if (sortingType === 'fpsDesc') {
return galleryArray.slice().sort((x: ImageElement, y: ImageElement): any => {
return this.sortFunctionLol(x, y, 'fps', false);
});
}else {
return galleryArray.slice().sort((x: ImageElement, y: ImageElement): any => {
return this.sortFunctionLol(x, y, 'index', true);
});
Expand Down