Merge pull request #372 from HaveAGitGat/duration_fix

Use file.ffProbeData?.format?.duration if available
make-only-subtitle-default
HaveAGitGat 3 years ago committed by GitHub
commit aecab1544f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -172,7 +172,9 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
// figure out final bitrate // figure out final bitrate
// Check if duration info is filled, if so times it by 0.0166667 to get time in minutes. // Check if duration info is filled, if so times it by 0.0166667 to get time in minutes.
// If not filled then get duration of stream 0 and do the same. // If not filled then get duration of stream 0 and do the same.
if (typeof file.meta.Duration !== 'undefined') { if (parseFloat(file.ffProbeData?.format?.duration) > 0) {
duration = parseFloat(file.ffProbeData?.format?.duration) * 0.0166667;
} else if (typeof file.meta.Duration !== 'undefined') {
duration = file.meta.Duration * 0.0166667; duration = file.meta.Duration * 0.0166667;
} else { } else {
duration = file.ffProbeData.streams[0].duration * 0.0166667; duration = file.ffProbeData.streams[0].duration * 0.0166667;

@ -396,8 +396,15 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
streamBR = file.mediaInfo.track[MILoc].extra.FromStats_BitRate * 1; streamBR = file.mediaInfo.track[MILoc].extra.FromStats_BitRate * 1;
} }
let duration = 0;
if (parseFloat(file.ffProbeData?.format?.duration) > 0) {
duration = parseFloat(file.ffProbeData?.format?.duration);
} else {
duration = file.meta.Duration;
}
response.infoLog response.infoLog
+= `Video stream ${i}:${Math.floor(file.meta.Duration / 60)}:` += `Video stream ${i}:${Math.floor(duration / 60)}:`
+ `${file.ffProbeData.streams[i].codec_name}${(bolSource10bit) ? '(10)' : ''}`; + `${file.ffProbeData.streams[i].codec_name}${(bolSource10bit) ? '(10)' : ''}`;
response.infoLog += `:${streamWidth}x${streamHeight}x${streamFPS}:${streamBR}bps \n`; response.infoLog += `:${streamWidth}x${streamHeight}x${streamFPS}:${streamBR}bps \n`;

@ -269,7 +269,14 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
var intChapNum = 0; var intChapNum = 0;
var strChapNum = ""; var strChapNum = "";
for (var i = 0; i < file.meta.Duration; i += chapterlengthlong) { let duration = 0;
if (parseFloat(file.ffProbeData?.format?.duration) > 0) {
duration = parseFloat(file.ffProbeData?.format?.duration)
} else {
duration = file.meta.Duration
}
for (var i = 0; i < duration; i += chapterlengthlong) {
intChapNum += 1; intChapNum += 1;
strChapNum = String(intChapNum).padStart(2, '0'); strChapNum = String(intChapNum).padStart(2, '0');
@ -283,7 +290,8 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
intChapNum += 1; intChapNum += 1;
strChapNum = String(intChapNum).padStart(2, "0"); strChapNum = String(intChapNum).padStart(2, "0");
var timeString = new Date((Math.floor(file.meta.Duration) - 1) * 1000).toISOString().substr(11, 12);
var timeString = new Date((Math.floor(duration) - 1) * 1000).toISOString().substr(11, 12);
strChapterFile += "CHAPTER" + strChapNum + "=" + timeString + "\n"; strChapterFile += "CHAPTER" + strChapNum + "=" + timeString + "\n";
strChapterFile += "CHAPTER" + strChapNum + "NAME=CHAPTER " + intChapNum + "\n"; strChapterFile += "CHAPTER" + strChapNum + "NAME=CHAPTER " + intChapNum + "\n";

@ -139,7 +139,9 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
// Check if duration info is filled, if so times it by 0.0166667 to get time in minutes. // Check if duration info is filled, if so times it by 0.0166667 to get time in minutes.
// If not filled then get duration of stream 0 and do the same. // If not filled then get duration of stream 0 and do the same.
if (typeof file.meta.Duration !== 'undefined') { if (parseFloat(file.ffProbeData?.format?.duration) > 0) {
duration = parseFloat(file.ffProbeData?.format?.duration) * 0.0166667;
} else if (typeof file.meta.Duration !== 'undefined') {
duration = file.meta.Duration * 0.0166667; duration = file.meta.Duration * 0.0166667;
} else { } else {
duration = file.ffProbeData.streams[0].duration * 0.0166667; duration = file.ffProbeData.streams[0].duration * 0.0166667;

@ -118,7 +118,9 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
// Check if duration info is filled, if so times it by 0.0166667 to get time in minutes. // Check if duration info is filled, if so times it by 0.0166667 to get time in minutes.
// If not filled then get duration of stream 0 and do the same. // If not filled then get duration of stream 0 and do the same.
if (typeof file.meta.Duration !== 'undefined') { if (parseFloat(file.ffProbeData?.format?.duration) > 0) {
duration = parseFloat(file.ffProbeData?.format?.duration) * 0.0166667;
} else if (typeof file.meta.Duration !== 'undefined') {
duration = file.meta.Duration * 0.0166667; duration = file.meta.Duration * 0.0166667;
} else { } else {
duration = file.ffProbeData.streams[0].duration * 0.0166667; duration = file.ffProbeData.streams[0].duration * 0.0166667;

@ -85,7 +85,16 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
// Bitrate = file size / (stream duration * .0075) // Bitrate = file size / (stream duration * .0075)
// Calculations were made based on the formula from this site: // Calculations were made based on the formula from this site:
// https://blog.frame.io/2017/03/06/calculate-video-bitrates/ // https://blog.frame.io/2017/03/06/calculate-video-bitrates/
duration = (file.meta.Duration !== `undefined` ? file.meta.Duration : stream.duration) * 0.0166667;
if (parseFloat(file.ffProbeData?.format?.duration) > 0) {
duration = parseFloat(file.ffProbeData?.format?.duration) * 0.0166667;
} else if(file.meta.Duration !== `undefined`){
duration = file.meta.Duration* 0.0166667;
}else{
duration = stream.duration * 0.0166667;
}
currentBitrate = ~~(file.file_size / (duration * 0.0075)); currentBitrate = ~~(file.file_size / (duration * 0.0075));
targetBitrate = ~~(currentBitrate / 2); targetBitrate = ~~(currentBitrate / 2);
minimumBitrate = ~~(targetBitrate * 0.7); minimumBitrate = ~~(targetBitrate * 0.7);

@ -331,7 +331,9 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
// Check if duration info is filled, if so times it by 0.0166667 to get time in minutes. // Check if duration info is filled, if so times it by 0.0166667 to get time in minutes.
// If not filled then get duration of stream 0 and do the same. // If not filled then get duration of stream 0 and do the same.
if (typeof file.meta.Duration !== 'undefined') { if (parseFloat(file.ffProbeData?.format?.duration) > 0) {
duration = parseFloat(file.ffProbeData?.format?.duration) * 0.0166667;
} else if (typeof file.meta.Duration !== 'undefined') {
duration = file.meta.Duration * 0.0166667; duration = file.meta.Duration * 0.0166667;
} else { } else {
duration = file.ffProbeData.streams[0].duration * 0.0166667; duration = file.ffProbeData.streams[0].duration * 0.0166667;

@ -142,6 +142,10 @@ class Configurator {
* Returns the duration of the file in minutes. * Returns the duration of the file in minutes.
*/ */
function getFileDurationInMinutes(file) { function getFileDurationInMinutes(file) {
if (parseFloat(file.ffProbeData?.format?.duration) > 0) {
return parseFloat(file.ffProbeData?.format?.duration) * 0.0166667;
}
return typeof file.meta.Duration != undefined return typeof file.meta.Duration != undefined
? file.meta.Duration * 0.0166667 ? file.meta.Duration * 0.0166667
: file.ffProbeData.streams[0].duration * 0.0166667; : file.ffProbeData.streams[0].duration * 0.0166667;
@ -409,8 +413,8 @@ function buildVideoConfiguration(inputs, file, logger) {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const plugin = (file, librarySettings, inputs, otherArguments) => { const plugin = (file, librarySettings, inputs, otherArguments) => {
const lib = require('../methods/lib')(); const lib = require('../methods/lib')();
// eslint-disable-next-line no-unused-vars,no-param-reassign // eslint-disable-next-line no-unused-vars,no-param-reassign
inputs = lib.loadDefaultValues(inputs, details); inputs = lib.loadDefaultValues(inputs, details);
var response = { var response = {

@ -284,7 +284,14 @@ function crop_decider(file, crop_height) {
function size_check(file, min_bitrate) { function size_check(file, min_bitrate) {
const fs = require("fs"); const fs = require("fs");
var duration = file.meta.Duration; //duration of video in seconds
let duration = 0;
if (parseFloat(file.ffProbeData?.format?.duration) > 0) {
duration = parseFloat(file.ffProbeData?.format?.duration)
}else{
duration = file.meta.Duration; //duration of video in seconds
}
var source = file.meta.SourceFile; //source file var source = file.meta.SourceFile; //source file
var stats = fs.statSync(source); var stats = fs.statSync(source);
var size = stats["size"] / 1000000000; var size = stats["size"] / 1000000000;

Loading…
Cancel
Save