@@ -21,7 +21,7 @@ FFMPEG_LOGLEVEL=${FFMPEG_LOGLEVEL:-warning}
2121
2222mpvc_cut_ffmpeg ()
2323{
24- " $FFMPEG " -hide_banner -loglevel " $LOGLEVEL " -i " $path " -ss " $pointA " -to " $pointB " -- " $@ "
24+ " $FFMPEG " -hide_banner -loglevel " $FFMPEG_LOGLEVEL " -- " $@ "
2525}
2626
2727mpvc_cutfile ()
@@ -30,48 +30,70 @@ mpvc_cutfile()
3030 local path=" $2 "
3131 local pointA=" $3 "
3232 local pointB=" $4 "
33+ local length=" $( mpvc -f ' %length%' ) "
3334
3435 if [ -z " $path " ] || [ ! -f " $path " ]; then usage 1; fi
3536 if [ -z " $pointA " ] || [ " $pointA " = " no" ]; then usage 1; fi
36- if [ -z " $pointB " ] || [ " $pointB " = " no" ]; then pointB=" $( mpvc -f " %length%" ) " ; fi
37+ if [ -z " $pointB " ] || [ " $pointB " = " no" ]; then pointB=" $length " ; fi
38+
39+ if ! printf ' %f' " $pointA " > /dev/null 2>&1 ; then usage 1; fi
40+ if ! printf ' %f' " $pointB " > /dev/null 2>&1 ; then usage 1; fi
3741
3842 local fileExt=" ${path#* .} "
3943 local infile=" ${path##*/ } "
4044 local infile=" ${infile## " $fileExt " } "
41- local outfile=" ${outfile:- ${infile} _${pointA} _${pointB} } "
42- LOGLEVEL=${LOGLEVEL:- warning}
45+ local outfile=" ${infile} _${pointA} _${pointB} "
46+
47+ outfile=$( printf ' %s' " $outfile " | sed ' s/[^a-zA-Z0-9._-]/_/g' )
4348
4449 echo " # $PROGNAME $operation $pointA $pointB $fileExt in $infile out $outfile "
4550
4651 case " $operation " in
4752 vidcord)
4853 # perform lossy transcode to x264
4954 mpvc_cut_ffmpeg \
50- -max_muxing_queue_size 1024 \
51- -sws_flags lanczos -vf " scale=-1:720" \
52- -c:v libx264 -crf 25 -preset fast \
53- -c:a copy -map 0 -f mp4 " $outfile .mp4"
55+ -i " $path " -ss " $pointA " -to " $pointB " \
56+ -max_muxing_queue_size 1024 \
57+ -sws_flags lanczos -vf " scale=-1:720" \
58+ -c:v libx264 -crf 25 -preset fast \
59+ -c:a copy -map 0 -f mp4 " $outfile .mp4"
5460 ;;
5561 lossless)
56- mpvc_cut_ffmpeg -c:v libx265 -x265-params lossless=1 " $outfile .mp4"
62+ mpvc_cut_ffmpeg \
63+ -i " $path " -ss " $pointA " -to " $pointB " \
64+ -c:v libx265 -x265-params lossless=1 " $outfile .mp4"
5765 ;;
5866 lossy)
59- mpvc_cut_ffmpeg " $outfile .mp4"
67+ mpvc_cut_ffmpeg \
68+ -i " $path " -ss " $pointA " -to " $pointB " \
69+ " $outfile .mp4"
6070 ;;
6171 dryrun)
62- mpvc_cut_ffmpeg -f null /dev/null
72+ mpvc_cut_ffmpeg \
73+ -i " $path " -ss " $pointA " -to " $pointB " \
74+ -f null /dev/null
75+ ;;
76+ default)
77+ mpvc_cut_ffmpeg \
78+ -i " $path " -ss " $pointA " -to " $pointB " \
79+ -c copy -map 0 " $outfile .$fileExt "
6380 ;;
6481 * )
65- mpvc_cut_ffmpeg -c copy -map 0 " $outfile . $fileExt "
82+ usage
6683 ;;
6784 esac
6885}
6986
7087mpvc_cut ()
7188{
72- mpvc_cutfile " $operation " " $( mpvc g ' path' ) " " $( mpvc g ' ab-loop-a' ) " " $( mpvc g ' ab-loop-b' ) "
89+ local path=$( mpvc g ' path' ) || usage 1
90+ local pointA=$( mpvc g ' ab-loop-a' ) || usage 1
91+ local pointB=$( mpvc g ' ab-loop-b' ) || usage 1
92+
93+ mpvc_cutfile " $operation " " $path " " $pointA " " $pointB "
7394}
7495
96+
7597mpvc_cut_vres ()
7698{
7799 $( command -v xrandr) | awk '
@@ -106,14 +128,16 @@ mpvc_screencast()
106128 local vres=" $( mpvc_cut_vres) "
107129 local asrc=" $( mpvc_cut_asrc) "
108130
109- local fout=" ${fout :- mpvc-cast-$(date -Iseconds | sed ' s/:/-/g ' ).mkv} "
110- local framerate=" ${framerate :- 25} "
131+ local fout=" mpvc-cast-$( date +%Y%m%d-%H%M%S ) .mkv"
132+ local framerate=" 25 "
111133
112- if [ -z " $vres " ]; then usage; fi
113- if [ -z " $asrc " ]; then usage; fi
134+ if [ -z " $vres " ]; then usage 1 ; fi
135+ if [ -z " $asrc " ]; then usage 1 ; fi
114136
115137 echo " # $PROGNAME : recording vres $vres asrc $asrc to $fout (ctl+c to finish)"
116- " $FFMPEG " -hide_banner -loglevel " $FFMPEG_LOGLEVEL " -video_size " $vres " -framerate " $framerate " -f x11grab -i :0.0 -f pulse -ac 2 -i " $asrc " " $fout "
138+ " $FFMPEG " -hide_banner -loglevel " $FFMPEG_LOGLEVEL " \
139+ -video_size " $vres " -framerate " $framerate " \
140+ -f x11grab -i :0.0 -f pulse -ac 2 -i " $asrc " " $fout "
117141}
118142
119143usage ()
0 commit comments