1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-22 02:12:30 +01:00

Merge branch 'master' of github.com:mifi/lossless-cut

This commit is contained in:
Mikael Finstad 2023-12-02 22:25:17 +08:00
commit 556f8a09e3
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26
2 changed files with 29 additions and 2 deletions

View File

@ -26,7 +26,14 @@ export async function parseCsv(csvStr, processTime = (t) => t) {
function parseTimeVal(str) {
if (str === '') return undefined;
const parsed = parseFloat(str, 10);
let timestampMatch = str.match(/^(\d{1,2}):(\d{1,2}):(\d{1,2})(?:\.(\d{1,3}))?$/);
let parsed = undefined;
if (timestampMatch && timestampMatch.length === 5) {
let [, h, m, s, ms] = timestampMatch;
parsed = parseInt(h, 10) * 60 + parseInt(m, 10) * 60 + parseInt(s, 10) + parseInt(ms, 10) / 1000;
} else {
parsed = parseFloat(str, 10);
}
return processTime(parsed);
}
const mapped = rows

View File

@ -4,7 +4,7 @@ import { fileURLToPath } from 'url';
import { it, describe, expect } from 'vitest';
import { parseYouTube, formatYouTube, parseMplayerEdl, parseXmeml, parseFcpXml, parseCsv, getTimeFromFrameNum, formatCsvFrames, getFrameCountRaw, parsePbf, parseDvAnalyzerSummaryTxt } from './edlFormats';
import { parseYouTube, formatYouTube, parseMplayerEdl, parseXmeml, parseFcpXml, parseCsv, getTimeFromFrameNum, formatCsvFrames, formatCsvHuman, getFrameCountRaw, parsePbf, parseDvAnalyzerSummaryTxt } from './edlFormats';
// eslint-disable-next-line no-underscore-dangle
const __dirname = dirname(fileURLToPath(import.meta.url));
@ -211,6 +211,26 @@ it('parses csv with frames', async () => {
expect(formatted).toEqual(csvFramesStr);
});
const csvTimestampStr = `\
00:01:54.612,00:03:09.053,A
00:05:00.448,00:07:56.194,B
00:09:27.075,00:11:44.264,C
`;
it('parses csv with timestamps', async () => {
const fps = 30;
const parsed = await parseCsv(csvTimestampStr);
expect(parsed).toEqual([
{ end: 189.053, name: 'A', start: 114.612},
{ end: 476.194, name: 'B', start: 300.448},
{ end: 704.264, name: 'C', start: 567.075},
]);
const formatted = await formatCsvHuman(parsed);
expect(formatted).toEqual(csvTimestampStr);
});
it('parses pbf', async () => {
expect(parsePbf(await readFixture('test1.pbf', null))).toMatchSnapshot();
expect(parsePbf(await readFixture('test2.pbf', null))).toMatchSnapshot();