| ||
Strange è una funzione che ho scritto ormai parecchi anni fa per aiutarmi nel filtraggio tramite CL di YATTA.
Nel tempo si è rivelata una delle funzioncine sceme più utili e che mi è capitato più spesso di andare a usare per un motivo o per l'altro, forse più per abitudine. Recentemente mi sono reso conto di un bug di strange in cui finora non ero incorso per come usavo strange in YATTA, ma che può accadere in condizioni normali in base all'uso. Per la precisione, non era gestita la situazione in cui il clip di edit fosse di durata diversa rispetto al clip base. Questo mi torna sovente comodo quando devo apportare modifiche shiftando frame o pezzi di video, quindi non volevo gestire l'eccezione dando un errore, per cui ho corretto facendo sì che, se il video di edit è più lungo, questo viene trimmato alla durata del clip base, se invece è più corto, viene allungato ripetendo il frame finale del clip di edit. Vi lascio quindi qui la versione aggiornata: SPOILER (clicca per visualizzare) CODICE #strange v1.5 by mirkosp #Yet Another function similar to ApplyRange in purpose that works somewhat differently. #Start and end work exactly like first_frame and last_frame work with trim(), for the #sake of consistency, which means that you can use end as if it was -num_frames too. #ofps parameter tells whether to keep the original fps (true) or not (false). #For reference: http://avisynth.org/mediawiki/Trim function strange (clip c, int "start", int "end", clip "edit", bool "ofps", bool "repeat") { #This function only makes sense with filters that return clips to begin with, so no #point in bothering with strings. It's both easier and better. start = default(start,0) end = default(end,0) edit = default(edit,blankclip(c,length=c.framecount()))#everybody loves blankclip amount = c.framecount() ofps = default(ofps,false) repeat = default(repeat,true) amountedit = edit.framecount() edit = amountedit >= amount ? edit.trim(0,amount-1) : repeat ? (edit+blankclip(edit,amount-amountedit)).freezeframe(amountedit,amount,amountedit-1) : edit+blankclip(edit,amount-amountedit) #Brainfarts check ahead. start = (start < 0) ? 0 : start end = (-end > amount-start) ? 0 : end start = (start > amount-1) ? amount-1 : start end = (end > amount-1) ? 0 : end #Match framerate in case user's custom filtering would change it c = !ofps ? c.assumefps(edit) : c edit = ofps ? edit.assumefps(c) : edit #I'm not a good programmer, so I'm not sure if this is slower than it could be. (start == 0) ? ((end == 0) || (end == amount-1)) ? edit :\ (end < 0) ? edit.trim(0,end)+c.trim(start-end,0) :\ edit.trim(0,end)+c.trim(end+1,0) :\ (start == 1) ? ((end == 0) || (end == amount-1)) ? c.trim(0,-1)+edit.trim(start,0) :\ (end < 0) ? c.trim(0,-1)+edit.trim(start,end)+c.trim(start-end,0) :\ c.trim(0,-1)+edit.trim(start,end)+c.trim(end+1,0) :\ ((end == 0) || (end == amount-1)) ? c.trim(0,start-1)+edit.trim(start,0) :\ (end < 0) ? c.trim(0,start-1)+edit.trim(start,end)+c.trim(start-end,0) :\ c.trim(0,start-1)+edit.trim(start,end)+c.trim(end+1,0) } Già che stavo mettendo mano al codice, ho deciso di revisionare inoltre del tutto il funzionamento. Al posto di gestire le eccezioni, aggiungo dei frame in testa e in coda. In questo modo, idealmente, si dovrebbe riuscire a rendere leggermente più rapido il codice di strange, perché ha molti meno if da gestire. Tuttavia, non avendo usando estensivamente questa versione di strange (anzi, al momento è puramente codice teorico che non ho provato con mano), non ho modo di caldeggiarla senza test su strada. La lascio qui sotto come funzione a parte, stranger: SPOILER (clicca per visualizzare) CODICE #strange v2.2 by mirkosp #Yet Another function similar to ApplyRange in purpose that works somewhat differently. #Start and end work exactly like first_frame and last_frame work with trim(), for the #sake of consistency, which means that you can use end as if it was -num_frames too. #ofps parameter tells whether to keep the original fps (true) or not (false). #For reference: http://avisynth.org/mediawiki/Trim function stranger (clip c, int "start", int "end", clip "edit", bool "ofps", bool "repeat") { #This function only makes sense with filters that return clips to begin with, so no #point in bothering with strings. It's both easier and better. start = default(start,0) end = default(end,0) edit = default(edit,blankclip(c,length=c.framecount()))#everybody loves blankclip amount = c.framecount() ofps = default(ofps,false) repeat = default(repeat,true) amountedit = edit.framecount() edit = amountedit >= amount ? edit.trim(0,amount-1) : repeat ? (edit+blankclip(edit,amount-amountedit)).freezeframe(amountedit,amount,amountedit-1) : edit+blankclip(edit,amount-amountedit) #Brainfarts check ahead. start = (start < 0) ? 0 : start end = (-end > amount-start) ? 0 : end start = (start > amount-1) ? amount-1 : start end = (end > amount-1) ? 0 : end start = start+3 end = (end == 0) ? amount+2 : (end < 0) ? end : end+3 #Match framerate in case user's custom filtering would change it c = !ofps ? c.assumefps(edit) : c edit = ofps ? edit.assumefps(c) : edit #New approach that avoids special case checks and should be slightly faster frames = blankclip(c,3) c = frames+c+frames edit = frames+edit+frames eclip=edit.trim(start,end) c.trim(0,start-1)+eclip+c.trim(start+eclip.framecount,0) return trim(3,amount+2) } Se qualcuno di voi riuscisse a confermare che il risultato di stranger è bit exact a quello di strange, gliene sarei molto grato. Anche eventuali test della velocità di esecuzione di codice tra strange e stranger potrebbero essere interessanti, anche se credo che la differenza di velocità, se realmente inesistente, sarebbe marginale, salvo un grande impiego di strange(r) nello script, che comunque è una situazione che può verificarsi. Edited by mirkosp - 27/5/2018, 08:34 |