diff --git a/265 b/265 index 4753d67..94a1c09 100644 --- a/265 +++ b/265 @@ -3,11 +3,6 @@ set -o pipefail IFS=$'\n\t' export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/x86_64-linux-gnu/ -# You'll want to run this kinda like this... -# find /mnt/ -maxdepth 25 -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\|m4v\)" | parallel ./parallel_convert_265 {} -# OR -# parallel 'find {} -type f -name "*.mkv"' ::: /Muninn/TV /Muninn/Movies | parallel --progress ~/convert265/265 {} - for video; do d=$(dirname "$video") filename=$(basename "$video") diff --git a/265_audio_problems b/265_audio_problems index e20c2a7..23ff1bd 100755 --- a/265_audio_problems +++ b/265_audio_problems @@ -2,20 +2,17 @@ set -o pipefail IFS=$'\n\t' -# You'll want to run this kinda like this... -# find /mnt/ -maxdepth 25 -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\|m4v\)" | parallel ./parallel_convert_265 {} -# OR -# parallel 'find {} -type f -name "*.mkv"' ::: /Muninn/TV /Muninn/Movies | parallel --progress ~/convert265/265 {} -# parallel 'find {} -type f -maxdepth 5 -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\|m4v\)"' ::: /Muninn/TV /Muninn/Movies | parallel --jobs 2 --progress ~/convert265/265 {} - for video; do + if [[ ! -f "${video}.json" ]]; then + ffprobe -v quiet -print_format json -show_streams "${video}" > "${video}.json" + fi d=$(dirname "$video") filename=$(basename "$video") - extension="${filename##*.}" filename="${filename%.*}" - video_codec=$(mediainfo --Inform="Video;%Format%" "${video}") - echo -e "${video} // ${video_codec}" - if [[ ! ${video_codec} =~ "HEVC" ]]; then + video_codec=$(jq -r '.streams[0].codec_name' < "${video}.json") + video_height=$(jq -r '.streams[0].height' < "${video}.json") + echo -e "${video} // ${video_codec} // ${video_height}" + if [[ ! ${video_codec} =~ "hevc" || ${video_height} -gt 1080 ]]; then _filename=$(echo "${filename}" | sed -e 's/h264/x265/g' -e 's/x264/x265/g' -e 's/AVC/x265/g' -e 's/XviD/x265/g').mkv nice -n 19 ffmpeg -hide_banner -loglevel info -y -threads 4 -hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/renderD128 -analyzeduration 20000000 -probesize 20000000 \ -i "${video}" -map 0:v -map 0:a -map 0:s? -map 0:d? -map 0:t? -c:s copy \ diff --git a/265_personal b/265_personal index 47a1dab..f0233e8 100755 --- a/265_personal +++ b/265_personal @@ -2,38 +2,34 @@ set -o pipefail IFS=$'\n\t' -# You'll want to run this kinda like this... -# find /mnt/ -maxdepth 25 -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\|m4v\)" | parallel ./parallel_convert_265 {} -# OR -# parallel 'find {} -type f -name "*.mkv"' ::: /Muninn/TV /Muninn/Movies | parallel --progress ~/convert265/265 {} -# parallel 'find {} -type f -maxdepth 5 -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\|m4v\)"' ::: /Muninn/TV /Muninn/Movies | parallel --jobs 2 --progress ~/convert265/265 {} - pro_dir="/opt/amdgpu-pro/etc/vulkan/icd.d" export LD_LIBRARY_PATH="/opt/amdgpu/libdrm/lib64:/opt/amdgpu/libdrm/lib32:$LD_LIBRARY_PATH" export VK_ICD_FILENAMES="${pro_dir}/amd_icd32.json:${pro_dir}/amd_icd64.json" - for video; do - d=$(dirname "$video") - filename=$(basename "$video") - extension="${filename##*.}" - filename="${filename%.*}" - video_codec=$(nice -n 19 mediainfo --Inform="Video;%Format%" "${video}") - echo -e "${video} // ${video_codec}" - if [[ ! ${video_codec} =~ "HEVC" ]]; then - _filename=$(echo "${filename}" | sed -e 's/h264/x265/g' -e 's/x264/x265/g' -e 's/AVC/x265/g' -e 's/XviD/x265/g')_H265.mkv - nice -n 19 ffmpeg -hide_banner -loglevel info -y -threads 4 -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device /dev/dri/renderD128 -analyzeduration 20000000 -probesize 20000000 \ - -i "${video}" -map 0:v -map 0:a -map 0:s? -map 0:d? -map 0:t? -c:s copy \ - -vf 'scale_vaapi=format=p010,scale_vaapi=w=1920:-2' \ - -c:v hevc_vaapi -profile:v main10 \ - -c:a copy \ - -max_muxing_queue_size 1024 -movflags +faststart -movflags use_metadata_tags \ - "/dev/shm/$_filename" || exit 1 - mv -vu "/dev/shm/${_filename}" "${d}/${_filename}" || rm -f "/dev/shm/${_filename}" - if [[ -f "${d}/${_filename}" ]]; then - cmp "${d}/${_filename}" "${video}" || rm -vf "${video}" - fi - fi + if [[ ! -f "${video}.json" ]]; then + ffprobe -v quiet -print_format json -show_streams "${video}" > "${video}.json" + fi + d=$(dirname "$video") + filename=$(basename "$video") + filename="${filename%.*}" + video_codec=$(jq -r '.streams[0].codec_name' < "${video}.json") + video_height=$(jq -r '.streams[0].height' < "${video}.json") + echo -e "${video} // ${video_codec} // ${video_height}" + if [[ ! ${video_codec} =~ "hevc" || ${video_height} -gt 1080 ]]; then + _filename=$(echo "${filename}" | sed -e 's/h264/x265/g' -e 's/x264/x265/g' -e 's/AVC/x265/g' -e 's/XviD/x265/g')_H265.mkv + nice -n 19 ffmpeg -hide_banner -loglevel info -y -threads 4 -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device /dev/dri/renderD128 -analyzeduration 20000000 -probesize 20000000 \ + -i "${video}" -map 0:v -map 0:a -map 0:s? -map 0:d? -map 0:t? -c:s copy \ + -vf 'scale_vaapi=format=p010,scale_vaapi=w=1920:-2' \ + -c:v hevc_vaapi -profile:v main10 \ + -c:a copy \ + -max_muxing_queue_size 1024 -movflags +faststart -movflags use_metadata_tags \ + "/dev/shm/$_filename" || exit 1 + mv -vu "/dev/shm/${_filename}" "${d}/${_filename}" || rm -f "/dev/shm/${_filename}" + if [[ -f "${d}/${_filename}" ]]; then + cmp "${d}/${_filename}" "${video}" || rm -vf "${video}" + fi + fi done #-vf 'format=p010,hwupload,scale=1920x1080:flags=lanczos' -c:v hevc_vaapi -profile:v main10 \ #-vf 'scale_vaapi=format=p010,scale_vaapi=w=1920' \ diff --git a/265_poster_problems b/265_poster_problems index 09fdd1e..de5bab8 100755 --- a/265_poster_problems +++ b/265_poster_problems @@ -2,28 +2,26 @@ set -o pipefail IFS=$'\n\t' -# You'll want to run this kinda like this... -# find /mnt/ -maxdepth 25 -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\|m4v\)" | parallel ./parallel_convert_265 {} -# OR -# parallel 'find {} -type f -name "*.mkv"' ::: /Muninn/TV /Muninn/Movies | parallel --progress ~/convert265/265 {} -# parallel 'find {} -type f -maxdepth 5 -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\|m4v\)"' ::: /Muninn/TV /Muninn/Movies | parallel --jobs 2 --progress ~/convert265/265 {} - for video; do + if [[ ! -f "${video}.json" ]]; then + ffprobe -v quiet -print_format json -show_streams "${video}" > "${video}.json" + fi d=$(dirname "$video") filename=$(basename "$video") - extension="${filename##*.}" filename="${filename%.*}" - video_codec=$(nice -n 19 mediainfo --Inform="Video;%Format%" "${video}") - echo -e "${video} // ${video_codec}" - if [[ ! ${video_codec} =~ "HEVC" ]]; then + video_codec=$(jq -r '.streams[0].codec_name' < "${video}.json") + video_height=$(jq -r '.streams[0].height' < "${video}.json") + echo -e "${video} // ${video_codec} // ${video_height}" + if [[ ! ${video_codec} =~ "hevc" || ${video_height} -gt 1080 ]]; then _filename=$(echo "${filename}" | sed -e 's/h264/x265/g' -e 's/x264/x265/g' -e 's/AVC/x265/g' -e 's/XviD/x265/g').mkv nice -n 19 ffmpeg -hide_banner -loglevel info -y -threads 4 -vaapi_device /dev/dri/renderD128 -analyzeduration 20000000 -probesize 20000000 \ - -i "${video}" -map 0:v:0 -map 0:a -c:a copy -vf 'format=nv12,hwupload' \ - -c:v hevc_vaapi \ + -i "${video}" -map 0:v:0 -map 0:s? -map 0:d? -map 0:t? -c:s copy -c:a copy -vf 'format=nv12,hwupload' \ + -c:v hevc_vaapi -profile:v main10 \ -max_muxing_queue_size 1024 -movflags +faststart -movflags use_metadata_tags "/dev/shm/$_filename" || exit 1 mv -vu "/dev/shm/${_filename}" "${d}/${_filename}" || rm -f "/dev/shm/${_filename}" if [[ -f "${d}/${_filename}" ]]; then - cmp "${d}/${_filename}" "${video}" || rm -vf "${video}" + cmp "${d}/${_filename}" "${video}" || rm -vf "${video}" "${video}.json" + ffprobe -v quiet -print_format json -show_streams "${d}/${_filename}" > "${d}/${_filename}.json" fi fi done diff --git a/265_problems b/265_problems index dde194b..3d3cc69 100755 --- a/265_problems +++ b/265_problems @@ -2,22 +2,18 @@ set -o pipefail IFS=$'\n\t' -# You'll want to run this kinda like this... -# find /mnt/ -maxdepth 25 -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\|m4v\)" | parallel ./parallel_convert_265 {} -# OR -# parallel 'find {} -type f -name "*.mkv"' ::: /Muninn/TV /Muninn/Movies | parallel --progress ~/convert265/265 {} -# parallel 'find {} -type f -maxdepth 5 -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\|m4v\)"' ::: /Muninn/TV /Muninn/Movies | parallel --jobs 2 --progress ~/convert265/265 {} - for video; do + if [[ ! -f "${video}.json" ]]; then + ffprobe -v quiet -print_format json -show_streams "${video}" > "${video}.json" + fi d=$(dirname "$video") filename=$(basename "$video") - extension="${filename##*.}" filename="${filename%.*}" - video_codec=$(nice -n 19 mediainfo --Inform="Video;%Format%" "${video}") - echo -e "${video} // ${video_codec}" - if [[ ! ${video_codec} =~ "HEVC" ]]; then + video_codec=$(jq -r '.streams[0].codec_name' < "${video}.json") + video_height=$(jq -r '.streams[0].height' < "${video}.json") + echo -e "${video} // ${video_codec} // ${video_height}" + if [[ ! ${video_codec} =~ "hevc" || ${video_height} -gt 1080 ]]; then _filename=$(echo "${filename}" | sed -e 's/h264/x265/g' -e 's/x264/x265/g' -e 's/XviD/x265/g').mkv - #nice -n 19 ffmpeg -hide_banner -loglevel info -y -threads 4 -hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/renderD128 -analyzeduration 20000000 -probesize 20000000 \ nice -n 19 ffmpeg -hide_banner -loglevel info -y -threads 4 -vaapi_device /dev/dri/renderD128 -analyzeduration 20000000 -probesize 20000000 \ -i "${video}" -map 0:v -map 0:a -map 0:s? -map 0:d? -map 0:t? -c:s copy -c:a copy -vf 'format=nv12,hwupload' \ -c:v hevc_vaapi \ diff --git a/265_system b/265_system index 71beb0b..35a8b1d 100755 --- a/265_system +++ b/265_system @@ -2,12 +2,6 @@ set -o pipefail IFS=$'\n\t' -# You'll want to run this kinda like this... -# find /mnt/ -maxdepth 25 -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\|m4v\)" | parallel ./parallel_convert_265 {} -# OR -# parallel 'find {} -type f -name "*.mkv"' ::: /Muninn/TV /Muninn/Movies | parallel --progress ~/convert265/265 {} -# parallel 'find {} -type f -maxdepth 5 -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\|m4v\)"' ::: /Muninn/TV /Muninn/Movies | parallel --jobs 2 --progress ~/convert265/265 {} - pro_dir="/opt/amdgpu-pro/etc/vulkan/icd.d" export LD_LIBRARY_PATH="/opt/amdgpu/libdrm/lib64:/opt/amdgpu/libdrm/lib32:$LD_LIBRARY_PATH" export VK_ICD_FILENAMES="${pro_dir}/amd_icd32.json:${pro_dir}/amd_icd64.json" diff --git a/README.md b/README.md index b89f5a6..64ff23c 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,25 @@ Script to convert media to x265 -Edit the path for the find command in the normal one. +These are mostly a hack job since I'm trying to save space for my media by converting things into HEVC. -To make it even faster you'll want to run this kinda like this... +I really need to make a unified script for the edge cases, but I haven't. Feel free to send a PR if you to something. I +also want to add AMF support, but have not gotten that to work right yet. -parallel ./parallel_convert_265 . ::: $(find /mnt/ -maxdepth 25 -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\|m4v\)") +The nvidia example is 265 the other scripts use vaapi (intel/amd) to do the HW HEVC encoding. I haven't done much with +the NVIDIA in a few years, so it's kinda stale. +265_system is the one that you should use if you're going to use it. + +I use it with parallel to do multiple files at once like this: + +```shell +parallel 'find {} -type f -maxdepth 5 -regex ".*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|avi\|m4v\|ts\m2ts\)"' ::: /mnt/Movies /mnt/TV | parallel --jobs 4 --progress ~/convert265/265_system {} +``` + +Change the --jobs flag to the number of files your system can handle at once. I think 4 is a sane number for older/lower +end NAS devices. + +YMMV // Caveat Emptor // And have an average day :| + +-H \ No newline at end of file diff --git a/season_posters b/season_posters deleted file mode 100755 index f476dfe..0000000 --- a/season_posters +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -set -o pipefail -IFS=$'\n\t' - -# you want to do something like this -# for x in $(echo "*"); do cd /Muninn/TV/"${x}"; ~/convert265/season_posters; done -cp -aln poster.jpg Season\ */ -cp -al season01-poster.jpg Season\ 1/poster.jpg || cp -al poster.jpg Season\ 1/poster.jpg -cp -al season02-poster.jpg Season\ 2/poster.jpg || cp -al poster.jpg Season\ 2/poster.jpg -cp -al season03-poster.jpg Season\ 3/poster.jpg || cp -al poster.jpg Season\ 3/poster.jpg -cp -al season04-poster.jpg Season\ 4/poster.jpg || cp -al poster.jpg Season\ 4/poster.jpg -cp -al season05-poster.jpg Season\ 5/poster.jpg || cp -al poster.jpg Season\ 5/poster.jpg -cp -al season06-poster.jpg Season\ 6/poster.jpg || cp -al poster.jpg Season\ 6/poster.jpg -cp -al season07-poster.jpg Season\ 7/poster.jpg || cp -al poster.jpg Season\ 7/poster.jpg -cp -al season08-poster.jpg Season\ 8/poster.jpg || cp -al poster.jpg Season\ 8/poster.jpg -cp -al season09-poster.jpg Season\ 9/poster.jpg || cp -al poster.jpg Season\ 9/poster.jpg -cp -al season10-poster.jpg Season\ 10/poster.jpg || cp -al poster.jpg Season\ 10/poster.jpg -cp -al season10-poster.jpg Season\ 11/poster.jpg || cp -al poster.jpg Season\ 11/poster.jpg -cp -al season10-poster.jpg Season\ 12/poster.jpg || cp -al poster.jpg Season\ 12/poster.jpg -cp -al season10-poster.jpg Season\ 13/poster.jpg || cp -al poster.jpg Season\ 13/poster.jpg -cp -al season10-poster.jpg Season\ 14/poster.jpg || cp -al poster.jpg Season\ 14/poster.jpg -cp -al season10-poster.jpg Season\ 15/poster.jpg || cp -al poster.jpg Season\ 15/poster.jpg diff --git a/tools/ffmpeg b/tools/ffmpeg deleted file mode 100755 index 1c144a9..0000000 Binary files a/tools/ffmpeg and /dev/null differ