refactor/reuse

pull/1233/head
Mikael Finstad 4 years ago
parent ecef90135b
commit 1849679448
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -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 = {

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

@ -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, s
const 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 {

@ -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, manuallyCopyDisposi
if (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, manuallyCopyDisposi
addCodecArgs('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 improved
return 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;
}

Loading…
Cancel
Save