Recensubs HQ

Strange, non credo ci fosse già un topic apposito

« Older   Newer »
  Share  
view post Posted on 17/4/2018, 17:39     +3   +1   -1
Avatar

Bimbosp

Group:
Administrator
Posts:
9,780
Reputation:
+929
Location:
Gallarate (VA)

Status:


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:
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:
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
 
Web  Top
view post Posted on 18/4/2018, 08:22     +1   -1
Avatar

Bimbosp

Group:
Administrator
Posts:
9,780
Reputation:
+929
Location:
Gallarate (VA)

Status:


Aggiornati alla v1.5 e v2.1: ho parametrizzato il repeat, ora si può decidere di tenere il fill come un blankclip nero (di default resta un freeze).
 
Web  Top
view post Posted on 20/4/2018, 15:44     +1   -1
Avatar

Member

Group:
Utente abilitato
Posts:
501
Reputation:
+10

Status:


Scrivo solo per linkare l'immagine completa di Lenna usata da sp:

len_full
 
Top
view post Posted on 22/4/2018, 12:09     +1   -1
Avatar

Advanced Member

Group:
Utente abilitato
Posts:
2,253
Reputation:
+32
Location:
Shichiriashima

Status:


In realtà ha messo solo la faccia perché altrimenti tutti si sarebbero concentrati sulle sue "qualità" e non su Strange.
 
Top
view post Posted on 22/4/2018, 15:08     +1   -1
Avatar

Bimbosp

Group:
Administrator
Posts:
9,780
Reputation:
+929
Location:
Gallarate (VA)

Status:


https://it.wikipedia.org/wiki/Lenna_(immagine)

Visto che ne state discutendo...
 
Web  Top
view post Posted on 22/4/2018, 17:05     +1   +1   -1

Member

Group:
Utente abilitato
Posts:
968
Reputation:
+161
Location:
Trentino Alto Adige

Status:


Ogni encoder che si rispetti ha la copia di Playboy di Novembre 1972

https://www.amazon.com/Playboy-Magazine-No...r/dp/B00TMIC0ZO
 
Top
view post Posted on 22/4/2018, 19:37     +1   -1
Avatar

Advanced Member

Group:
Utente abilitato
Posts:
2,253
Reputation:
+32
Location:
Shichiriashima

Status:


CITAZIONE (mirkosp @ 22/4/2018, 16:08) 
https://it.wikipedia.org/wiki/Lenna_(immagine)

Visto che ne state discutendo...

No vabbè ma grazie infinitamente, questa scoperta mi ha sconvolto l'esistenza, tutto ciò è stupendo.
 
Top
view post Posted on 23/4/2018, 13:52     +1   -1
Avatar

Member

Group:
Utente abilitato
Posts:
843
Reputation:
+38

Status:


ROTFL
 
Top
view post Posted on 23/4/2018, 15:02     +1   -1
Avatar

Bimbosp

Group:
Administrator
Posts:
9,780
Reputation:
+929
Location:
Gallarate (VA)

Status:


Tornando in topic, ho fatto un confronto in caso limite e stranger è circa 1.5% più veloce di strange (in media).
In situazioni normali non dovrebbe comportare differenze sostanziali, ma tenetelo presente.

Dal poco che l'ho usato sembra inoltre esente da bug di trim, ma non si sa mai.

Edited by mirkosp - 23/4/2018, 23:09
 
Web  Top
view post Posted on 22/5/2018, 10:05     +1   -1
Avatar

Bimbosp

Group:
Administrator
Posts:
9,780
Reputation:
+929
Location:
Gallarate (VA)

Status:


ATTENZIONE: Stranger si direbbe buggato usando l'end negativo (quindi facendo tipo 0,-1 come range). Usate strange in caso vi servissero valori negativi, al momento non sono interessato a sistemare il codice per i valori negativi. Se invece dovete usare solo i frame, funziona correttamente.

Edited by mirkosp - 27/5/2018, 08:37
 
Web  Top
view post Posted on 27/5/2018, 07:35     +1   +1   -1
Avatar

Bimbosp

Group:
Administrator
Posts:
9,780
Reputation:
+929
Location:
Gallarate (VA)

Status:


Ok, stranger aggiornato alla 2.2 (era facile, in realtà).
 
Web  Top
10 replies since 17/4/2018, 17:39   645 views
  Share