Skip to content
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

Open
wants to merge 2 commits into
base: aria2c_forRealNow
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/CommandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

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

alias: 'c',
describe: 'If enabled concatenate videos in the order they are typed in the file',
type: 'boolean',
default: false,
demandOption: false
},
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.',
Expand Down
25 changes: 25 additions & 0 deletions src/destreamer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Collaborator

@lukaarma lukaarma Nov 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use fs.writeFileSync for consistency please

Copy link
Author

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
You could take a look at pipes in node to handle file redirection, if your up to the task.
If not this way is perfectly fine and I'll approve, let me know.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look at this and see if I can do it.

Copy link
Owner

@snobu snobu Nov 4, 2020

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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');
Expand Down