diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2018-06-11 18:38:53 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2018-06-11 18:38:53 +0200 |
commit | 02aa31efc0a295e74cdb322dd5657fbf85eefaf7 (patch) | |
tree | b428fee6ef94aa66fd7d23d7fc36654c832302c0 /odin/strm/download_youtube | |
parent | dc637663c59dd0f57d0c13d091d5e33cf0b2e490 (diff) | |
download | nixos-02aa31efc0a295e74cdb322dd5657fbf85eefaf7.tar nixos-02aa31efc0a295e74cdb322dd5657fbf85eefaf7.tar.gz nixos-02aa31efc0a295e74cdb322dd5657fbf85eefaf7.tar.bz2 nixos-02aa31efc0a295e74cdb322dd5657fbf85eefaf7.tar.xz nixos-02aa31efc0a295e74cdb322dd5657fbf85eefaf7.zip |
try both enumeration modes
Diffstat (limited to 'odin/strm/download_youtube')
-rw-r--r-- | odin/strm/download_youtube | 184 |
1 files changed, 102 insertions, 82 deletions
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}" | |||
215 | 215 | ||
216 | ext=${extensions[1]} | 216 | ext=${extensions[1]} |
217 | filename=${filename%.*}.${ext} | 217 | filename=${filename%.*}.${ext} |
218 | typeset -a args | ||
219 | args=(-y) | ||
220 | typeset -a prePass | ||
221 | prePass=() | ||
222 | typeset -a cargs | ||
223 | cargs=() | ||
224 | typeset -a p1args | ||
225 | p1args=() | ||
226 | typeset -a p2args | ||
227 | p2args=() | ||
228 | for formatKey (${(k)fileInfo}); do | ||
229 | [[ ${formatKey} =~ "stream.([0-9]+).codec_type" ]] || continue | ||
230 | local i=$match[1] | ||
231 | local cType=${fileInfo[${formatKey}]} | ||
232 | local cName=${fileInfo[stream.${i}.codec_name]} | ||
233 | |||
234 | printf "Stream %d: %s (%s)\n" ${i} ${cName} ${cType} | ||
235 | |||
236 | if [[ ${cType} == "video" ]]; then | ||
237 | if [[ ${ext} == "mkv" ]]; then | ||
238 | case ${cName} in | ||
239 | h264|vp9|png) | ||
240 | cargs+=(-c:${i} copy) | ||
241 | ;; | ||
242 | *) | ||
243 | # p1args=(-pass 1 -threads 8 -speed 4 -tile-columns 6 -frame-parallel 1) | ||
244 | # prePass+=(-c:${i} libvpx-vp9 -b:${i} 0 -crf:${i} 33) | ||
245 | # p2args+=(-pass 2 -threads 8 -speed 2 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25) | ||
246 | # cargs+=(-c:${i} libvpx-vp9 -b:${i} 0 -crf:${i} 33) | ||
247 | cargs+=(-c:${i} libvpx-vp9 -b:${i} 2M -threads 8 -tile-columns 6 -frame-parallel 1) | ||
248 | ;; | ||
249 | esac | ||
250 | elif [[ ${ext} == "mp4" ]]; then | ||
251 | case ${cName} in | ||
252 | mpeg|h264) | ||
253 | cargs+=(-c:${i} copy) | ||
254 | ;; | ||
255 | *) | ||
256 | p2args+=(-strict -2) | ||
257 | cargs+=(-c:${i} libx264) | ||
258 | ;; | ||
259 | esac | ||
260 | fi | ||
261 | elif [[ ${cType} == "audio" ]]; then | ||
262 | if [[ ${ext} == "mkv" ]]; then | ||
263 | if [[ ( ${cName} == opus || ${cName} == flac || ${cName} == vorbis ) && "${bare_amp}" -eq 0 ]]; then | ||
264 | cargs+=(-c:${i} copy) | ||
265 | else | ||
266 | p2args+=(-vbr on -compression_level 10) | ||
267 | cargs+=(-c:${i} libopus -b:${i} 256K) | ||
268 | fi | ||
269 | elif [[ ${ext} == "mp4" ]]; then | ||
270 | if [[ ${cName} == aac && "${bare_amp}" -eq 0 ]]; then | ||
271 | cargs+=(-c:${i} copy) | ||
272 | else | ||
273 | cargs+=(-c:${i} aac) | ||
274 | fi | ||
275 | fi | ||
276 | fi | ||
277 | done | ||
278 | |||
279 | [[ "${bare_amp}" -ne 0 ]] && p2args+=(-af "${amp}") | ||
280 | |||
281 | if [[ $#prePass -gt 0 ]]; then | ||
282 | args+=(-v info -i ${tempfile}) | ||
283 | |||
284 | oldPwd=${PWD} | ||
285 | cd $(mktemp -d --tmpdir "transcode.${0:t}.$$.XXXXXX") | ||
286 | cleanup rm -rfv -- ${PWD} | ||
287 | |||
288 | p1args+=(-an -f matroska) | ||
289 | print -- ${prePass} ${p1args} | ||
290 | ffmpeg ${args} ${prePass} ${p1args} -- /dev/null | ||
291 | 218 | ||
292 | print -- ${cargs} ${p2args} | 219 | typeset -a transModes |
293 | ffmpeg ${args} ${cargs} ${p2args} -- "${filename}" | 220 | transModes=(use-index enumerate) |
294 | 221 | ||
295 | cd ${oldPwd} | 222 | for transMode (${transModes}); do |
296 | else | 223 | typeset -a args |
297 | args+=(-v warning -i pipe:0) | 224 | args=(-y) |
225 | typeset -a prePass | ||
226 | prePass=() | ||
227 | typeset -a cargs | ||
228 | cargs=() | ||
229 | typeset -a p1args | ||
230 | p1args=() | ||
231 | typeset -a p2args | ||
232 | p2args=() | ||
233 | |||
234 | local j=0 | ||
235 | |||
236 | for formatKey (${(k)fileInfo}); do | ||
237 | [[ ${formatKey} =~ "stream.([0-9]+).codec_type" ]] || continue | ||
238 | local i=$match[1] | ||
239 | local cType=${fileInfo[${formatKey}]} | ||
240 | local cName=${fileInfo[stream.${i}.codec_name]} | ||
241 | |||
242 | if [[ ${transMode} == "enumerate" ]]; then | ||
243 | i=${j} | ||
244 | j=$((j + 1)) | ||
245 | fi | ||
246 | |||
247 | printf "Stream %d: %s (%s)\n" ${i} ${cName} ${cType} | ||
248 | |||
249 | if [[ ${cType} == "video" ]]; then | ||
250 | if [[ ${ext} == "mkv" ]]; then | ||
251 | case ${cName} in | ||
252 | h264|vp9|png) | ||
253 | cargs+=(-c:${i} copy) | ||
254 | ;; | ||
255 | *) | ||
256 | # p1args=(-pass 1 -threads 8 -speed 4 -tile-columns 6 -frame-parallel 1) | ||
257 | # prePass+=(-c:${i} libvpx-vp9 -b:${i} 0 -crf:${i} 33) | ||
258 | # p2args+=(-pass 2 -threads 8 -speed 2 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25) | ||
259 | # cargs+=(-c:${i} libvpx-vp9 -b:${i} 0 -crf:${i} 33) | ||
260 | cargs+=(-c:${i} libvpx-vp9 -b:${i} 2M -threads 8 -tile-columns 6 -frame-parallel 1) | ||
261 | ;; | ||
262 | esac | ||
263 | elif [[ ${ext} == "mp4" ]]; then | ||
264 | case ${cName} in | ||
265 | mpeg|h264) | ||
266 | cargs+=(-c:${i} copy) | ||
267 | ;; | ||
268 | *) | ||
269 | p2args+=(-strict -2) | ||
270 | cargs+=(-c:${i} libx264) | ||
271 | ;; | ||
272 | esac | ||
273 | fi | ||
274 | elif [[ ${cType} == "audio" ]]; then | ||
275 | if [[ ${ext} == "mkv" ]]; then | ||
276 | if [[ ( ${cName} == opus || ${cName} == flac || ${cName} == vorbis ) && "${bare_amp}" -eq 0 ]]; then | ||
277 | cargs+=(-c:${i} copy) | ||
278 | else | ||
279 | p2args+=(-vbr on -compression_level 10) | ||
280 | cargs+=(-c:${i} libopus -b:${i} 256K) | ||
281 | fi | ||
282 | elif [[ ${ext} == "mp4" ]]; then | ||
283 | if [[ ${cName} == aac && "${bare_amp}" -eq 0 ]]; then | ||
284 | cargs+=(-c:${i} copy) | ||
285 | else | ||
286 | cargs+=(-c:${i} aac) | ||
287 | fi | ||
288 | fi | ||
289 | fi | ||
290 | done | ||
291 | |||
292 | [[ "${bare_amp}" -ne 0 ]] && p2args+=(-af "${amp}") | ||
293 | |||
294 | local success=false | ||
295 | |||
296 | if [[ $#prePass -gt 0 ]]; then | ||
297 | args+=(-v info -i ${tempfile}) | ||
298 | |||
299 | oldPwd=${PWD} | ||
300 | cd $(mktemp -d --tmpdir "transcode.${0:t}.$$.XXXXXX") | ||
301 | cleanup rm -rfv -- ${PWD} | ||
302 | |||
303 | p1args+=(-an -f matroska) | ||
304 | print -- ${prePass} ${p1args} | ||
305 | ffmpeg ${args} ${prePass} ${p1args} -- /dev/null | ||
306 | |||
307 | print -- ${cargs} ${p2args} | ||
308 | ffmpeg ${args} ${cargs} ${p2args} -- "${filename}" && success=true | ||
309 | |||
310 | cd ${oldPwd} | ||
311 | else | ||
312 | args+=(-v warning -i pipe:0) | ||
313 | |||
314 | print -- ${cargs} ${p2args} | ||
315 | pv -N "$(trimName "trans:" ${title})" ${tempfile} | ffmpeg ${args} ${cargs} ${p2args} -- "${filename}" && success=true | ||
316 | fi | ||
298 | 317 | ||
299 | print -- ${cargs} ${p2args} | 318 | if ${success}; then |
300 | pv -N "$(trimName "trans:" ${title})" ${tempfile} | ffmpeg ${args} ${cargs} ${p2args} -- "${filename}" | 319 | break |
301 | fi | 320 | fi |
321 | done | ||
302 | fi | 322 | fi |
303 | fi | 323 | fi |
304 | 324 | ||