Skip to content

armgit / my-yt

Public Imported from GitHub
0

A clean and minimal youtube frontend, without all the ads and whistles

JavaScript

feat: transcoding video to h265 for max compat

Christian Feid19983f37f77
diff --git a/lib/youtube.js b/lib/youtube.js
index 83ab840..dc14d7e 100644
--- a/lib/youtube.js
+++ b/lib/youtube.js
@@ -1,6 +1,7 @@
import spawn from 'nano-spawn'
import fs from 'fs'
import * as ytdlp from './yt-dlp.js'
+import { exec, execSync } from 'child_process'
export const ytUrlRegExp = /^(https?:\/\/)?(www\.)?(youtube\.com\/watch\?v=|youtu\.be\/)([^&\s]+).*/
@@ -24,6 +25,20 @@ export async function downloadVideo(id, repo, callback = () => {}) {
format = location.substring(location.lastIndexOf('.') + 1)
}
}
+ if (process.env.SKIP_TRANSCODING !== 'true') {
+ try {
+ console.log(`transcoding video ${id} to h264`)
+ exec(`ffmpeg -i ${location} -vcodec libx264 -acodec aac -movflags +faststart ${location.replace(format, `-h264.${format}`)}`, (error) => {
+ if (!error) {
+ console.log(`succcessfully transcoded video ${id} to h264`)
+ return execSync(`mv ${location.replace(format, `-h264.${format}`)} ${location}`)
+ }
+ console.error(error)
+ })
+ } catch (error) {
+ console.error('failed to transcode video to h264', error)
+ }
+ }
if (!repo.getVideo(id)) {
const video = await getVideo(id)