This commit is contained in:
Luke 2019-11-07 07:44:50 -08:00
parent 89fdfc7e78
commit 2ec1960ebe

View file

@ -294,7 +294,7 @@ function parseStreams() {
export SUB_COUNT=$("$JQ" 'length' "${STREAMS_SUB}") export SUB_COUNT=$("$JQ" 'length' "${STREAMS_SUB}")
# shellcheck disable=SC2016 # shellcheck disable=SC2016
"$JQ" 'reduce .streams[] as $item ([]; if ($item.codec_type == "audio") then [.[],$item] else . end) | reduce .[] as $item ([]; [.[],{t:($item.tags.title),i:($item.index),lang:$item.tags.language, disposition:$item.disposition}]) | reduce .[] as $item ([]; [.[],{t:($item.t // ($item.lang + "-" + ($item.i | tostring))),i:$item.i,lang:$item.lang,disposition:$item.disposition}])' "${STREAMS_ALL}" > "${STREAMS_AUDIO}" "$JQ" 'reduce .streams[] as $item ([]; if ($item.codec_type == "audio") then [.[],$item] else . end) | reduce .[] as $item ([]; [.[],{t:($item.tags.title),i:($item.index),lang:$item.tags.language, disposition:$item.disposition}]) | reduce .[] as $item ([]; [.[],{t:($item.t // ($item.lang + "-" + ($item.i | tostring))),i:$item.i,lang:$item.lang,disposition:$item.disposition}])' "${STREAMS_ALL}" > "${STREAMS_AUDIO}"
export AUDIO_COUNT=$("$JQ" 'length' "${STREAMS_SUB}") export AUDIO_COUNT=$("$JQ" 'length' "${STREAMS_AUDIO}")
} }
@ -306,8 +306,8 @@ function listSubtitles() {
printf "Num: %4s %s\n" "LANG" "Subtitle Title String" printf "Num: %4s %s\n" "LANG" "Subtitle Title String"
echo "---------------------------------" echo "---------------------------------"
for iSUB in $(seq 0 $(($SUB_COUNT-1))); do for iSUB in $(seq 0 $(($SUB_COUNT-1))); do
X_TITLE=$($JQ '.['$iSUB'].t' $STREAMS_SUB) X_TITLE=$($JQ '.['$iSUB'].t' $STREAMS_SUB | tr -d '"')
X_INDEX=$($JQ '.['$iSUB'].i' $STREAMS_SUB) X_INDEX=$($JQ '.['$iSUB'].i' $STREAMS_SUB | tr -d '"')
X_LANG=$($JQ '.['$iSUB'].lang' $STREAMS_SUB) X_LANG=$($JQ '.['$iSUB'].lang' $STREAMS_SUB)
printf " %2d: %4s %s\n" $X_INDEX $X_LANG "$X_TITLE" printf " %2d: %4s %s\n" $X_INDEX $X_LANG "$X_TITLE"
done done
@ -315,6 +315,22 @@ function listSubtitles() {
return return
} }
function listAudioTracks() {
# TODO:
echo ""
echo "available audio tracks:"
printf "Num: %4s %s\n" "LANG" "Title String"
echo "---------------------------------"
for iAUDIO in $(seq 0 $(($AUDIO_COUNT-1))); do
X_TITLE=$($JQ '.['$iAUDIO'].t' $STREAMS_AUDIO | tr -d '"')
X_INDEX=$($JQ '.['$iAUDIO'].i' $STREAMS_AUDIO | tr -d '"')
X_LANG=$($JQ '.['$iAUDIO'].lang' $STREAMS_AUDIO)
printf " %2d: %4s %s\n" $X_INDEX $X_LANG "$X_TITLE"
done
echo ""
return
}
function selectSubs() { function selectSubs() {
# TODO: handle multiple subtitle files # TODO: handle multiple subtitle files
# TODO: verify the the subtitle index is legal # TODO: verify the the subtitle index is legal
@ -350,6 +366,7 @@ function selectSubs() {
fi fi
if [[ $AUDIO_COUNT -gt 1 ]]; then if [[ $AUDIO_COUNT -gt 1 ]]; then
if [[ $OPTS_SELAUDIO -lt 0 ]]; then
LANG_TEST=$($JQ '[.[].lang] | index("jpn")' "$STREAMS_AUDIO") LANG_TEST=$($JQ '[.[].lang] | index("jpn")' "$STREAMS_AUDIO")
echo " > WARNING: Multiple audio streams!" echo " > WARNING: Multiple audio streams!"
printf " Using default selection rules... " printf " Using default selection rules... "
@ -362,6 +379,9 @@ function selectSubs() {
echo "Japanese audio found" echo "Japanese audio found"
export AUDIO_INDEX=$($JQ '.['$LANG_TEST'].i' "$STREAMS_AUDIO") export AUDIO_INDEX=$($JQ '.['$LANG_TEST'].i' "$STREAMS_AUDIO")
fi fi
else
AUDIO_INDEX=$OPTS_SELAUDIO
fi
export FF_AUDIO="-map 0:$AUDIO_INDEX -map 0:v:0" export FF_AUDIO="-map 0:$AUDIO_INDEX -map 0:v:0"
else else
export FF_AUDIO="" export FF_AUDIO=""
@ -443,6 +463,7 @@ function alertUser() {
OPTS_KLOBBER=false OPTS_KLOBBER=false
OPTS_LISTSUBS=false OPTS_LISTSUBS=false
OPTS_SELSUB=-1 OPTS_SELSUB=-1
OPTS_SELAUDIO=-1
OPTS_LISTSUBS=false OPTS_LISTSUBS=false
OPTS_FORCESOFT=false OPTS_FORCESOFT=false
OPTS_FORCEPARTSOFT=false OPTS_FORCEPARTSOFT=false
@ -505,13 +526,21 @@ while true; do
shift 2 shift 2
continue continue
;; ;;
"-a")
OPTS_SELAUDIO="$2"
#TODO: verify legal subtitle track number convention"
echo "TODO: verify legal audio track number convention"
echo ">> !! Selecting audio track #${OPTS_SELAUDIO}"
shift 2
continue
;;
"--psoft") "--psoft")
OPTS_FORCEPARTSOFT=true OPTS_FORCEPARTSOFT=true
echo ">> !! forcing software encoding." echo ">> !! forcing software encoding."
shift shift
continue continue
;; ;;
"--audio") "--lpf")
OPTS_LPF_AUDIO=true OPTS_LPF_AUDIO=true
OPTS_TRANS_AUDIO=true OPTS_TRANS_AUDIO=true
echo ">> !! low pass filter audio to AAC." echo ">> !! low pass filter audio to AAC."
@ -567,11 +596,13 @@ while true; do
--soft force software decode and encode --soft force software decode and encode
--psoft use software encoding (allow hardware decode when available) --psoft use software encoding (allow hardware decode when available)
--audiofix transcode audio --audiofix transcode audio
--audio transcode audio, and low-pass filter as well --lpf transcode audio, and low-pass filter as well
-l list subtitles (no encoding) -l list subtitles and audio tracks (no encoding)
-s <#> select specific subtitle track number -s <#> select specific subtitle track number
#TODO: verify legal subtitle track number convention #TODO: verify legal subtitle track number convention
-a <#> select specific subtitle track number
#TODO: verify legal subtitle track number convention
-d debug (no cleanup) -d debug (no cleanup)
--dry dry run (no encoding) --dry dry run (no encoding)
@ -587,13 +618,17 @@ _EOT
done done
# Now parse POSITIONAL ARGUMENTS # Now parse POSITIONAL ARGUMENTS
if [[ $# -ne 2 ]]; then if [[ $# -eq 2 || $OPTS_derived_NO_OUTPUT == true ]]; then
INPUT_VIDEO="$(readlink -f "$1")"
if [[ $# -eq 2 ]]; then
OUTPUT_VIDEO="$2"
else
OUTPUT_VIDEO="/dev/null"
fi
else
echo "ERROR: Incorrect number of positional arguments. Expected 2, got $#" echo "ERROR: Incorrect number of positional arguments. Expected 2, got $#"
echo " $(basename $0) [args] <input> <output>" echo " $(basename $0) [args] <input> <output>"
exit exit
else
INPUT_VIDEO="$(readlink -f "$1")"
OUTPUT_VIDEO="$2"
fi fi
############### ###############
@ -616,6 +651,7 @@ parseStreams
# Now! If OPTS_LISTSUBS is defined, then we branch to list subs and exit. # Now! If OPTS_LISTSUBS is defined, then we branch to list subs and exit.
if [[ "$OPTS_LISTSUBS" == "true" ]]; then if [[ "$OPTS_LISTSUBS" == "true" ]]; then
listSubtitles listSubtitles
listAudioTracks
exit exit
fi fi
# ask the user for the subtitle file if more than one is available # ask the user for the subtitle file if more than one is available