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

Showing bitrate in video details #714

Merged
merged 2 commits into from
Dec 14, 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
2 changes: 2 additions & 0 deletions interfaces/final-object.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface ImageElement {
duration: number; // number of seconds - duration of film
fileName: string; // full file name with extension - for opening the file
fileSize: number; // file size in bytes
bitrate: number; // bitrate of the displayed video file - (fileSize/duration)*1024
fps: number; // base frame rate of the video in fps
hash: string; // used for detecting changed files and as a screenshot identifier
height: AllowedScreenshotHeight; // height of the video (px)
Expand Down Expand Up @@ -72,6 +73,7 @@ export function NewImageElement(): ImageElement {
durationDisplay: '',
fileName: '',
fileSize: 0,
bitrate: 0,
fileSizeDisplay: '',
fps: 0,
hash: '',
Expand Down
12 changes: 10 additions & 2 deletions node/main-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function getFileSizeDisplay(sizeInBytes: number): string {
* Generate duration formatted as X:XX:XX
* @param numOfSec
*/

function getDurationDisplay(numOfSec: number): string {

if (numOfSec === undefined || numOfSec === 0) {
Expand Down Expand Up @@ -302,18 +303,24 @@ function getBestStream(metadata) {
*/
function getFileDuration(metadata): number {
if (metadata?.streams?.[0]?.duration) {

return metadata.streams[0].duration;

} else if (metadata?.format?.duration) {

return metadata.format.duration;

} else {
return 0;
}
}

//Calculation of video bitrate in mb/s

function getBitrate(fileSize,duration){
var bitrate = ((fileSize/1000)/duration)/1000;
return Math.round(bitrate*100)/100;
}

/**
* Return the average frame rate of files
* ===========================================================================================
Expand Down Expand Up @@ -537,6 +544,7 @@ export function insertTemporaryFieldsSingle(element: ImageElement): ImageElement
const resolution: ResolutionMeta = labelVideo(element.width, element.height);
element.durationDisplay = getDurationDisplay(element.duration);
element.fileSizeDisplay = getFileSizeDisplay(element.fileSize);
element.bitrate = getBitrate(element.fileSize, element.duration);
element.resBucket = resolution.bucket;
element.resolution = resolution.label;
return element;
Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion src/app/components/meta/meta.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
| {{ video.width }} x {{ video.height }}

| {{ video.fileSizeDisplay }}


| {{ video.bitrate + ' mb/s' }}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to accept as is. But currently if bitrate property is absent (as it would be for old Hubs), there would be an empty display. I recommend something like the line below, for example:
{{ video.bitrate ? '| ' + video.bitrate + ' mb/s' : '' }}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will always be a bitrate property, because it's calculated from videoSize and duration, which are present in every video there is (if I understand correctly).

Copy link
Owner

@whyboris whyboris Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you're right! I'm sorry, in my mind, before I saw your code, I was thinking you were grabbing the bitrate from what FFmpeg was returning (when initially scanning the video), and then I commented based on my guess about your code rather than your code 😓

I like your implementation rather than what I was thinking, since it provides previously-scanned videos with a bitrate estimate!

I'll merge this in soon 👏


{{ video.fps ? '| ' + video.fps + ' fps' : '' }}

| <input
Expand Down