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

Make '--ffmpeg-ss' much quicker. #274

Open
mhertz opened this issue Oct 3, 2023 · 0 comments
Open

Make '--ffmpeg-ss' much quicker. #274

mhertz opened this issue Oct 3, 2023 · 0 comments

Comments

@mhertz
Copy link

mhertz commented Oct 3, 2023

As title, I was annoyed about often needing wait 15+ minutes when needing seek in --tomp4 mode, as the option is added to ffmeg after the '-i -', and also would crash when the seek was over 35m.

I patched the source(in a dep to castnow) to apply that '-ss' option, when given, before the '-i -' input assignment, so starts in few secs instead often 15+ minutes, and doesn't crash. Note '-ss' is still left also after the input assignment here, but doesn't matter I tested, so was lazy and just left as is, when no ill effect regardless. Last, I added a '-copyts' arg because needed to not loose sync with subs when '-ss' before the input.

Here's my patch: ('/usr/lib/node_modules/castnow/node_modules/stream-transcoder/lib/transcoder.js')

--- transcoder-orig.js	2023-10-03 13:32:38.024691518 +0200
+++ transcoder.js	2023-10-03 13:28:21.004696398 +0200
@@ -243,6 +243,7 @@
 		
 		if ('string' == typeof this.source) a = [ '-i', this.source ].concat(a);
 		else a = [ '-i', '-' ].concat(a);
+		if (this.args['ss']) a = [ '-ss', this.args['ss'].pop(), '-copyts' ].concat(a);
 		
 		//console.log('Spawning ffmpeg ' + a.join(' '));
 		

Btw, here's my castnow shell-function for chromecast unsupported video, with subs and optional seek time as extra arg:

castnow2() {
	time="00:00:00"
	[[ "$2" != "" ]] && time="$2"
	sub=$(echo "$1" | sed -e 's/\.[^.]*$//').srt
	file "$sub" | grep UTF >/dev/null || (iconv -f iso-8859-1 -t utf-8 "$sub" -o tmp.srt && mv tmp.srt "$sub")
	[[ -e "$sub" ]] && cp "$sub" ~/video/out.srt
	if [[ ${1: -4} == ".mp4" ]]; then
		qt-faststart "$1" ~/video/out.mp4 >/dev/null
		[[ -e "$sub" ]] && castnow --command down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,up,up,up,up,up --tomp4 --ffmpeg-ss "$time" --ffmpeg-f matroska --ffmpeg-preset ultrafast --ffmpeg-tune fastdecode --ffmpeg-vf "subtitles=/home/martin/video/out.srt:force_style='BorderStyle=3'" --ffmpeg-ac 2 --ffmpeg-af dynaudnorm=f=75:g=11 ~/video/out.mp4
		[[ -e "$sub" ]] || castnow --command down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,up,up,up,up,up --tomp4 --ffmpeg-ss "$time" --ffmpeg-f matroska --ffmpeg-preset ultrafast --ffmpeg-tune fastdecode --ffmpeg-ac 2 --ffmpeg-af dynaudnorm=f=75:g=11 ~/video/out.mp4
		rm ~/video/out.mp4
	else
		[[ -e "$sub" ]] && castnow --command down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,up,up,up,up,up --tomp4 --ffmpeg-ss "$time" --ffmpeg-f matroska --ffmpeg-preset ultrafast --ffmpeg-tune fastdecode --ffmpeg-vf "subtitles=/home/martin/video/out.srt:force_style='BorderStyle=3'" --ffmpeg-ac 2 --ffmpeg-af dynaudnorm=f=75:g=11 $1
		[[ -e "$sub" ]] || castnow --command down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,down,up,up,up,up,up --tomp4 --ffmpeg-ss "$time" --ffmpeg-f matroska --ffmpeg-preset ultrafast --ffmpeg-tune fastdecode --ffmpeg-ac 2 --ffmpeg-af dynaudnorm=f=75:g=11 $1
	fi
	[[ -e "$sub" ]] && rm ~/video/out.srt
}

It has some fixes for videos not otherwise working transcoded(qt-faststart, subs-fix and forcing mkv), and I added a volume normalization filter, and need those down/up commands to not blow out my speakers/ears as don't use my TV remote which is at max.

Then just:
castnow2 <video> [xx:xx:xx]
(For seeking no need pad with 0's or specify hour if under an hour, e.g '32:9' , is '00:32:09' etc. - Srt subs with same name, except extension, auto-loaded)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant