The swiss army knife of lossless video/audio editing
refactor/reuse
Mikael Finstad1849679448de
diff --git a/src/ExportConfirm.jsx b/src/ExportConfirm.jsxindex a1bab57d..cd6246a7 100644--- a/src/ExportConfirm.jsx+++ b/src/ExportConfirm.jsx@@ -16,7 +16,7 @@ import OutSegTemplateEditor from './components/OutSegTemplateEditor';import HighlightedText from './components/HighlightedText';import { withBlur, toast } from './util';-import { isMov as ffmpegIsMov } from './ffmpeg';+import { isMov as ffmpegIsMov } from './util/streams';import useUserSettings from './hooks/useUserSettings';const sheetStyle = {diff --git a/src/ffmpeg.js b/src/ffmpeg.jsindex 22abca9b..2ed89148 100644--- a/src/ffmpeg.js+++ b/src/ffmpeg.js@@ -577,9 +577,6 @@ export async function captureFrame({ timestamp, videoPath, outPath, numFrames })]);}--export const isMov = (format) => ['ismv', 'ipod', 'mp4', 'mov'].includes(format);-export function isIphoneHevc(format, streams) {if (!streams.some((s) => s.codec_name === 'hevc')) return false;const makeTag = format.tags && format.tags['com.apple.quicktime.make'];diff --git a/src/smartcut.js b/src/smartcut.jsindex f2304392..6f409534 100644--- a/src/smartcut.js+++ b/src/smartcut.js@@ -1,4 +1,4 @@-import { getRealVideoStreams } from './util/streams';+import { getRealVideoStreams, getVideoTimebase } from './util/streams';import { readFrames } from './ffmpeg';@@ -56,12 +56,7 @@ export async function getSmartCutParams({ path, videoDuration, desiredCutFrom, sconst videoCodec = mapInputToOutputCodec(videoStream.codec_name);if (videoCodec == null) throw new Error('Unable to determine codec for smart cut');- let timebase;- const timebaseMatch = videoStream.time_base && videoStream.time_base.split('/');- if (timebaseMatch) {- const timebaseParsed = parseInt(timebaseMatch[1], 10);- if (!Number.isNaN(timebaseParsed)) timebase = timebaseParsed;- }+ const timebase = getVideoTimebase(videoStream);if (timebase == null) console.warn('Unable to determine timebase', videoStream.time_base);return {diff --git a/src/util/streams.js b/src/util/streams.jsindex ba67eba8..62de6ce1 100644--- a/src/util/streams.js+++ b/src/util/streams.js@@ -102,6 +102,8 @@ export function getActiveDisposition(disposition) {return existingActiveDispositionEntry[0]; // return the key}+export const isMov = (format) => ['ismv', 'ipod', 'mp4', 'mov'].includes(format);+function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposition = false, getVideoArgs = () => {} }) {let args = [];@@ -112,7 +114,7 @@ function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposiif (stream.codec_type === 'subtitle') {// mp4/mov only supports mov_text, so convert it https://stackoverflow.com/a/17584272/6519037// https://github.com/mifi/lossless-cut/issues/418- if (['mov', 'mp4'].includes(outFormat) && stream.codec_name !== 'mov_text') {+ if (isMov(outFormat) && stream.codec_name !== 'mov_text') {addCodecArgs('mov_text');} else if (outFormat === 'matroska' && stream.codec_name === 'mov_text') {// matroska doesn't support mov_text, so convert it to SRT (popular codec)@@ -144,7 +146,7 @@ function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposiaddCodecArgs('copy');}- if (['mov', 'mp4'].includes(outFormat)) {+ if (isMov(outFormat)) {if (['0x0000', '0x31637668'].includes(stream.codec_tag) && stream.codec_name === 'hevc') {args = [...args, `-tag:${outputIndex}`, 'hvc1'];}@@ -234,3 +236,12 @@ export function isAudioDefinitelyNotSupported(streams) {// TODO this could be improvedreturn audioStreams.every(stream => ['ac3'].includes(stream.codec_name));}++export function getVideoTimebase(videoStream) {+ const timebaseMatch = videoStream.time_base && videoStream.time_base.split('/');+ if (timebaseMatch) {+ const timebaseParsed = parseInt(timebaseMatch[1], 10);+ if (!Number.isNaN(timebaseParsed)) return timebaseParsed;+ }+ return undefined;+}