Skip to content

Commit

Permalink
Showing bitrate in video details (#714)
Browse files Browse the repository at this point in the history
* showing bitrate in video details implemented

* showing bitrate in video details implemented

Co-authored-by: Jozef Kopčák <jozef.kopcak@student.tuke.sk>
  • Loading branch information
jozefkopcak and Jozef Kopčák authored Dec 14, 2021
1 parent 9620390 commit a926bf4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
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' }}

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

| <input
Expand Down

0 comments on commit a926bf4

Please sign in to comment.