Skip to content

The swiss army knife of lossless video/audio editing

implement export single track

Mikael Finstad6093acee637e
diff --git a/src/App.jsx b/src/App.jsx
index f46fdd83..c3b658e3 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1144,6 +1144,9 @@ const App = memo(() => {
const validEdl = edl.filter((row) => (
(row.start === undefined || row.end === undefined || row.start < row.end)
&& (row.start === undefined || row.start >= 0)
+ // TODO: Cannot do this because duration is not yet set when loading a file
+ // && (row.start === undefined || (row.start >= 0 && row.start < duration))
+ // && (row.end === undefined || row.end < duration)
));
if (validEdl.length === 0) throw new Error(i18n.t('No valid segments found'));
@@ -1431,6 +1434,22 @@ const App = memo(() => {
electron.ipcRenderer.send('setAskBeforeClose', askBeforeClose && isFileOpened);
}, [askBeforeClose, isFileOpened]);
+ const extractSingleStream = useCallback(async (index) => {
+ if (!filePath || working) return;
+
+ try {
+ // setStreamsSelectorShown(false);
+ setWorking(i18n.t('Extracting track'));
+ await extractStreams({ customOutDir, filePath, streams: mainStreams.filter((s) => s.index === index) });
+ openDirToast({ dirPath: outputDir, text: i18n.t('Track has been extracted') });
+ } catch (err) {
+ errorToast(i18n.t('Failed to extract track'));
+ console.error('Failed to extract track', err);
+ } finally {
+ setWorking();
+ }
+ }, [customOutDir, filePath, mainStreams, outputDir, working]);
+
const extractAllStreams = useCallback(async () => {
if (!filePath) return;
@@ -1449,10 +1468,6 @@ const App = memo(() => {
}
}, [customOutDir, filePath, mainStreams, outputDir]);
- function onExtractAllStreamsPress() {
- extractAllStreams();
- }
-
const addStreamSourceFile = useCallback(async (path) => {
if (externalStreamFiles[path]) return;
const { streams } = await getAllStreams(path);
@@ -2022,7 +2037,8 @@ const App = memo(() => {
isCopyingStreamId={isCopyingStreamId}
toggleCopyStreamId={toggleCopyStreamId}
setCopyStreamIdsForPath={setCopyStreamIdsForPath}
- onExtractAllStreamsPress={onExtractAllStreamsPress}
+ onExtractAllStreamsPress={extractAllStreams}
+ onExtractStreamPress={extractSingleStream}
areWeCutting={areWeCutting}
shortestFlag={shortestFlag}
setShortestFlag={setShortestFlag}
diff --git a/src/StreamsSelector.jsx b/src/StreamsSelector.jsx
index 2215d0ee..3374e198 100644
--- a/src/StreamsSelector.jsx
+++ b/src/StreamsSelector.jsx
@@ -173,7 +173,7 @@ function onInfoClick(s, title) {
});
}
-const Stream = memo(({ filePath, stream, onToggle, copyStream, fileDuration, setEditingStream }) => {
+const Stream = memo(({ filePath, stream, onToggle, copyStream, fileDuration, setEditingStream, onExtractStreamPress }) => {
const { t } = useTranslation();
const bitrate = parseInt(stream.bit_rate, 10);
@@ -213,6 +213,7 @@ const Stream = memo(({ filePath, stream, onToggle, copyStream, fileDuration, set
<td>
<FaInfoCircle role="button" onClick={() => onInfoClick(stream, t('Track info'))} size={22} />
<FiEdit title={t('Edit track metadata')} role="button" size={20} style={{ padding: '0 5px' }} onClick={() => setEditingStream({ streamId: stream.index, path: filePath })} />
+ <FaFileExport title={t('Extract this track as file')} role="button" onClick={onExtractStreamPress} size={18} />
</td>
</tr>
);
@@ -256,7 +257,7 @@ const fileStyle = { marginBottom: 10, backgroundColor: 'rgba(0,0,0,0.04)', paddi
const StreamsSelector = memo(({
mainFilePath, mainFileFormatData, streams: mainFileStreams, isCopyingStreamId, toggleCopyStreamId,
- setCopyStreamIdsForPath, onExtractAllStreamsPress, externalFiles, setExternalFiles,
+ setCopyStreamIdsForPath, onExtractStreamPress, onExtractAllStreamsPress, externalFiles, setExternalFiles,
showAddStreamSourceDialog, shortestFlag, setShortestFlag, nonCopiedExtraStreams,
AutoExportToggler, customTagsByFile, setCustomTagsByFile, customTagsByStreamId, setCustomTagsByStreamId,
}) => {
@@ -303,6 +304,7 @@ const StreamsSelector = memo(({
onToggle={(streamId) => toggleCopyStreamId(mainFilePath, streamId)}
setEditingStream={setEditingStream}
fileDuration={getFormatDuration(mainFileFormatData)}
+ onExtractStreamPress={() => onExtractStreamPress(stream.index)}
/>
))}
</tbody>