castnow icon indicating copy to clipboard operation
castnow copied to clipboard

Make '--ffmpeg-ss' much quicker.

Open mhertz opened this issue 2 years ago • 0 comments

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)

mhertz avatar Oct 03 '23 12:10 mhertz

Hi, sorry for the delay. Mentioning pipx in the documentation makes a lot of sense, but not in README.md; it belongs in INSTALL.md.

newren avatar Jul 07 '24 00:07 newren

I think it make sense to at least mention in the readme that the package is available via pypi.

If you prefer I just keep the info about availability on pypi in README.md and move the hint on pipx to INSTALL.md

dalito avatar Jul 07 '24 18:07 dalito

I think it make sense to at least mention in the readme that the package is available via pypi.

If you prefer I just keep the info about availability on pypi in README.md and move the hint on pipx to INSTALL.md

I'd rather both were moved to INSTALL.md. For many, they'll install via apt/yum/dnf/brew/pacman/nix/pypi/pipx/etc. Everyone who uses one of these will believe their preference should get special mention, but I see no reason to call out one above the others.

newren avatar Jul 13 '24 06:07 newren

I moved the notes to INSTALL.md - hope it´s fine now.

dalito avatar Aug 17 '24 18:08 dalito