∟⊔⊤∦∣≶

  • 3 Posts
  • 61 Comments
Joined 1 year ago
cake
Cake day: June 29th, 2023

help-circle

















  • I wrote a bash script for this, but I’m not sure of the correct settings so I haven’t used it to re-encode my whole library yet.

    Here’s my script in case anyone has any tips:

    spoiler

    #!/bin/sh

    shopt -s globstar

    for FILE in */

    {

    if [[ -d $FILE ]]; then
    
    	continue
    
    fi
    
    match="*-re.mp4"
    if [[ $FILE == $match ]]; then
    	echo already encoded, skipping $FILE
    	continue
    fi
    match="*-ex.mp4"
    if [[ $FILE == $match ]]; then
    	echo already excluded, skipping $FILE
    	continue
    fi
    
    if [[ $(du "${FILE}" | awk '{print $1}') -lt 10000 ]]; then		
    	#echo $(date),$(pwd)/,$FILE,toosmall >> errors.csv
    	echo $(date),$(pwd)/,$FILE, 0,0,0,0, original too small >> encoding.csv
    	continue
    fi
    if [[ $(mediainfo "${FILE}" | grep -c -e'Audio #') -gt 1 ]]; then
    	#echo $(date),$(pwd)/,$FILE,skip-audio >> errors.csv
    	echo $(date),$(pwd)/,$FILE, 0,0,0,0, multiple audio tracks >> encoding.csv
    	continue
    fi
    if [[ $(mediainfo "${FILE}" | grep -c -e'Text #') -gt 1 ]]; then
    	#echo $(date),$(pwd)/,$FILE,skip-subs >> errors.csv
    	echo $(date),$(pwd)/,$FILE, 0,0,0,0, contains subtitles >> encoding.csv
    	continue
    fi
    
    
    FULLM=${FILE%.*}
    REN="$FULLM-re.mp4"
    echo writing $REN
    
    #ffmpeg -y -i "${FILE}" -vcodec libx264 -crf 23 "${REN}" 
    #ffmpeg -y -i "${FILE}" -vcodec h264_nvenc -crf 23 "${REN}" 
    ffmpeg -y -i "${FILE}" -vcodec libx265 -crf 23 "${REN}" 
    
    ORIGSIZE=$(du "${FILE}" | awk '{print $1}')
    NEWSIZE=$(du "${REN}" | awk '{print $1}')
    ORIGBITRATE=$(mediainfo "${FILE}" | grep Overall | sed 's/[^0-9]*//g')
    NEWBITRATE=$(mediainfo "${REN}" | grep Overall | sed 's/[^0-9]*//g')
    
    echo $FILE vs $REN
    echo $ORIGBITRATE vs $NEWBITRATE
    
    #if [[ $NEWBITRATE -gt $ORIGBITRATE ]]; then
    	#echo new bitrate is too big, renaming $FILE to $FULLM-ex.mp4
    	#echo $(date),$(pwd)/,$FILE, $ORIGBITRATE, $NEWBITRATE, $ORIGSIZE, $NEWSIZE, bitrate increased >> encoding.csv
    	#mv "${FILE}" "${FULLM}"-ex.mp4
    	#rm -f "${REN}"
    	#continue
    #fi
    
    if [[ $ORIGSIZE -lt $NEWSIZE ]]; then
    	#echo $(date),$(pwd)/,$FILE,sizeToSmall: $ORIGSIZE vs $NEWSIZE >> errors.csv
    	echo $(date),$(pwd)/,$FILE, $ORIGBITRATE, $NEWBITRATE, $ORIGSIZE, $NEWSIZE, filesize increased >> encoding.csv
    	echo deleting "${REN}"
    	rm -f "${REN}"
    	mv "${FILE}" "${FULLM}"-ex.mp4
    else
    	echo $(date),$(pwd)/,$FILE, $ORIGBITRATE, $NEWBITRATE, $ORIGSIZE, $NEWSIZE, ENCODED >> encoding.csv
    	rm -f "${FILE}"
    fi
    

    }