-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added concatenation function to downloadVideo #274
base: aria2c_forRealNow
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,13 @@ export const argv: any = yargs.options({ | |
describe: 'The username used to log into Microsoft Stream (enabling this will fill in the email field for you).', | ||
demandOption: false | ||
}, | ||
concat: { // FOR CONCATENATING VIDEOS | ||
alias: 'c', | ||
describe: 'If enabled concatenate videos in the order they are typed in the file', | ||
type: 'boolean', | ||
default: false, | ||
demandOption: false | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move it down the options list, below closedCaptions, so that the required/most important options can be seen first |
||
videoUrls: { | ||
alias: 'i', | ||
describe: 'List of urls to videos or Microsoft Stream groups.', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,6 +347,31 @@ async function downloadVideo(videoGUIDs: Array<string>, | |
logger.info(`Video no.${videos.indexOf(video) + 1} downloaded!!\n\n`); | ||
} | ||
|
||
// START CONCATENATE | ||
if(argv.concat){ | ||
logger.info("Concatenating videos..."); | ||
let concatFiles = ""; | ||
let concatName = `videos_concatenated ${videos.length}`; | ||
for(const video of videos){ | ||
concatFiles += ("file '" + video.outPath + "'\n"); | ||
logger.info("file " + video.outPath); | ||
} | ||
|
||
// Create a file containg all videos path | ||
await fs.promises.writeFile('files.txt', concatFiles); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use fs.writeFileSync for consistency please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the moment I did this and fixed CommandLineParser. I will try to figure out how to work with stream and pipelines to merge file using "Nodejs vanilla" without ffmpeg |
||
|
||
const concatCommand = ( | ||
// set video concat settings | ||
`ffmpeg -f concat -safe 0 -protocol_whitelist file,http,https,tcp,tls,crypto ` + | ||
// add video list | ||
`-i files.txt ` + | ||
// copy codec and output path | ||
`-c copy videos/${concatName}.mkv` | ||
); | ||
execSync(concatCommand, {stdio: 'ignore'}); //TODO: remove video files after they have been concateated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using FFmpeg you could concatenate the video by literally concatenating the file byte per byte. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will look at this and see if I can do it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, no! What are we concatenating here, segments or entire finished videos? If the latter, you can't simply concatenate bytes together since every .mkv or .mp4 file has its own header with track/codec/atoms information so you absolutely positively need ffmpeg to handle the concat as it will require reencoding almost every time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are concatenating finished videos, but at the end of the concatenation the code won't delete single video files. |
||
} | ||
// END CONCATENATE | ||
|
||
logger.info('Exiting, this will take some seconds...'); | ||
|
||
logger.debug('[destreamer] closing downloader socket'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code it's clear, there's no need for a comment here :D