forked from wulkano/Kap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support HEVC files in the editor (wulkano#626)
Fixes wulkano#341
- Loading branch information
1 parent
abf2ed1
commit fb017c8
Showing
13 changed files
with
160 additions
and
1,300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* eslint-disable array-element-newline */ | ||
'use strict'; | ||
const path = require('path'); | ||
const tmp = require('tmp'); | ||
const ffmpeg = require('@ffmpeg-installer/ffmpeg'); | ||
const util = require('electron-util'); | ||
const execa = require('execa'); | ||
|
||
const {track} = require('../common/analytics'); | ||
|
||
const ffmpegPath = util.fixPathForAsarUnpack(ffmpeg.path); | ||
|
||
const getEncoding = async filePath => { | ||
try { | ||
await execa(ffmpegPath, ['-i', filePath]); | ||
} catch (error) { | ||
return /.*: Video: (.*?) \(.*/.exec(error.stderr)[1]; | ||
} | ||
}; | ||
|
||
// `ffmpeg -i original.mp4 -vcodec libx264 -crf 27 -preset veryfast -c:a copy output.mp4` | ||
const convertToH264 = async inputPath => { | ||
const outputPath = tmp.tmpNameSync({postfix: path.extname(inputPath)}); | ||
track('encoding/converted/hevc'); | ||
|
||
await execa(ffmpegPath, [ | ||
'-i', inputPath, | ||
'-vcodec', 'libx264', | ||
'-crf', '27', | ||
'-preset', 'veryfast', | ||
'-c:a', 'copy', | ||
outputPath | ||
]); | ||
|
||
return outputPath; | ||
}; | ||
|
||
module.exports = { | ||
getEncoding, | ||
convertToH264 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use strict'; | ||
|
||
const fileIcon = require('file-icon'); | ||
|
||
const getAppIcon = async () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
|
||
const {supportedVideoExtensions} = require('../common/constants'); | ||
const {openEditorWindow} = require('../editor'); | ||
const {getEncoding, convertToH264} = require('./encoding'); | ||
|
||
const fileExtensions = supportedVideoExtensions.map(ext => `.${ext}`); | ||
|
||
const openFiles = (...filePaths) => { | ||
return Promise.all( | ||
filePaths | ||
.filter(filePath => fileExtensions.includes(path.extname(filePath).toLowerCase())) | ||
.map(async filePath => { | ||
const encoding = await getEncoding(filePath); | ||
if (encoding.toLowerCase() === 'hevc') { | ||
openEditorWindow(await convertToH264(filePath), {originalFilePath: filePath}); | ||
} else { | ||
openEditorWindow(filePath); | ||
} | ||
}) | ||
); | ||
}; | ||
|
||
module.exports = openFiles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.