The swiss army knife of lossless video/audio editing
fix a bug
Mikael Finstad2d705e54547a
diff --git a/src/App.jsx b/src/App.jsxindex d028e6e2..53ece6c5 100644--- a/src/App.jsx+++ b/src/App.jsx@@ -48,7 +48,7 @@ import {defaultProcessedCodecTypes, getStreamFps, isCuttingStart, isCuttingEnd,readFileMeta, getFormatData, renderThumbnails as ffmpegRenderThumbnails,extractStreams, getAllStreams, runStartupCheck,- isStreamThumbnail, isAudioDefinitelyNotSupported, isIphoneHevc, tryReadChaptersToEdl,+ isAudioDefinitelyNotSupported, isIphoneHevc, tryReadChaptersToEdl,getDuration, getTimecodeFromStreams, createChaptersFromSegments, extractSubtitleTrack,} from './ffmpeg';import { exportEdlFile, readEdlFile, saveLlcProject, loadLlcProject, readEdl } from './edlStore';@@ -58,7 +58,7 @@ import {checkDirWriteAccess, dirExists, openDirToast, isMasBuild, isStoreBuild, dragPreventer, doesPlayerSupportFile,isDurationValid, isWindows, filenamify, getOutFileExtension, generateSegFileName, defaultOutSegTemplate,hasDuplicates, havePermissionToReadFile, isMac, resolvePathIfNeeded, pathExists, html5ifiedPrefix, html5dummySuffix, findExistingHtml5FriendlyFile,- deleteFiles, getHtml5ifiedPath,+ deleteFiles, getHtml5ifiedPath, isStreamThumbnail, getAudioStreams, getVideoStreams,} from './util';import { formatDuration } from './util/duration';import { adjustRate } from './util/rate-calculator';@@ -1294,16 +1294,22 @@ const App = memo(() => {const timecode = autoLoadTimecode ? getTimecodeFromStreams(streams) : undefined;- const videoStream = streams.find(stream => stream.codec_type === 'video' && !isStreamThumbnail(stream));- const audioStream = streams.find(stream => stream.codec_type === 'audio');+ const videoStreams = getVideoStreams(streams);+ const audioStreams = getAudioStreams(streams);- const detectedFpsNew = videoStream ? getStreamFps(videoStream) : undefined;+ const videoStream = videoStreams[0];+ const audioStream = audioStreams[0];++ const haveVideoStream = !!videoStream;+ const haveAudioStream = !!audioStream;++ const detectedFpsNew = haveVideoStream ? getStreamFps(videoStream) : undefined;const shouldCopyStreamByDefault = (stream) => {if (!defaultProcessedCodecTypes.includes(stream.codec_type)) return false;// Don't enable thumbnail stream by default if we have a main video stream// It's been known to cause issues: https://github.com/mifi/lossless-cut/issues/308- if (isStreamThumbnail(stream) && videoStream) return false;+ if (haveVideoStream && isStreamThumbnail(stream)) return false;return true;};@@ -1324,7 +1330,7 @@ const App = memo(() => {// 'fastest' works with almost all video filesif (!hasLoadedExistingHtml5FriendlyFile && !doesPlayerSupportFile(streams) && validDuration) {setWorking(i18n.t('Converting to supported format'));- await html5ifyAndLoad(cod, fp, rememberConvertToSupportedFormat || 'fastest', !!videoStream, !!audioStream);+ await html5ifyAndLoad(cod, fp, rememberConvertToSupportedFormat || 'fastest', haveVideoStream, haveAudioStream);}try {diff --git a/src/ffmpeg.js b/src/ffmpeg.jsindex 671dcd19..56381e51 100644--- a/src/ffmpeg.js+++ b/src/ffmpeg.js@@ -5,7 +5,7 @@ import moment from 'moment';import i18n from 'i18next';import Timecode from 'smpte-timecode';-import { getOutPath, isDurationValid, getExtensionForFormat, isWindows, platform } from './util';+import { getOutPath, isDurationValid, getExtensionForFormat, isWindows, platform, getAudioStreams } from './util';const execa = window.require('execa');const { join } = window.require('path');@@ -540,12 +540,6 @@ export const defaultProcessedCodecTypes = [export const isMov = (format) => ['ismv', 'ipod', 'mp4', 'mov'].includes(format);-export function isStreamThumbnail(stream) {- return stream && stream.disposition && stream.disposition.attached_pic === 1;-}--const getAudioStreams = (streams) => streams.filter(stream => stream.codec_type === 'audio');-export function isAudioDefinitelyNotSupported(streams) {const audioStreams = getAudioStreams(streams);if (audioStreams.length === 0) return false;diff --git a/src/util.js b/src/util.jsindex 775f0cd8..8c0d86be 100644--- a/src/util.js+++ b/src/util.js@@ -133,13 +133,21 @@ export function dragPreventer(ev) {ev.preventDefault();}+export function isStreamThumbnail(stream) {+ return stream && stream.disposition && stream.disposition.attached_pic === 1;+}++export const getAudioStreams = (streams) => streams.filter(stream => stream.codec_type === 'audio');+export const getVideoStreams = (streams) => streams.filter(stream => stream.codec_type === 'video' && !isStreamThumbnail(stream));+// With these codecs, the player will not give a playback error, but instead only play audioexport function doesPlayerSupportFile(streams) {- const videoStreams = streams.filter(s => s.codec_type === 'video');+ const videoStreams = getVideoStreams(streams);// Don't check audio formats, assume all is OKif (videoStreams.length === 0) return true;// If we have at least one video that is NOT of the unsupported formats, assume the player will be able to play it natively// https://github.com/mifi/lossless-cut/issues/595+ // But cover art / thumbnail streams don't count e.g. hevc with a png stream (disposition.attached_pic=1)return videoStreams.some(s => !['hevc', 'prores', 'mpeg4'].includes(s.codec_name));}