#!/bin/sh
# bash  "$d_bin"'video cut.sh'  
# www.BillHowell.ca   24Oct2017 initial, 30Jul2020 split off header


# this is a COPY of : 
#	"$d_bin""video production/video cut.sh"  
# videos, see : 
# 	"$d_bin""video production/video cut.sh" 
# 	"$d_bin""video production/trim video.sh"  
# 	"$d_web"'My sports & clubs/natural- FECC Fusion/231024 FECC webinar.txt'  	
#24************************24





#24************************24
# Table of Contents, generate with :
# $ grep  "^#]"  "$d_bin""video production/video cut.sh"  |  sed "s/^#\]/  /" 
#


#24************************24
# Setup, ToDos,   

# video timings:	"$d_bin"'video production/0_video capture - dimensions.ods'
# video capture:	"$d_bin"'video production/capture video.sh'
# examples		:	"$d_bin""video production/video cut.sh" 

# it is best to record videos one-by-one rather than split them - otherwise sound lags are bad, and there are many problems with snipping out bits

# use video_cut (ffmpeg) which is much faster than trimit (avconv) 

#+--+
# olde notes 
# see "/media/bill/HOWELL_BASE/System_maintenance/video/avconv/0_avconv notes.txt"
# 26Sep2016 18:34  for video snipping only (can't screen capture)  try avconv instead of recoredmydesktop
#24************************24




#*************
# Run

#]	video_cut(codecInn  codecOut  t_start  t_end  p_inn  p_out) save a segment of a video
#]    format of [t_start, t_end]= '00:00:00' -> hh:mm:ss

	video_cut()
{  
codecInn="$1"
codecOut="$2"
t_start=$(date --date="$3" +%s)
t_ender=$(date --date="$4" +%s)
t_durtn=$(( $t_ender - $t_start ))
p_inn="$5"
p_out="$6"
echo "f_source= $5"
echo "f_trimmd= $6"
echo "t_start= $t_start"
echo "t_ender= $t_ender"
echo "t_durtn= $t_durtn"
echo ""

if		[ "$codecInn" ==  "$codecOut"  ]; then
		ffmpeg -i "$p_inn" -vcodec copy -acodec copy  -ss $3  -t $t_durtn   "$p_out"
elif	[[ "$codecInn" =  "mts" &&  "$codecOut = "mov"" ]]; then	
		ffmpeg -i "$p_inn" -vcodec mjpeg -b 100M -acodec pcm_s16be "$p_out"
elif	[[ "$codecInn" =  "mts" &&  "$codecOut = "ogv"" ]]; then	
		ffmpeg -i "$p_inn" -vcodec mjpeg -b 100M -acodec avchd "$p_out"
elif	[[ "$codecInn" =  "mp4" &&  "$codecOut = "ogv"" ]]; then	
		ffmpeg -i "$p_inn" -codec:v libtheora -qscale:v 6 -codec:a libvorbis -qscale:a 6 "$p_out"
else	echo "video_cut error : unnown codec combination"
fi
}  

# 20:21$ t_start=$(date --date='00:22:50' +%s)
# 20:22$ t_ender=$(date --date='00:44:35' +%s)
# 20:23$ t_durtn=$(( $t_ender - $t_start ))
# 20:21$ echo $t_start		1698301370
# 20:23$ echo $t_durtn				1305
# 20:23$ echo $t_ender		1698302675
# >> OK

# 26Oct2023 Fusion Energy Council of Canada (FECC) example : 
	d_FECC="$d_PROJECTS"'9_My sports & clubs/FECC - Fusion Energy Council of Canada/231024 FECC webinar/'
	video_cut  mts  mts  '00:00:00'  '00:22:50'  "$d_FECC"'00005.MTS'  "$d_FECC"'Lawrence Livermore NatlLab, NISA, laser + Xray implosion, He-filled hohlraum 231024.MTS'  
	#video_cut  mts  mts  '00:22:50'  '00:44:35'  "$d_FECC"'00005.MTS'  "$d_FECC"'First Light, inertial fusion, one-sided drive 231024.MTS'  
	#video_cut  mts  mts  '00:44:35'  '00:46:33'  "$d_FECC"'00005.MTS'  "$d_FECC"'Marios Schollmeier, Marvel Fusion, ODIN direct drive nano-accelerator, pB fuel D-T  231024 v0.MTS'  

# 26Oct2023 join video segments - DON'T cat, just play sequentially
	#vlc "$d_FECC"'Marvel Fusion, ODIN direct drive nano-accelerator, pB fuel D-T  231024 v1.MTS'  "$d_FECC"'Marvel Fusion, ODIN direct drive nano-accelerator, pB fuel D-T 231024 v2.MTS' 





# to run  $ bash  "$d_bin"'video cut.sh'


# enddoc
