mirror of
				https://github.com/KrumpetPirate/AAXtoMP3.git
				synced 2025-11-03 20:40:43 +01:00 
			
		
		
		
	use custom path for ffmpeg/ffprobe binaries
This commit is contained in:
		
							
								
								
									
										37
									
								
								AAXtoMP3
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								AAXtoMP3
									
									
									
									
									
								
							@@ -34,6 +34,7 @@ authorOverride=             # Override the author, ignoring the metadata
 | 
			
		||||
audibleCli=0                # Default off, Use additional data gathered from mkb79/audible-cli
 | 
			
		||||
aaxc_key=                   # Initialize variables, in case we need them in debug_vars
 | 
			
		||||
aaxc_iv=                    # Initialize variables, in case we need them in debug_vars
 | 
			
		||||
ffmpegPath=                 # Set a custom path, useful for using the updated version that supports aaxc
 | 
			
		||||
 | 
			
		||||
# -----
 | 
			
		||||
# Code tip Do not have any script above this point that calls a function or a binary.  If you do
 | 
			
		||||
@@ -88,6 +89,8 @@ while true; do
 | 
			
		||||
    --keep-author     ) keepArtist="$2";                                                shift 2 ;;
 | 
			
		||||
                      # Author override
 | 
			
		||||
    --author          ) authorOverride="$2";                                            shift 2 ;;
 | 
			
		||||
                      # Ffmpeg path override
 | 
			
		||||
    --ffmpeg-path     ) ffmpegPath="$2";                                                shift 2 ;;
 | 
			
		||||
                      # Command synopsis.
 | 
			
		||||
    -h | --help       ) printf "$usage" $0 ;                                            exit ;;
 | 
			
		||||
                      # Standard flag signifying the end of command line processing.
 | 
			
		||||
@@ -212,6 +215,16 @@ else
 | 
			
		||||
    SED="gsed"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Use custom ffmpeg (and ffprobe) binary ( --ffmpeg-path flag)
 | 
			
		||||
if [ -n "$ffmpegPath" ]; then
 | 
			
		||||
  FFMPEG="$ffmpegPath/ffmpeg"
 | 
			
		||||
  FFPROBE="$ffmpegPath/ffprobe"
 | 
			
		||||
else
 | 
			
		||||
  FFMPEG="ffmpeg"
 | 
			
		||||
  FFPROBE="ffprobe"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
debug_vars "ffmpeg/ffprobe paths" FFMPEG FFPROBE
 | 
			
		||||
 | 
			
		||||
# -----
 | 
			
		||||
# Detect which annoying version of grep we have
 | 
			
		||||
@@ -242,7 +255,7 @@ fi
 | 
			
		||||
 | 
			
		||||
# -----
 | 
			
		||||
# Detect ffmpeg and ffprobe
 | 
			
		||||
if [[ "x$(type -P ffmpeg)" == "x" ]]; then
 | 
			
		||||
if [[ "x$(type -P "$FFMPEG")" == "x" ]]; then
 | 
			
		||||
  echo "ERROR ffmpeg was not found on your env PATH variable"
 | 
			
		||||
  echo "Without it, this script will break."
 | 
			
		||||
  echo "INSTALL:"
 | 
			
		||||
@@ -255,7 +268,7 @@ fi
 | 
			
		||||
 | 
			
		||||
# -----
 | 
			
		||||
# Detect ffmpeg and ffprobe
 | 
			
		||||
if [[ "x$(type -P ffprobe)" == "x" ]]; then
 | 
			
		||||
if [[ "x$(type -P "$FFPROBE")" == "x" ]]; then
 | 
			
		||||
  echo "ERROR ffprobe was not found on your env PATH variable"
 | 
			
		||||
  echo "Without it, this script will break."
 | 
			
		||||
  echo "INSTALL:"
 | 
			
		||||
@@ -409,7 +422,7 @@ validate_aax() {
 | 
			
		||||
  set +e errexit
 | 
			
		||||
 | 
			
		||||
  # Take a look at the aax file and see if it is valid. If the source file is aaxc, we give ffprobe additional flags
 | 
			
		||||
  output="$(ffprobe -loglevel warning ${decrypt_param} -i "${media_file}" 2>&1)"
 | 
			
		||||
  output="$("$FFPROBE" -loglevel warning ${decrypt_param} -i "${media_file}" 2>&1)"
 | 
			
		||||
 | 
			
		||||
  # If invalid then say something.
 | 
			
		||||
  if [[ $? != "0" ]] ; then
 | 
			
		||||
@@ -422,7 +435,7 @@ validate_aax() {
 | 
			
		||||
 | 
			
		||||
  # This is a big test only performed when the --validate switch is passed.
 | 
			
		||||
  if [[ "${VALIDATE}" == "1" ]]; then
 | 
			
		||||
    output="$(ffmpeg -hide_banner ${decrypt_param} -i "${media_file}" -vn -f null - 2>&1)"
 | 
			
		||||
    output="$("$FFMPEG" -hide_banner ${decrypt_param} -i "${media_file}" -vn -f null - 2>&1)"
 | 
			
		||||
    if [[ $? != "0" ]] ; then
 | 
			
		||||
      log "ERROR: Invalid File: ${media_file}"
 | 
			
		||||
    else
 | 
			
		||||
@@ -492,7 +505,7 @@ validate_extra_files() {
 | 
			
		||||
save_metadata() {
 | 
			
		||||
  local media_file
 | 
			
		||||
  media_file="$1"
 | 
			
		||||
  ffprobe -i "$media_file" 2> "$metadata_file"
 | 
			
		||||
  "$FFPROBE" -i "$media_file" 2> "$metadata_file"
 | 
			
		||||
  if [[ $(type -P mediainfo) ]]; then
 | 
			
		||||
    echo "Mediainfo data START" >> "$metadata_file"
 | 
			
		||||
    # Mediainfo output is structured like ffprobe, so we append it to the metadata file and then parse it with get_metadata_value()
 | 
			
		||||
@@ -693,7 +706,7 @@ do
 | 
			
		||||
 | 
			
		||||
  # Display the total length of the audiobook in format hh:mm:ss
 | 
			
		||||
  # 10#$var force base-10 interpretation. By default it's base-8, so values like 08 or 09 are not octal numbers
 | 
			
		||||
  total_length="$(ffprobe -v error ${decrypt_param} -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${aax_file}" | cut -d . -f 1)"
 | 
			
		||||
  total_length="$("$FFPROBE" -v error ${decrypt_param} -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${aax_file}" | cut -d . -f 1)"
 | 
			
		||||
  hours="$((total_length/3600))"
 | 
			
		||||
  if [ "$((hours<10))" = "1" ]; then hours="0$hours"; fi
 | 
			
		||||
  minutes="$((total_length/60-60*10#$hours))"
 | 
			
		||||
@@ -712,8 +725,8 @@ do
 | 
			
		||||
  if [ "${continue}" == "0" ]; then
 | 
			
		||||
    # This is the main work horse command.  This is the primary transcoder.
 | 
			
		||||
    # This is the primary transcode. All the heavy lifting is here.
 | 
			
		||||
    debug 'ffmpeg -loglevel error -stats ${decrypt_param} -i "${aax_file}" -vn -codec:a "${codec}" -ab ${bitrate} -map_metadata -1 -metadata title="${title}" -metadata artist="${artist}" -metadata album_artist="${album_artist}" -metadata album="${album}" -metadata date="${album_date}" -metadata track="1/1" -metadata genre="${genre}" -metadata copyright="${copyright}" "${output_file}"'
 | 
			
		||||
    </dev/null ffmpeg -loglevel error \
 | 
			
		||||
    debug '"$FFMPEG" -loglevel error -stats ${decrypt_param} -i "${aax_file}" -vn -codec:a "${codec}" -ab ${bitrate} -map_metadata -1 -metadata title="${title}" -metadata artist="${artist}" -metadata album_artist="${album_artist}" -metadata album="${album}" -metadata date="${album_date}" -metadata track="1/1" -metadata genre="${genre}" -metadata copyright="${copyright}" "${output_file}"'
 | 
			
		||||
    </dev/null "$FFMPEG" -loglevel error \
 | 
			
		||||
      -stats \
 | 
			
		||||
      ${decrypt_param} \
 | 
			
		||||
      -i "${aax_file}" \
 | 
			
		||||
@@ -761,7 +774,7 @@ do
 | 
			
		||||
      if [ "$((${loglevel} > 1))" == "1" ]; then
 | 
			
		||||
        log "Extracting cover into ${cover_file}..."
 | 
			
		||||
      fi
 | 
			
		||||
      </dev/null ffmpeg -loglevel error -activation_bytes "${auth_code}" -i "${aax_file}" -an -codec:v copy "${cover_file}"
 | 
			
		||||
      </dev/null "$FFMPEG" -loglevel error -activation_bytes "${auth_code}" -i "${aax_file}" -an -codec:v copy "${cover_file}"
 | 
			
		||||
    fi
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
@@ -842,7 +855,7 @@ do
 | 
			
		||||
        #ffmpeg version 4+ and on the output for all older versions.
 | 
			
		||||
        split_input=""
 | 
			
		||||
        split_output=""
 | 
			
		||||
        if [ "$(($(ffmpeg -version | $SED -E 's/[^0-9]*([0-9]).*/\1/g;1q') > 3))" = "1" ]; then
 | 
			
		||||
        if [ "$(($("$FFMPEG" -version | $SED -E 's/[^0-9]*([0-9]).*/\1/g;1q') > 3))" = "1" ]; then
 | 
			
		||||
          split_input="-ss ${chapter_start%?} -to ${chapter_end}"
 | 
			
		||||
        else
 | 
			
		||||
          split_output="-ss ${chapter_start%?} -to ${chapter_end}"
 | 
			
		||||
@@ -856,7 +869,7 @@ do
 | 
			
		||||
          if [ "$((${loglevel} > 1))" == "1" ]; then
 | 
			
		||||
            log "Splitting chapter ${chapternum}/${chaptercount} start:${chapter_start%?}(s) end:${chapter_end}(s)"
 | 
			
		||||
          fi
 | 
			
		||||
          </dev/null ffmpeg -loglevel quiet \
 | 
			
		||||
          </dev/null "$FFMPEG" -loglevel quiet \
 | 
			
		||||
            -nostats \
 | 
			
		||||
            ${split_input} \
 | 
			
		||||
            -i "${output_file}" \
 | 
			
		||||
@@ -907,7 +920,7 @@ do
 | 
			
		||||
      if [ "${audibleCli}" == "1" ]; then
 | 
			
		||||
        mv "${tmp_chapter_file}" "${output_directory}/${currentFileNameScheme}.chapters.txt"
 | 
			
		||||
      else
 | 
			
		||||
        ffprobe -i "${aax_file}" -print_format csv -show_chapters 2>/dev/null | awk -F "," '{printf "CHAPTER%d=%02d:%02d:%02.3f\nCHAPTER%dNAME=%s\n", NR, $5/60/60, $5/60%60, $5%60, NR, $8}' > "${output_directory}/${currentFileNameScheme}.chapters.txt"
 | 
			
		||||
        "$FFPROBE" -i "${aax_file}" -print_format csv -show_chapters 2>/dev/null | awk -F "," '{printf "CHAPTER%d=%02d:%02d:%02.3f\nCHAPTER%dNAME=%s\n", NR, $5/60/60, $5/60%60, $5%60, NR, $8}' > "${output_directory}/${currentFileNameScheme}.chapters.txt"
 | 
			
		||||
      fi
 | 
			
		||||
      mp4chaps -i "${output_file}"
 | 
			
		||||
    fi
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user