From 02aa31efc0a295e74cdb322dd5657fbf85eefaf7 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 11 Jun 2018 18:38:53 +0200 Subject: try both enumeration modes --- odin/strm/download_youtube | 184 +++++++++++++++++++++++++-------------------- 1 file changed, 102 insertions(+), 82 deletions(-) (limited to 'odin/strm/download_youtube') diff --git a/odin/strm/download_youtube b/odin/strm/download_youtube index 05a8374d..29d54872 100644 --- a/odin/strm/download_youtube +++ b/odin/strm/download_youtube @@ -215,90 +215,110 @@ printf ">>> %s <<<\n %s\n" "${msgId}" "${message}" ext=${extensions[1]} filename=${filename%.*}.${ext} - typeset -a args - args=(-y) - typeset -a prePass - prePass=() - typeset -a cargs - cargs=() - typeset -a p1args - p1args=() - typeset -a p2args - p2args=() - for formatKey (${(k)fileInfo}); do - [[ ${formatKey} =~ "stream.([0-9]+).codec_type" ]] || continue - local i=$match[1] - local cType=${fileInfo[${formatKey}]} - local cName=${fileInfo[stream.${i}.codec_name]} - - printf "Stream %d: %s (%s)\n" ${i} ${cName} ${cType} - - if [[ ${cType} == "video" ]]; then - if [[ ${ext} == "mkv" ]]; then - case ${cName} in - h264|vp9|png) - cargs+=(-c:${i} copy) - ;; - *) - # p1args=(-pass 1 -threads 8 -speed 4 -tile-columns 6 -frame-parallel 1) - # prePass+=(-c:${i} libvpx-vp9 -b:${i} 0 -crf:${i} 33) - # p2args+=(-pass 2 -threads 8 -speed 2 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25) - # cargs+=(-c:${i} libvpx-vp9 -b:${i} 0 -crf:${i} 33) - cargs+=(-c:${i} libvpx-vp9 -b:${i} 2M -threads 8 -tile-columns 6 -frame-parallel 1) - ;; - esac - elif [[ ${ext} == "mp4" ]]; then - case ${cName} in - mpeg|h264) - cargs+=(-c:${i} copy) - ;; - *) - p2args+=(-strict -2) - cargs+=(-c:${i} libx264) - ;; - esac - fi - elif [[ ${cType} == "audio" ]]; then - if [[ ${ext} == "mkv" ]]; then - if [[ ( ${cName} == opus || ${cName} == flac || ${cName} == vorbis ) && "${bare_amp}" -eq 0 ]]; then - cargs+=(-c:${i} copy) - else - p2args+=(-vbr on -compression_level 10) - cargs+=(-c:${i} libopus -b:${i} 256K) - fi - elif [[ ${ext} == "mp4" ]]; then - if [[ ${cName} == aac && "${bare_amp}" -eq 0 ]]; then - cargs+=(-c:${i} copy) - else - cargs+=(-c:${i} aac) - fi - fi - fi - done - - [[ "${bare_amp}" -ne 0 ]] && p2args+=(-af "${amp}") - - if [[ $#prePass -gt 0 ]]; then - args+=(-v info -i ${tempfile}) - - oldPwd=${PWD} - cd $(mktemp -d --tmpdir "transcode.${0:t}.$$.XXXXXX") - cleanup rm -rfv -- ${PWD} - - p1args+=(-an -f matroska) - print -- ${prePass} ${p1args} - ffmpeg ${args} ${prePass} ${p1args} -- /dev/null - print -- ${cargs} ${p2args} - ffmpeg ${args} ${cargs} ${p2args} -- "${filename}" - - cd ${oldPwd} - else - args+=(-v warning -i pipe:0) + typeset -a transModes + transModes=(use-index enumerate) + + for transMode (${transModes}); do + typeset -a args + args=(-y) + typeset -a prePass + prePass=() + typeset -a cargs + cargs=() + typeset -a p1args + p1args=() + typeset -a p2args + p2args=() + + local j=0 + + for formatKey (${(k)fileInfo}); do + [[ ${formatKey} =~ "stream.([0-9]+).codec_type" ]] || continue + local i=$match[1] + local cType=${fileInfo[${formatKey}]} + local cName=${fileInfo[stream.${i}.codec_name]} + + if [[ ${transMode} == "enumerate" ]]; then + i=${j} + j=$((j + 1)) + fi + + printf "Stream %d: %s (%s)\n" ${i} ${cName} ${cType} + + if [[ ${cType} == "video" ]]; then + if [[ ${ext} == "mkv" ]]; then + case ${cName} in + h264|vp9|png) + cargs+=(-c:${i} copy) + ;; + *) + # p1args=(-pass 1 -threads 8 -speed 4 -tile-columns 6 -frame-parallel 1) + # prePass+=(-c:${i} libvpx-vp9 -b:${i} 0 -crf:${i} 33) + # p2args+=(-pass 2 -threads 8 -speed 2 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25) + # cargs+=(-c:${i} libvpx-vp9 -b:${i} 0 -crf:${i} 33) + cargs+=(-c:${i} libvpx-vp9 -b:${i} 2M -threads 8 -tile-columns 6 -frame-parallel 1) + ;; + esac + elif [[ ${ext} == "mp4" ]]; then + case ${cName} in + mpeg|h264) + cargs+=(-c:${i} copy) + ;; + *) + p2args+=(-strict -2) + cargs+=(-c:${i} libx264) + ;; + esac + fi + elif [[ ${cType} == "audio" ]]; then + if [[ ${ext} == "mkv" ]]; then + if [[ ( ${cName} == opus || ${cName} == flac || ${cName} == vorbis ) && "${bare_amp}" -eq 0 ]]; then + cargs+=(-c:${i} copy) + else + p2args+=(-vbr on -compression_level 10) + cargs+=(-c:${i} libopus -b:${i} 256K) + fi + elif [[ ${ext} == "mp4" ]]; then + if [[ ${cName} == aac && "${bare_amp}" -eq 0 ]]; then + cargs+=(-c:${i} copy) + else + cargs+=(-c:${i} aac) + fi + fi + fi + done + + [[ "${bare_amp}" -ne 0 ]] && p2args+=(-af "${amp}") + + local success=false + + if [[ $#prePass -gt 0 ]]; then + args+=(-v info -i ${tempfile}) + + oldPwd=${PWD} + cd $(mktemp -d --tmpdir "transcode.${0:t}.$$.XXXXXX") + cleanup rm -rfv -- ${PWD} + + p1args+=(-an -f matroska) + print -- ${prePass} ${p1args} + ffmpeg ${args} ${prePass} ${p1args} -- /dev/null + + print -- ${cargs} ${p2args} + ffmpeg ${args} ${cargs} ${p2args} -- "${filename}" && success=true + + cd ${oldPwd} + else + args+=(-v warning -i pipe:0) + + print -- ${cargs} ${p2args} + pv -N "$(trimName "trans:" ${title})" ${tempfile} | ffmpeg ${args} ${cargs} ${p2args} -- "${filename}" && success=true + fi - print -- ${cargs} ${p2args} - pv -N "$(trimName "trans:" ${title})" ${tempfile} | ffmpeg ${args} ${cargs} ${p2args} -- "${filename}" - fi + if ${success}; then + break + fi + done fi fi -- cgit v1.2.3