Slide 1

Slide 1 text

Смешные шапочки на Insertable Streams

Slide 2

Slide 2 text

Начнем с WebRTC…

Slide 3

Slide 3 text

Пересылаем видео, аудио, файлики, скриншару Challenge В условиях Лагающего интернета Злых админов, настроивших fi rewall Между Большим количеством участников С разными приоритетами 🧟🧟🧟

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Как работает WebRTC new RTCPeerConnection(…) new RTCPeerConnection(…) 🦄

Slide 6

Slide 6 text

Media: SRTP + SRTCP Data: SCTP Шифрование Работает поверх UDP→быстрее Можно терять пакеты, если нужно Не гарантирует порядок Bundling DTLS: TLS для UDP

Slide 7

Slide 7 text

Как выглядит пожатое видео?

Slide 8

Slide 8 text

Compression: intra & inter

Slide 9

Slide 9 text

Intraframe compression (AV1)

Slide 10

Slide 10 text

Какие кодеки поддерживает ваш браузер?

Slide 11

Slide 11 text

Чего-то не хватает….

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Streams 101

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Insertable-streams const stream = await getUserMedia({ video: true }); const track = stream.getVideoTracks()[0]; const processor = new MediaStreamTrackProcessor({ track }); const generator = new MediaStreamTrackGenerator({ kind: 'video' }); const transformer = new TransformStream({ async transform(frame, controller) { const newFrame = processFrameSomehow(frame); videoFrame.close(); controller.enqueue(newFrame); }, }); trackProcessor.readable.pipeThrough(transformer).pipeTo(trackGenerator.writable);

Slide 19

Slide 19 text

Как же нарисовать ?

Slide 20

Slide 20 text

Нам нужна нейронка :)

Slide 21

Slide 21 text

Находим точки одевания шапочки Выбираем бекенд •WebAssembly •WebGL •WebGPU Находим нужную модель или грузим свою • Лучше использовать Lite (Mobile) варианты Закидываем в модель пиксели •getImageData •VideoDecoder.decode Запускаем модель и получаем результат

Slide 22

Slide 22 text

Рисуем const silhouette = predictions[0].annotations.silhouette const slice = [silhouette[silhouette.length - 4], silhouette[0], silhouette[4]] const hatW = slice[2][0] - slice[0][0] const hatH = hatW * ratio ctx.drawImage(image, slice[0][0] + 0.2 * hatW, slice[0][1] - 0.8 * hatH, hatW, hatH)

Slide 23

Slide 23 text

Крафтим новый поток const transformer = new TransformStream({ async transform(frame, controller) { // ... const newFrame = new VideoFrame(canvas, { timestamp: frame.timestamp }) controller.enqueue(newFrame) frame.close() }}) trackProcessor.readable.pipeThrough(transformer).pipeTo(trackGenerator.writable) const transformedStream = new MediaStream([trackGenerator])

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Что еще можно делать? • Encryption • Analytics • Transcoding (VideoEncoder) • Frame rate change

Slide 26

Slide 26 text

@polina_gurtovaya @pgurtovaya @evilmartians @evilmartians_ru evilmartians.com Спасибо! [email protected]