1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-23 02:42:37 +01:00

fix a bug

where a h265 file would not auto convert to supported format, because png was identified as a playable video stream
fixes #931
This commit is contained in:
Mikael Finstad 2021-11-17 12:09:53 +07:00
parent 189056dfcd
commit 2d705e5454
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26
3 changed files with 23 additions and 15 deletions

View File

@ -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 files
if (!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 {

View File

@ -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;

View File

@ -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 audio
export function doesPlayerSupportFile(streams) {
const videoStreams = streams.filter(s => s.codec_type === 'video');
const videoStreams = getVideoStreams(streams);
// Don't check audio formats, assume all is OK
if (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));
}