SlideShare a Scribd company logo
HTML5 VIDEO FILTERS 
IN SEARCH OF THE DRAGON BALLS 
Created by giorgio.beggiora@artigianidelweb.it
OBJECTIVE 
Show in a browser a video with the following controls: 
Grayscale 
Brightness 
Contrast 
RGB channels
LOOKING FOR AN IDEA 
1. The mysterious SVG filters? 
✗ potentially the best option, but 2014 is too early because... 
✗ not so good browsers' support 
✗ IE9- (XP/Vista) don't support SVG at all 
2. The lightweight CSS filters? 
✗ bad browsers' support 
✗ no support for feColorMatrix SVG filter 
3. The powerful WebGL? 
✗ bad browsers' support 
✗ unfamiliar enviroment for most developers 
✗ not W3C, depends from graphic board's drivers 
4. The hungry Canvas? 
✓ good browsers' support (IE9+) 
✓ polyfills for IE8 (but don't rely on them) 
✓ familiar enviroment for most developers
A VIDEO IN A CANVAS 
var videoElement = document.getElementById('myVideo') ; 
var canvasElement = document.getElementById('myCanvas') ; 
var canvasContext = canvasElement.getContext('2d') ; 
canvasContext.drawImage(videoElement,0,0,width,height) ; // loop
DEMO 
VIDEO 
854 × 480 = 409.920 px 
× 4 channels = 1.639.680 byte 
CANVAS 
Red 80% 
Green 80% 
Blue 80% 
Contrast 80% 
Brightness 80% 
Black & white 
FPS 13.9
BONUS 
CHROMA KEY
LET'S TRY FULL HD
DEMO FULL HD
WHAT DO WE NEED?
MORE POWER!
PROGRAMMING TIPS 
consider not using frameworks or polyfills 
access DOM as little as possible 
reduce the number of dots 
cache everything (i said EVERITHING!) 
don't write 2 times the same thing 
use while(i--) insead of for(i++) 
multiply instead of divide 
requestAnimationFrame() 
['a','b'].join('') instead of 'a'+'b' 
bitwise operations when convenient (i.e. floor if n>=0) 
O'Reilly - High Performance JavaScript 
jsPerf, StackOverflow, Google
AND NOW, WHAT DO WE NEED?
MORE POWER!
TYPED ARRAYS 
Direct access to RAM (IE10+) 
// Floating point arrays. 
var f64 = new Float64Array(8); 
var f32 = new Float32Array(16); 
// Signed integer arrays. 
var i32 = new Int32Array(16); 
var i16 = new Int16Array(32); 
var i8 = new Int8Array(64); 
// Unsigned integer arrays. 
var u32 = new Uint32Array(16); 
var u16 = new Uint16Array(32); 
var u8 = new Uint8Array(64); 
var pixels = new Uint8ClampedArray(64); 
Example 
var a = new Uint8Array(64); // length = 64 // 0 < value < 2^8 ; 
a[0] = 300 ; 
console.log (a[0]) // 44 = 300 - 256
BUFFERS AND VIEWS 
var buffer = new ArrayBuffer(16); // 16 byte = 128 bit of RAM 
// to access it, you need to create a view 
var int32View = new Uint32Array(buffer); // length = 4 (128/32) 
// each element = 0 < value < 2^32 
// you can create multiple views of the same buffer 
var int8View = new Uint8Array(buffer); // length = 16 (128/8) 
// each element = 0 < value < 2^8 
// what does it mean? 
int32View[0]=300; 
console.log(int32View[0]); // 300 
console.log(int32View[1]); // 0 
console.log(int8View[0]); // 44 
console.log(int8View[1]); // 1 
// it means that the Endianess is "Little-endian" (first byte = less significant)
YOU ARE ALREADY USING THEM 
Canvas 2D 
alert(canvasElement.getContext('2d').getImageData(0,0,w,h).data); 
// in most recent browsers, "data" is an [object Uint8ClampedArray] 
// in older browsers, "data" is an [object CanvasPixelArray] 
// the cause is an HTML5 spec change 
var a = new Uint8ClampedArray(2); // length = 2 < value < 2^8 ; 
a[0] = 300 ; 
console.log (a[0]) // 255 
console.log (a[1]) // 0 
XMLHttpRequest2 
File APIs 
Media Source API 
WebGL 
Transferable objects 
Binary WebSockets
AND NOW, WHAT DO WE NEED?
MORE POWER!
WEB WORKERS (IE10+) 
Execute JavaScript in background (multithreading!!!) 
Honestly, i had no time to try them :P 
demo by Conor Buckley using getUserMedia() 
http://bit.ly/10YhHoK
LET'S TRY ALL THIS STUFF 
(except for web workers)
DEMO FULL HD OPTIMIZED
AND NOW, WHAT DO WE NEED?
MORE POWER!
PIXI.JS 
2D WebGL framework with canvas fallback O.O 
pixijs.com 
(video with audio will autoplay on next slide)
DEMO FULL HD WEBGL
WHAT IS THE (COLOR)MATRIX? 
var brightness_colorMatrix = [ 
// r g b a 
/*R*/ 1, 0, 0, x, 
/*G*/ 0, 1, 0, x, 
/*B*/ 0, 0, 1, x, 
/*A*/ 0, 0, 0, 1 
]; 
// R = r*1 + g*0 + b*0 + a*x ; 
// G = r*0 + g*1 + b*0 + a*x ; 
// B = r*0 + g*0 + b*1 + a*x ; 
// A = r*1 + g*0 + b*0 + a*1 ;
THANK YOU 
BY 
GIORGIO . BEGGIORA @ ARTIGIANI DEL WEB . IT

More Related Content

What's hot (20)

PDF
Principios básicos de Garbage Collector en Java
Víctor Leonel Orozco López
 
PPTX
Intro to node and non blocking io
Amy Hua
 
PPTX
Bs webgl소모임004
Seonki Paik
 
PDF
Node Architecture and Getting Started with Express
jguerrero999
 
PDF
Running JavaScript Efficiently in a Java World
irbull
 
PDF
Add Some Fun to Your Functional Programming With RXJS
Ryan Anklam
 
PPTX
Introduction to Node js
Akshay Mathur
 
KEY
Introduction to node.js
jacekbecela
 
PDF
Cassandra Day Chicago 2015: Building Java Applications with Apache Cassandra
DataStax Academy
 
PDF
Introduction to Node.js: What, why and how?
Christian Joudrey
 
PDF
Google App Engine Developer - Day4
Simon Su
 
PDF
All aboard the NodeJS Express
David Boyer
 
ZIP
Javascript Everywhere
Pascal Rettig
 
PDF
PyCon KR 2019 sprint - RustPython by example
YunWon Jeong
 
PPTX
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
 
PDF
KrakenJS
PayPal
 
PDF
Dev Day 2019: Mirko Seifert – Next Level Integration Testing mit Docker und T...
DevDay Dresden
 
PPTX
Introduction to Node.js
Vikash Singh
 
PPTX
Kraken js at paypal
Lenny Markus
 
PDF
2 docker engine_hands_on
FEG
 
Principios básicos de Garbage Collector en Java
Víctor Leonel Orozco López
 
Intro to node and non blocking io
Amy Hua
 
Bs webgl소모임004
Seonki Paik
 
Node Architecture and Getting Started with Express
jguerrero999
 
Running JavaScript Efficiently in a Java World
irbull
 
Add Some Fun to Your Functional Programming With RXJS
Ryan Anklam
 
Introduction to Node js
Akshay Mathur
 
Introduction to node.js
jacekbecela
 
Cassandra Day Chicago 2015: Building Java Applications with Apache Cassandra
DataStax Academy
 
Introduction to Node.js: What, why and how?
Christian Joudrey
 
Google App Engine Developer - Day4
Simon Su
 
All aboard the NodeJS Express
David Boyer
 
Javascript Everywhere
Pascal Rettig
 
PyCon KR 2019 sprint - RustPython by example
YunWon Jeong
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
 
KrakenJS
PayPal
 
Dev Day 2019: Mirko Seifert – Next Level Integration Testing mit Docker und T...
DevDay Dresden
 
Introduction to Node.js
Vikash Singh
 
Kraken js at paypal
Lenny Markus
 
2 docker engine_hands_on
FEG
 

Similar to HTML5 video filters (20)

PDF
Browsers with Wings
Remy Sharp
 
PDF
HTML5: where flash isn't needed anymore
Remy Sharp
 
PDF
How to build a html5 websites.v1
Bitla Software
 
PDF
HTML5: friend or foe (to Flash)?
Remy Sharp
 
PDF
BINARY DATA ADVENTURES IN BROWSER JAVASCRIPT
Or Hiltch
 
PPT
WebGL: GPU acceleration for the open web
pjcozzi
 
KEY
Stupid Canvas Tricks
deanhudson
 
PDF
Google's HTML5 Work: what's next?
Patrick Chanezon
 
PPTX
Top 10 HTML5 features every developer should know!
Gill Cleeren
 
PPTX
Top 10 HTML5 features
Gill Cleeren
 
PDF
HTML5 APIs - The New Frontier 2011
Robert Nyman
 
PDF
Html5apis thenewfrontier-knowit-110203080245-phpapp02
Rajkumar Agarwal
 
ODP
Graphics & Animation with HTML5
Knoldus Inc.
 
KEY
Canvas: we must go deeper
ardcore
 
PPT
Game Development With HTML5
Gil Megidish
 
PDF
codebits 2009 HTML5 JS APIs
Remy Sharp
 
PPTX
HTML5 and Other Modern Browser Game Tech
vincent_scheib
 
PPT
Canvas in html5 - TungVD
Framgia Vietnam
 
PPTX
Javascript Animation with Canvas - Gregory Starr 2015
Gregory Starr
 
PPTX
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)
Felix Faber
 
Browsers with Wings
Remy Sharp
 
HTML5: where flash isn't needed anymore
Remy Sharp
 
How to build a html5 websites.v1
Bitla Software
 
HTML5: friend or foe (to Flash)?
Remy Sharp
 
BINARY DATA ADVENTURES IN BROWSER JAVASCRIPT
Or Hiltch
 
WebGL: GPU acceleration for the open web
pjcozzi
 
Stupid Canvas Tricks
deanhudson
 
Google's HTML5 Work: what's next?
Patrick Chanezon
 
Top 10 HTML5 features every developer should know!
Gill Cleeren
 
Top 10 HTML5 features
Gill Cleeren
 
HTML5 APIs - The New Frontier 2011
Robert Nyman
 
Html5apis thenewfrontier-knowit-110203080245-phpapp02
Rajkumar Agarwal
 
Graphics & Animation with HTML5
Knoldus Inc.
 
Canvas: we must go deeper
ardcore
 
Game Development With HTML5
Gil Megidish
 
codebits 2009 HTML5 JS APIs
Remy Sharp
 
HTML5 and Other Modern Browser Game Tech
vincent_scheib
 
Canvas in html5 - TungVD
Framgia Vietnam
 
Javascript Animation with Canvas - Gregory Starr 2015
Gregory Starr
 
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)
Felix Faber
 
Ad

More from Artigiani del Web (16)

PDF
Innovazione sociale alimentata dalle persone
Artigiani del Web
 
PPT
Dal fordismo al toyotismo asso
Artigiani del Web
 
PDF
Costruire la comunità globale
Artigiani del Web
 
PDF
La produzione domestica
Artigiani del Web
 
PDF
Il "Bravo Ragazzo di Quartiere"
Artigiani del Web
 
PDF
Taralla di Agerola
Artigiani del Web
 
PDF
Cuci Scuci
Artigiani del Web
 
PDF
Noivotiamo
Artigiani del Web
 
PDF
Agerola frutta e verdura
Artigiani del Web
 
PDF
Presentazione food ita ottobre 2013
Artigiani del Web
 
PDF
Il discorso del cortile
Artigiani del Web
 
PDF
Agerola
Artigiani del Web
 
PDF
Pantuost
Artigiani del Web
 
PDF
Beati i Secondi
Artigiani del Web
 
PDF
KOLLEMA
Artigiani del Web
 
PDF
Kollema
Artigiani del Web
 
Innovazione sociale alimentata dalle persone
Artigiani del Web
 
Dal fordismo al toyotismo asso
Artigiani del Web
 
Costruire la comunità globale
Artigiani del Web
 
La produzione domestica
Artigiani del Web
 
Il "Bravo Ragazzo di Quartiere"
Artigiani del Web
 
Taralla di Agerola
Artigiani del Web
 
Cuci Scuci
Artigiani del Web
 
Noivotiamo
Artigiani del Web
 
Agerola frutta e verdura
Artigiani del Web
 
Presentazione food ita ottobre 2013
Artigiani del Web
 
Il discorso del cortile
Artigiani del Web
 
Beati i Secondi
Artigiani del Web
 
Ad

Recently uploaded (20)

PPTX
My Mother At 66! (2).pptx00000000000000000000000000000
vedapattisiddharth
 
PPTX
原版一样(毕业证书)法国蒙彼利埃大学毕业证文凭复刻
Taqyea
 
PDF
ContextForge MCP Gateway - the missing proxy for AI Agents and Tools
Mihai Criveti
 
PDF
BRKSP-2551 - Introduction to Segment Routing.pdf
fcesargonca
 
PDF
FutureCon Seattle 2025 Presentation Slides - You Had One Job
Suzanne Aldrich
 
PDF
google promotion services in Delhi, India
Digital Web Future
 
PPTX
Lesson 1.1 Career-Opportunities-in-Ict.pptx
lizelgumadlas1
 
PDF
Materi tentang From Digital Economy to Fintech.pdf
Abdul Hakim
 
PDF
The Convergence of Threat Behaviors Across Intrusions
Joe Slowik
 
PDF
Beginning-Laravel-Build-Websites-with-Laravel-5.8-by-Sanjib-Sinha-z-lib.org.pdf
TagumLibuganonRiverB
 
PDF
Digital burnout toolkit for youth workers and teachers
asociatiastart123
 
PPTX
Ransomware attack and its effects on cyber crimes
ShilpaShreeD
 
PPTX
Metaphysics_Presentation_With_Visuals.pptx
erikjohnsales1
 
PDF
Empowering Local Language Email with IDN & EAI – Powered by XgenPlus
XgenPlus Technologies
 
PPTX
Class_4_Limbgvchgchgchgchgchgcjhgchgcnked_Lists.pptx
test123n
 
PPTX
PHIPA-Compliant Web Hosting in Toronto: What Healthcare Providers Must Know
steve198109
 
PDF
Strategic Plan New and Completed Templeted
alvi932317
 
PPTX
美国电子毕业证帕克大学电子版成绩单UMCP学费发票办理学历认证
Taqyea
 
PPTX
Introduction-to-the-AWS-Solution-Architect.pptx
Prince391830
 
PPTX
Meloniusk_Communication_Template_best.pptx
howesix147
 
My Mother At 66! (2).pptx00000000000000000000000000000
vedapattisiddharth
 
原版一样(毕业证书)法国蒙彼利埃大学毕业证文凭复刻
Taqyea
 
ContextForge MCP Gateway - the missing proxy for AI Agents and Tools
Mihai Criveti
 
BRKSP-2551 - Introduction to Segment Routing.pdf
fcesargonca
 
FutureCon Seattle 2025 Presentation Slides - You Had One Job
Suzanne Aldrich
 
google promotion services in Delhi, India
Digital Web Future
 
Lesson 1.1 Career-Opportunities-in-Ict.pptx
lizelgumadlas1
 
Materi tentang From Digital Economy to Fintech.pdf
Abdul Hakim
 
The Convergence of Threat Behaviors Across Intrusions
Joe Slowik
 
Beginning-Laravel-Build-Websites-with-Laravel-5.8-by-Sanjib-Sinha-z-lib.org.pdf
TagumLibuganonRiverB
 
Digital burnout toolkit for youth workers and teachers
asociatiastart123
 
Ransomware attack and its effects on cyber crimes
ShilpaShreeD
 
Metaphysics_Presentation_With_Visuals.pptx
erikjohnsales1
 
Empowering Local Language Email with IDN & EAI – Powered by XgenPlus
XgenPlus Technologies
 
Class_4_Limbgvchgchgchgchgchgcjhgchgcnked_Lists.pptx
test123n
 
PHIPA-Compliant Web Hosting in Toronto: What Healthcare Providers Must Know
steve198109
 
Strategic Plan New and Completed Templeted
alvi932317
 
美国电子毕业证帕克大学电子版成绩单UMCP学费发票办理学历认证
Taqyea
 
Introduction-to-the-AWS-Solution-Architect.pptx
Prince391830
 
Meloniusk_Communication_Template_best.pptx
howesix147
 

HTML5 video filters

  • 1. HTML5 VIDEO FILTERS IN SEARCH OF THE DRAGON BALLS Created by [email protected]
  • 2. OBJECTIVE Show in a browser a video with the following controls: Grayscale Brightness Contrast RGB channels
  • 3. LOOKING FOR AN IDEA 1. The mysterious SVG filters? ✗ potentially the best option, but 2014 is too early because... ✗ not so good browsers' support ✗ IE9- (XP/Vista) don't support SVG at all 2. The lightweight CSS filters? ✗ bad browsers' support ✗ no support for feColorMatrix SVG filter 3. The powerful WebGL? ✗ bad browsers' support ✗ unfamiliar enviroment for most developers ✗ not W3C, depends from graphic board's drivers 4. The hungry Canvas? ✓ good browsers' support (IE9+) ✓ polyfills for IE8 (but don't rely on them) ✓ familiar enviroment for most developers
  • 4. A VIDEO IN A CANVAS var videoElement = document.getElementById('myVideo') ; var canvasElement = document.getElementById('myCanvas') ; var canvasContext = canvasElement.getContext('2d') ; canvasContext.drawImage(videoElement,0,0,width,height) ; // loop
  • 5. DEMO VIDEO 854 × 480 = 409.920 px × 4 channels = 1.639.680 byte CANVAS Red 80% Green 80% Blue 80% Contrast 80% Brightness 80% Black & white FPS 13.9
  • 9. WHAT DO WE NEED?
  • 11. PROGRAMMING TIPS consider not using frameworks or polyfills access DOM as little as possible reduce the number of dots cache everything (i said EVERITHING!) don't write 2 times the same thing use while(i--) insead of for(i++) multiply instead of divide requestAnimationFrame() ['a','b'].join('') instead of 'a'+'b' bitwise operations when convenient (i.e. floor if n>=0) O'Reilly - High Performance JavaScript jsPerf, StackOverflow, Google
  • 12. AND NOW, WHAT DO WE NEED?
  • 14. TYPED ARRAYS Direct access to RAM (IE10+) // Floating point arrays. var f64 = new Float64Array(8); var f32 = new Float32Array(16); // Signed integer arrays. var i32 = new Int32Array(16); var i16 = new Int16Array(32); var i8 = new Int8Array(64); // Unsigned integer arrays. var u32 = new Uint32Array(16); var u16 = new Uint16Array(32); var u8 = new Uint8Array(64); var pixels = new Uint8ClampedArray(64); Example var a = new Uint8Array(64); // length = 64 // 0 < value < 2^8 ; a[0] = 300 ; console.log (a[0]) // 44 = 300 - 256
  • 15. BUFFERS AND VIEWS var buffer = new ArrayBuffer(16); // 16 byte = 128 bit of RAM // to access it, you need to create a view var int32View = new Uint32Array(buffer); // length = 4 (128/32) // each element = 0 < value < 2^32 // you can create multiple views of the same buffer var int8View = new Uint8Array(buffer); // length = 16 (128/8) // each element = 0 < value < 2^8 // what does it mean? int32View[0]=300; console.log(int32View[0]); // 300 console.log(int32View[1]); // 0 console.log(int8View[0]); // 44 console.log(int8View[1]); // 1 // it means that the Endianess is "Little-endian" (first byte = less significant)
  • 16. YOU ARE ALREADY USING THEM Canvas 2D alert(canvasElement.getContext('2d').getImageData(0,0,w,h).data); // in most recent browsers, "data" is an [object Uint8ClampedArray] // in older browsers, "data" is an [object CanvasPixelArray] // the cause is an HTML5 spec change var a = new Uint8ClampedArray(2); // length = 2 < value < 2^8 ; a[0] = 300 ; console.log (a[0]) // 255 console.log (a[1]) // 0 XMLHttpRequest2 File APIs Media Source API WebGL Transferable objects Binary WebSockets
  • 17. AND NOW, WHAT DO WE NEED?
  • 19. WEB WORKERS (IE10+) Execute JavaScript in background (multithreading!!!) Honestly, i had no time to try them :P demo by Conor Buckley using getUserMedia() http://bit.ly/10YhHoK
  • 20. LET'S TRY ALL THIS STUFF (except for web workers)
  • 21. DEMO FULL HD OPTIMIZED
  • 22. AND NOW, WHAT DO WE NEED?
  • 24. PIXI.JS 2D WebGL framework with canvas fallback O.O pixijs.com (video with audio will autoplay on next slide)
  • 25. DEMO FULL HD WEBGL
  • 26. WHAT IS THE (COLOR)MATRIX? var brightness_colorMatrix = [ // r g b a /*R*/ 1, 0, 0, x, /*G*/ 0, 1, 0, x, /*B*/ 0, 0, 1, x, /*A*/ 0, 0, 0, 1 ]; // R = r*1 + g*0 + b*0 + a*x ; // G = r*0 + g*1 + b*0 + a*x ; // B = r*0 + g*0 + b*1 + a*x ; // A = r*1 + g*0 + b*0 + a*1 ;
  • 27. THANK YOU BY GIORGIO . BEGGIORA @ ARTIGIANI DEL WEB . IT