The swiss army knife of lossless video/audio editing
improve help sheet and add banner
Mikael Finstad2cea3c1a0347
diff --git a/package.json b/package.jsonindex b21cbbd6..5e2bff8d 100644--- a/package.json+++ b/package.json@@ -51,6 +51,7 @@"svg2png": "^4.1.1"},"dependencies": {+ "axios": "^0.19.2","bluebird": "^3.4.6","classnames": "^2.2.5","color": "^3.1.0",@@ -73,6 +74,7 @@"react": "^16.12.0","react-dom": "^16.12.0","react-hammerjs": "^1.0.1",+ "react-icons": "^3.9.0","react-sortable-hoc": "^1.5.3","react-use": "^13.24.0","read-chunk": "^2.0.0",diff --git a/src/HelpSheet.jsx b/src/HelpSheet.jsxindex 108f7f5b..47de8744 100644--- a/src/HelpSheet.jsx+++ b/src/HelpSheet.jsx@@ -1,14 +1,15 @@-const React = require('react');-const PropTypes = require('prop-types');+import React from 'react';+import { IoIosCloseCircleOutline } from 'react-icons/io';-/* eslint-disable react/jsx-one-expression-per-line */-const HelpSheet = ({ visible }) => {+const HelpSheet = ({ visible, onTogglePress, renderSettings }) => {if (visible) {return (<div className="help-sheet">+ <IoIosCloseCircleOutline role="button" onClick={onTogglePress} size={30} style={{ position: 'fixed', right: 0, top: 0, padding: 20 }} />+<h1>Keyboard shortcuts</h1><ul>- <li><kbd>H</kbd> Show/hide help</li>+ <li><kbd>H</kbd> Show/hide this screen</li><li><kbd>SPACE</kbd>, <kbd>k</kbd> Play/pause</li><li><kbd>J</kbd> Slow down video</li><li><kbd>L</kbd> Speed up video</li>@@ -23,16 +24,16 @@ const HelpSheet = ({ visible }) => {<li><kbd>+</kbd> Add cut segment</li><li><kbd>BACKSPACE</kbd> Remove current cut segment</li></ul>++ <p style={{ fontWeight: 'bold' }}>Hover mouse over buttons to see which function they have.</p>++ <h1 style={{ marginTop: 40 }}>Settings</h1>+ {renderSettings()}</div>);}return null;};-/* eslint-enable react/jsx-one-expression-per-line */--HelpSheet.propTypes = {- visible: PropTypes.bool.isRequired,-};-module.exports = HelpSheet;+export default HelpSheet;diff --git a/src/main.css b/src/main.cssindex 8ef52db8..87fd4d46 100644--- a/src/main.css+++ b/src/main.css@@ -17,21 +17,7 @@ body {cursor: default;}input, button, textarea, :focus {- outline: none; // You should add some other style for :focus to help UX/a11y-}--#player {- position: absolute;- top: 0;- left: 0;- right: 0;- bottom: 6rem;-}--#player video {- width: 100%;- height: 100%;- object-fit: contain;+ outline: none;}.button {@@ -114,25 +100,17 @@ input, button, textarea, :focus {width: 1px;}-#drag-drop-field {- padding: 15vw 0;- border: 2vw dashed #252525;- color: #303030;- margin: 7vw;- text-align: center;- white-space: nowrap;-}-.help-sheet {background: #525252;color: white;padding: 1em 2em;- position: absolute;+ position: fixed;left: 0;right: 0;top: 0;bottom: 0;z-index: 10;+ overflow-y: scroll;}.help-sheet h1 {diff --git a/src/mifi.js b/src/mifi.jsnew file mode 100644index 00000000..cbb39690--- /dev/null+++ b/src/mifi.js@@ -0,0 +1,11 @@+import axios from 'axios';++// eslint-disable-next-line import/prefer-default-export+export async function loadMifiLink() {+ try {+ const resp = await axios.get('https://mifi.no/losslesscut/config.json');+ return resp.data;+ } catch (err) {+ return undefined;+ }+}diff --git a/src/renderer.jsx b/src/renderer.jsxindex 116aa006..8b5edebb 100644--- a/src/renderer.jsx+++ b/src/renderer.jsx@@ -1,7 +1,9 @@-import React, { memo, useEffect, useState, useCallback } from 'react';+import React, { memo, useEffect, useState, useCallback, useRef } from 'react';+import { IoIosHelpCircle } from 'react-icons/io';import HelpSheet from './HelpSheet';import TimelineSeg from './TimelineSeg';+import { loadMifiLink } from './mifi';const electron = require('electron'); // eslint-disable-lineconst $ = require('jquery');@@ -33,29 +35,6 @@ const {const { dialog } = electron.remote;-function getVideo() {- return $('#player video')[0];-}--function seekAbs(val) {- const video = getVideo();- if (val == null || Number.isNaN(val)) return;-- let outVal = val;- if (outVal < 0) outVal = 0;- if (outVal > video.duration) outVal = video.duration;-- video.currentTime = outVal;-}--function seekRel(val) {- seekAbs(getVideo().currentTime + val);-}--function shortStep(dir) {- seekRel((1 / 60) * dir);-}-function withBlur(cb) {return (e) => {cb(e);@@ -72,6 +51,10 @@ function createSegment({ start, end } = {}) {};}+const dragPreventer = ev => {+ ev.preventDefault();+};+function doesPlayerSupportFile(streams) {// TODO improve, whitelist supported codecs insteadreturn !streams.find(s => ['hevc', 'prores'].includes(s.codec_name));@@ -111,9 +94,31 @@ const App = memo(() => {const [autoMerge, setAutoMerge] = useState(false);const [helpVisible, setHelpVisible] = useState(false);const [timecodeShowFrames, setTimecodeShowFrames] = useState(false);+ const [mifiLink, setMifiLink] = useState();++ const videoRef = useRef();++ function seekAbs(val) {+ const video = videoRef.current;+ if (val == null || Number.isNaN(val)) return;++ let outVal = val;+ if (outVal < 0) outVal = 0;+ if (outVal > video.duration) outVal = video.duration;++ video.currentTime = outVal;+ }++ const seekRel = useCallback((val) => {+ seekAbs(videoRef.current.currentTime + val);+ }, []);++ const shortStep = useCallback((dir) => {+ seekRel((1 / 60) * dir);+ }, [seekRel]);const resetState = useCallback(() => {- const video = getVideo();+ const video = videoRef.current;video.currentTime = 0;video.playbackRate = 1;@@ -249,7 +254,7 @@ const App = memo(() => {function onPlayingChange(val) {setPlaying(val);- if (!val) getVideo().playbackRate = 1;+ if (!val) videoRef.current.playbackRate = 1;}function onTimeUpdate(e) {@@ -322,10 +327,10 @@ const App = memo(() => {seekAbs((relX / $target[0].offsetWidth) * (duration || 0));}- const onPlaybackRateChange = () => setPlaybackRate(getVideo().playbackRate);+ const onPlaybackRateChange = () => setPlaybackRate(videoRef.current.playbackRate);const playCommand = useCallback(() => {- const video = getVideo();+ const video = videoRef.current;if (playing) return video.pause();return video.play().catch((err) => {@@ -428,7 +433,7 @@ const App = memo(() => {return;}try {- await captureFrame(customOutDir, filePath, getVideo(), currentTime, captureFormat);+ await captureFrame(customOutDir, filePath, videoRef.current, currentTime, captureFormat);} catch (err) {console.error(err);errorToast('Failed to capture frame');@@ -436,7 +441,7 @@ const App = memo(() => {}, [filePath, currentTime, captureFormat, customOutDir, html5FriendlyPath, dummyVideoPath]);const changePlaybackRate = useCallback((dir) => {- const video = getVideo();+ const video = videoRef.current;if (!playing) {video.playbackRate = 0.5; // dir * 0.5;video.play();@@ -517,9 +522,9 @@ const App = memo(() => {}}, [resetState, working, createDummyVideo, checkExistingHtml5FriendlyFile]);- useEffect(() => {- const toggleHelp = () => setHelpVisible(val => !val);+ const toggleHelp = () => setHelpVisible(val => !val);+ useEffect(() => {Mousetrap.bind('space', () => playCommand());Mousetrap.bind('k', () => playCommand());Mousetrap.bind('j', () => changePlaybackRate(-1));@@ -555,12 +560,12 @@ const App = memo(() => {};}, [addCutSegment, capture, changePlaybackRate, cutClick, playCommand, removeCutSegment,- setCutEnd, setCutStart,+ setCutEnd, setCutStart, seekRel, shortStep,]);useEffect(() => {- document.ondragover = ev => ev.preventDefault();- document.ondragend = document.ondragover;+ document.ondragover = dragPreventer;+ document.ondragend = dragPreventer;electron.ipcRenderer.send('renderer-ready');}, []);@@ -643,18 +648,18 @@ const App = memo(() => {createDummyVideo,]);- useEffect(() => {- function onDrop(ev) {- ev.preventDefault();- const { files } = ev.dataTransfer;- if (files.length < 1) return;- if (files.length === 1) load(files[0].path);- else showMergeDialog(Array.from(files).map(f => f.path), mergeFiles);- }+ const onDrop = useCallback((ev) => {+ ev.preventDefault();+ const { files } = ev.dataTransfer;+ if (files.length < 1) return;+ if (files.length === 1) load(files[0].path);+ else showMergeDialog(Array.from(files).map(f => f.path), mergeFiles);+ }, [load, mergeFiles]);+ useEffect(() => {document.body.addEventListener('drop', onDrop);return () => document.body.removeEventListener('drop', onDrop);- }, [load, mergeFiles]);+ }, [load, mergeFiles, onDrop]);function renderCutTimeInput(type) {const cutTimeManual = type === 'start' ? cutStartTimeManual : cutEndTimeManual;@@ -713,12 +718,149 @@ const App = memo(() => {background: 'rgba(255, 255, 255, 0.4)', padding: '.1em .4em', margin: '0 3px', fontSize: 13, borderRadius: '.3em',};+ function renderOutFmt({ width } = {}) {+ return (+ <select style={{ width }} defaultValue="" value={fileFormat} title="Format of current file" onChange={withBlur(e => setFileFormat(e.target.value))}>+ <option key="" value="" disabled>Out fmt</option>+ {detectedFileFormat && (+ <option key={detectedFileFormat} value={detectedFileFormat}>+ {detectedFileFormat}+ </option>+ )}+ {selectableFormats.map(f => <option key={f} value={f}>{f}</option>)}+ </select>+ );+ }++ function renderCaptureFormatButton() {+ return (+ <button+ type="button"+ title="Capture frame format"+ onClick={withBlur(toggleCaptureFormat)}+ >+ {captureFormat}+ </button>+ );+ }++ function renderSettings() {+ return (+ <table>+ <tbody>+ <tr>+ <td>Output format (default autodetected)</td>+ <td style={{ width: '50%' }}>{renderOutFmt()}</td>+ </tr>+ <tr>+ <td>In timecode show</td>+ <td>+ <button+ type="button"+ onClick={() => setTimecodeShowFrames(v => !v)}+ >+ {timecodeShowFrames ? 'frame numbers' : 'millisecond fractions'}+ </button>+ </td>+ </tr>+ <tr>+ <td>Auto merge segments to one file after export?</td>+ <td>+ <button+ type="button"+ onClick={toggleAutoMerge}+ >+ {autoMerge ? 'Auto merge segments to one file (am)' : 'Export separate segments (nm)'}+ </button>+ </td>+ </tr>++ <tr>+ <td>Cut mode</td>+ <td>+ <button+ type="button"+ onClick={toggleKeyframeCut}+ >+ {keyframeCut ? 'Nearest keyframe cut (kc) - will cut at the nearest keyframe' : 'Normal cut (nc) - cut accurate position but could leave an empty portion'}+ </button>+ </td>+ </tr>++ <tr>+ <td>Include treams</td>+ <td>+ <button+ type="button"+ onClick={toggleIncludeAllStreams}+ >+ {includeAllStreams ? 'include all streams (audio, video, subtitle, data) (all)' : 'include only primary streams (1 audio and 1 video stream only) (ps)'}+ </button>++ <div>+ Note that some streams like subtitles and data are not possible to cut and will therefore be transferred as is.+ </div>+ </td>+ </tr>++ <tr>+ <td>+ Delete audio?+ </td>+ <td>+ <button+ type="button"+ onClick={toggleStripAudio}+ >+ {stripAudio ? 'Delete all audio tracks' : 'Keep all audio tracks'}+ </button>+ </td>+ </tr>++ <tr>+ <td>Output directory</td>+ <td>+ <button+ type="button"+ onClick={setOutputDir}+ >+ {outputDir ? 'Custom output directory (cd)' : 'Output files to same directory as input (id)'}+ </button>+ <div>{outputDir}</div>+ </td>+ </tr>++ <tr>+ <td>+ Snapshot capture format+ </td>+ <td>+ {renderCaptureFormatButton()}+ </td>+ </tr>+ </tbody>+ </table>+ );+ }++ useEffect(() => {+ loadMifiLink().then(setMifiLink);+ }, []);+return (<div>{!filePath && (- <div id="drag-drop-field">- <div style={{ fontSize: '9vw' }}>DROP VIDEO</div>- <div>PRESS H FOR HELP</div>+ <div style={{ position: 'fixed', left: 0, right: 0, top: 0, bottom: '6rem', border: '2vmin dashed #252525', color: '#505050', margin: '5vmin', display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center', whiteSpace: 'nowrap' }}>+ <div style={{ fontSize: '9vmin' }}>DROP VIDEO</div>+ <div style={{ fontSize: '3vmin' }}>PRESS H FOR HELP</div>++ {mifiLink && mifiLink.loadUrl && (+ <div style={{ position: 'relative', margin: '3vmin', width: '60vmin', height: '20vmin' }}>+ <iframe src={mifiLink.loadUrl} title="iframe" style={{ background: 'rgba(0,0,0,0)', border: 'none', pointerEvents: 'none', width: '100%', height: '100%', position: 'absolute' }} />+ {/* eslint-disable-next-line jsx-a11y/interactive-supports-focus */}+ <div style={{ width: '100%', height: '100%', position: 'absolute', cursor: 'pointer' }} role="button" onClick={() => electron.shell.openExternal(mifiLink.targetUrl)} />+ </div>+ )}</div>)}@@ -746,8 +888,10 @@ const App = memo(() => {)}{/* eslint-disable jsx-a11y/media-has-caption */}- <div id="player">+ <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: '6rem', pointerEvents: 'none' }}><video+ ref={videoRef}+ style={{ width: '100%', height: '100%', objectFit: 'contain' }}src={fileUri}onRateChange={onPlaybackRateChange}onPlay={() => onPlayingChange(true)}@@ -901,15 +1045,7 @@ const App = memo(() => {</div><div className="left-menu">- <select style={{ width: 60 }} defaultValue="" value={fileFormat} title="Format of current file" onChange={withBlur(e => setFileFormat(e.target.value))}>- <option key="" value="" disabled>Out fmt</option>- {detectedFileFormat && (- <option key={detectedFileFormat} value={detectedFileFormat}>- {detectedFileFormat}- </option>- )}- {selectableFormats.map(f => <option key={f} value={f}>{f}</option>)}- </select>+ {renderOutFmt({ width: 30 })}<span style={infoSpanStyle} title="Playback rate">{round(playbackRate, 1) || 1}@@ -949,6 +1085,8 @@ const App = memo(() => {>{autoMerge ? 'am' : 'nm'}</button>++ <IoIosHelpCircle size={22} role="button" onClick={toggleHelp} style={{ verticalAlign: 'middle' }} /></div><div className="right-menu">@@ -1001,16 +1139,14 @@ const App = memo(() => {onClick={capture}/>- <button- type="button"- title="Capture frame format"- onClick={withBlur(toggleCaptureFormat)}- >- {captureFormat}- </button>+ {renderCaptureFormatButton()}</div>- <HelpSheet visible={!!helpVisible} />+ <HelpSheet+ visible={!!helpVisible}+ onTogglePress={toggleHelp}+ renderSettings={renderSettings}+ /></div>);});diff --git a/yarn.lock b/yarn.lockindex afa7c21b..09812c31 100644--- a/yarn.lock+++ b/yarn.lock@@ -534,6 +534,13 @@ axios@^0.19.0:follow-redirects "1.5.10"is-buffer "^2.0.2"+axios@^0.19.2:+ version "0.19.2"+ resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27"+ integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==+ dependencies:+ follow-redirects "1.5.10"+axobject-query@^2.0.2:version "2.1.2"resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.1.2.tgz#2bdffc0371e643e5f03ba99065d5179b9ca79799"@@ -4537,6 +4544,13 @@ react-hammerjs@^1.0.1:dependencies:hammerjs "^2.0.8"+react-icons@^3.9.0:+ version "3.9.0"+ resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-3.9.0.tgz#89a00f20a0e02e6bfd899977eaf46eb4624239d5"+ integrity sha512-gKbYKR+4QsD3PmIHLAM9TDDpnaTsr3XZeK1NTAb6WQQ+gxEdJ0xuCgLq0pxXdS7Utg2AIpcVhM1ut/jlDhcyNg==+ dependencies:+ camelcase "^5.0.0"+react-is@^16.8.1:version "16.12.0"resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.12.0.tgz#2cc0fe0fba742d97fd527c42a13bec4eeb06241c"