increase precision from 5 to 6

closes #2838
pull/2774/head
Mikael Finstad 4 months ago
parent 2605292cb8
commit 260529e8a4
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -5,3 +5,7 @@ export const parseFfprobeDuration = (durationStr: string | undefined) => (
);
export const getHwaccelArgs = (hwaccel: FfmpegHwAccel) => (hwaccel !== 'none' ? ['-hwaccel', hwaccel] : []);
// Used to be 5, but we recently increased to 6 because https://github.com/mifi/lossless-cut/issues/2838
// I don't remember why 5 was chosen initially, but if we don't truncate, ffmpeg can sometimes give an error when too many decimal places are used in the time argument, see:
export const formatFfmpegTime = (time: number) => time.toFixed(6);

@ -14,7 +14,7 @@ import type { FFprobeFormat } from '../common/ffprobe.js';
import isDev from './isDev.js';
import logger from './logger.js';
import { parseFfmpegProgressLine } from './progress.js';
import { getHwaccelArgs, parseFfprobeDuration } from '../common/util.js';
import { formatFfmpegTime, getHwaccelArgs, parseFfprobeDuration } from '../common/util.js';
import { getFfmpegJpegQuality } from './ffmpegUtil.js';
@ -260,9 +260,9 @@ export async function renderWaveformPng({ filePath, start, duration, resample, c
}
const getInputSeekArgs = ({ filePath, from, to }: { filePath: string, from?: number | undefined, to?: number | undefined }) => [
...(from != null ? ['-ss', from.toFixed(5)] : []),
...(from != null ? ['-ss', formatFfmpegTime(from)] : []),
'-i', filePath,
...(from != null && to != null ? ['-t', (to - from).toFixed(5)] : []),
...(from != null && to != null ? ['-t', formatFfmpegTime(to - from)] : []),
];
export function mapTimesToSegments(times: number[], includeLast: boolean) {

@ -16,7 +16,7 @@ import { deleteDispositionValue, type AllFilesMeta, type Chapter, type CopyfileS
import type { LossyMode } from '../../../main';
import { UserFacingError } from '../../errors';
import mainApi from '../mainApi';
import { getHwaccelArgs } from '../../../common/util';
import { formatFfmpegTime, getHwaccelArgs } from '../../../common/util';
const { join, resolve, dirname } = window.require('path');
const { writeFile, mkdir, access, constants: { W_OK } } = window.require('fs/promises');
@ -278,8 +278,8 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
if (detectedFps != null) cutDuration = Math.max(cutDuration, frameDuration); // ensure at least one frame duration
// Don't cut if no need: https://github.com/mifi/lossless-cut/issues/50
const cutFromArgs = cuttingStart ? ['-ss', cutFromWithAdjustment.toFixed(5)] : [];
const cutToArgs = cuttingEnd ? ['-t', cutDuration.toFixed(5)] : [];
const cutFromArgs = cuttingStart ? ['-ss', formatFfmpegTime(cutFromWithAdjustment)] : [];
const cutToArgs = cuttingEnd ? ['-t', formatFfmpegTime(cutDuration)] : [];
const copyFileStreamsFiltered = copyFileStreams.filter(({ streamIds }) => streamIds.length > 0);
@ -480,10 +480,10 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
// No progress if we set loglevel warning :(
// '-loglevel', 'warning',
'-ss', cutFrom.toFixed(5), // if we don't -ss before -i, seeking will be slow for long files, see https://github.com/mifi/lossless-cut/issues/126#issuecomment-1135451043
'-ss', formatFfmpegTime(cutFrom), // if we don't -ss before -i, seeking will be slow for long files, see https://github.com/mifi/lossless-cut/issues/126#issuecomment-1135451043
'-i', filePath,
'-ss', '0', // If we don't do this, the output seems to start with an empty black after merging with the encoded part
'-t', (cutTo - cutFrom).toFixed(5),
'-t', formatFfmpegTime(cutTo - cutFrom),
...mapStreamsArgs,

Loading…
Cancel
Save