• Stars
    star
    149
  • Rank 248,619 (Top 5 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created about 2 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

DanmakuRenderEngine is a lightweight and scalable Android danmaku library. 轻量级高扩展安卓弹幕渲染引擎

DanmakuRenderEngine

简体中文版说明 >>>

GitHub license API

DanmakuRenderEngine is a lightweight and scalable danmaku library.

  1. High-performance rendering and low memory usage
  2. Easy-to-use interface with high scalability
  3. Support complex custom danmaku styles
  4. Support custom danmaku motion modes

Download the Demo >>>

screenshot1 screenshot2 screenshot3 screenshot4

Apps Using DanmakuRenderEngine

xigua douyin toutiao dongchedi
Xigua Video Douyin Toutiao DongCheDi

Quick Startup

Add it to your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://artifact.bytedance.com/repository/releases/' }
	}
}

Add dependency to your build.gradle:

implementation 'com.github.bytedance:danmaku-render-engine:$latest_version'

In the simplest case, it only takes four steps to start playing danmakus:

  1. Place DanmakuView to the same size as the video view in the XML layout
  2. Get the DanmakuController through the danmakuView.controller method
  3. Construct a TextData for each danmaku. Only the fields of text, LayerType and showAtTime need to be filled in by default
  4. Call controller.setData() to set the data, and then use controller.start() to start playing

Timeline Synchronization

Control the Danmaku

DanmakuController provides four methods related to the timeline control:

fun start(playTime: Long)  // Play or resume from a paused state.
fun pause()                // Pause and the danmakus on the screen will stop in place.
fun stop()                 // Stop playing which will clear the danmakus on the screen and reset the timeline.
fun clear()                // Clear the danmakus that has been displayed on the screen alone.

Play Synchronization

According to the industry's common implementation logic, the callback of the player and methods of DanmakuController are corresponding as following which can be customized to meet specific needs.

Callback of the Player DanmakuController Comment
RenderStart start
VideoPause pause
VideoResume start
VideoStop pause Let the rest danmakus stay in place after the video is played over
VideoReplay stop
VideoError pause
onSeekStart pause
onSeekComplete clear; if (isPlaying) {start} The screen should be cleared after seek completed
onBufferStart pause
onBufferEnd start

Other Forms of Business

DanmakuRenderEngine library is not coupled with the video. If you want to achieve a picture danmaku similar to Qzone, the approach is similar.

Custom Motion Modes

The rendering structure of DanmakuRenderEngine is divided into different layers by motion modes. Each rendering layer manages the layout and rendering by itself, and they are controlled by the z-index attribute.

DanmakuRenderEngine supports three motion modes by default:

  1. ScrollLayer: scroll from the right to the left
  2. TopCenterLayer: display in the top middle of the screen
  3. BottomCenterLayer: display in the bottom middle of the screen

Implement IRenderLayer interface to develop your custom layer and then call DanmakuController.addRenderLayer() to register it. After that, DanmakuRenderEngine will automatically delivery every DanmakuData with the specify LayerType to the corresponding Layer for typesetting and drawing.

Custom Danmaku Style

Definition

DanmakuRenderEngine library divides a danmaku into two part during design: a data entity (DanmakuData) and a drawing entity (DrawItem):

  1. DanmakuData only contains the data attribute of this danmaku, which will not change unless modified manually
  2. DrawItem defines how this danmaku will be drawn, and also contains the attributes will be using by drawing (x/y/width/height, etc.)
  3. DrawItem properties will be continuously modified by RenderLayer logic during the rendering process, and will be recycled and reused after it been moved out of the screen

To make a custom danmaku you need to inherit the three classes below:

  1. CustomDanmakuData
  2. CustomDrawItem
  3. CustomDrawItemFactory

Then call DanmakuController.registerDrawItemFactory() to register your custom factory, and DanmakuRenderEngine will use the registered factory to generate a CustomDrawItem automatically when there is a custom CustomDanmakuData.

Implementation

Based on the idea that combination is better than inheritance, DanmakuRenderEngine only provides two types of danmaku by default: text (TextData) and picture (BitmapData). Most advanced types of danmaku can be implemented by combining the two basic ones.

The custom DanmakuData and DrawItem need to be defined by the same structure. When the x, y and other attributes is changing, the new value will be distributed downward.

Take the danmaku style of the Xigua Video as an example, it has three parts: text, like icon and the number of likes:

Custom Danmaku

The structure combination of DanmakuData is as follows:

Danmaku Data

Note that the canvas is accessible in the DrawItem which means you can draw directly with it. The background of the above-mentioned like icon is drawn by the canvas.

Danmaku Configuration

Requirements

Under typical circumstances, we have to modify the properties of danmaku sometimes:

  1. The font size and line height of a danmaku should be larger after entering the full screen, and smaller after exiting.
  2. The font color of a danmaku should be changed after being give a like.
  3. Changing the font size, transparency, etc. of all danmaku from the setting panel.

Similar requirements can mainly achieved through the DanmakuController.config in DanmakuRenderEngine.

Cascade and Priority

DanmakuRenderEngine is designed to use the concept of cascade and priority in configuration similar to CSS according to actual needs.

Config is the global configuration with the lowest priority, which is divided into:

val debug = DebugConfig(this)
val common = CommonConfig(this)
val text = TextConfig(this)
val underline = UnderlineConfig(this)
val scroll = ScrollLayerConfig(this)
val top = TopCenterLayerConfig(this)
val bottom = BottomCenterLayerConfig(this)

For example, TextConfig in Config control the global size and color of all text. Meanwhile the TextData of each danmaku can also control the TextSize and TextColor of itself which has higher priority.

If a property is defined in TextData, then this one takes effect.
If it is not defined in TextData, then the one defined in Config takes effect.

Commands and Events

For a danmaku library, there are usually two requirements:

  1. Let the library to do some things, such as:
    1. pause a danmaku.
    2. change the color of a danmaku.
  2. The library informs the outside that something has happened, such as:
    1. a danmaku has been displayed.
    2. a danmaku has been removed from the screen.
    3. the size of a danmaku changed.

In response to these requirements, DanmakuRenderEngine has designed two sets of mechanisms: command and event

Command

DanmakuCommand is used to let DanmakuRenderEngine to do something which main entrance isDanmakuController.executeCommand(), such as:

mController?.executeCommand(CMD_PAUSE_ITEM, data)           // pause a danmaku
mController?.executeCommand(CMD_RESUME_ITEM, data)          // resume a danmaku
mController?.executeCommand(CMD_SET_TOUCHABLE, null, false) // make danmaku view unclickable

Event

DanmakuEvent is used to notify something has happend, you can use the method of DanmakuController.addEventListener() to register listeners. And use the DanmakuEvent.what to determine the type of Event, for example:

override fun onEvent(event: DanmakuEvent) {
    when (event.what) {
        EVENT_DANMAKU_SHOW -> {}     // event.data shows
        EVENT_DANMAKU_DISMISS -> {}  // event.data dismisses
        EVENT_DANMAKU_REMEASURE -> {
            (event.param as? RectF)?.let { rectF ->
                // event.data has been remeasured and the new size is rectF
            }
        }
    }
}

Masked Danmaku

"Masked Danmaku" is an advanced feature that can achieve the effect of "not blocking the portrait". After turning on this function, the danmakus will no longer cover the portrait, but will pass through behind the human body.

DanmakuRenderEngine has built-in the realization of "Masked Danmaku", and it only takes a few simple steps to turn it on.

  1. Analyze the content of the video content in advance, and calculate the closed SVG path that needs to be cut out for each frame.
  2. Assemble each mask Path data into a MaskData structure.
  3. Set these MaskData to DanmakuController like other danmaku data
  4. Turn on the switch: DanmakuController.config.mask.enable = true

(The above code can refer to SmartMaskActivity.kt

Requires attention:

  1. DanmakuRenderEngine only provides the implementation of "Masked Danmaku" on Android, and does not provide the function of content analyzing or mask path generating. You need to analyzing the screen content on server side by using AI tools in advance and deliver the data to client.
  2. DanmakuRenderEngine has no restrictions on the frame rate of the MaskData. But it is recommended not to be higher than 30Hz for performance and data transmission considerations (the effect is already good enough when greater than 10Hz). At the same time, DanmakuRenderEngine also supports dynamic frame rate masks by specifying the start and end time of each MaskData.

Q&A

Q1:Can I dynamically insert the DanmakuView?

A:Yes. You can create a DanmakuView and overlay it on the top of the video screen whenever you want, as long as the size of DanmakuView and the video screen are always the same (for example, when switching full screen state).

Q2:Can I set or add danmaku data after play it?

A:Yes. But the danmakus which showAtTime is before the set time will not be displayed this time (if you seek forward, they can still be displayed).

License

Copyright (c) 2022 ByteDance Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

IconPark

🍎Transform an SVG icon into multiple themes, and generate React icons,Vue icons,svg icons
TypeScript
8,298
star
2

xgplayer

A HTML5 video player with a parser that saves traffic
JavaScript
8,260
star
3

sonic

A blazingly fast JSON serializing & deserializing library
Assembly
6,870
star
4

monoio

Rust async runtime based on io-uring.
Rust
3,864
star
5

byteps

A high performance and generic framework for distributed DNN training
Python
3,603
star
6

lightseq

LightSeq: A High Performance Library for Sequence Processing and Generation
C++
3,193
star
7

ByteX

ByteX is a bytecode plugin platform based on Android Gradle Transform API and ASM. 字节码插件开发平台
Java
2,865
star
8

Elkeid

Elkeid is an open source solution that can meet the security requirements of various workloads such as hosts, containers and K8s, and serverless. It is derived from ByteDance's internal best practices.
Go
2,226
star
9

AlphaPlayer

AlphaPlayer is a video animation engine.
Java
2,181
star
10

scene

Android Single Activity Framework compatible with Fragment.
Java
2,097
star
11

bhook

🔥 ByteHook is an Android PLT hook library which supports armeabi-v7a, arm64-v8a, x86 and x86_64.
C
2,073
star
12

flutter_ume

UME is an in-app debug kits platform for Flutter. Produced by Flutter Infra team of ByteDance
Dart
2,053
star
13

terarkdb

A RocksDB compatible KV storage engine with better performance
C++
2,044
star
14

btrace

🔥🔥 btrace(AKA RheaTrace) is a high performance Android trace tool which is based on Perfetto, it support to define custom events automatically during building apk and using bhook to provider more native events like Render/Binder/IO etc.
Kotlin
1,913
star
15

gopkg

Universal Utilities for Go
Go
1,704
star
16

android-inline-hook

🔥 ShadowHook is an Android inline hook library which supports thumb, arm32 and arm64.
C
1,660
star
17

bitsail

BitSail is a distributed high-performance data integration engine which supports batch, streaming and incremental scenarios. BitSail is widely used to synchronize hundreds of trillions of data every day.
Java
1,627
star
18

go-tagexpr

An interesting go struct tag expression syntax for field validation, etc.
Go
1,470
star
19

GiantMIDI-Piano

Python
1,431
star
20

appshark

Appshark is a static taint analysis platform to scan vulnerabilities in an Android app.
Kotlin
1,363
star
21

AabResGuard

The tool of obfuscated aab resources.(Android app bundle资源混淆工具)
Java
1,307
star
22

piano_transcription

Python
1,247
star
23

CodeLocator

Kotlin
1,163
star
24

BoostMultiDex

BoostMultiDex is a solution for quickly loading multiple dex files on low Android version devices (4.X and below, SDK <21).
Java
1,106
star
25

music_source_separation

Python
1,039
star
26

Fastbot_Android

Fastbot(2.0) is a model-based testing tool for modeling GUI transitions to discover app stability problems
C++
1,031
star
27

SALMONN

SALMONN: Speech Audio Language Music Open Neural Network
Python
1,000
star
28

memory-leak-detector

C
919
star
29

fedlearner

A multi-party collaborative machine learning framework
Python
892
star
30

monolith

ByteDance's Recommendation System
Python
844
star
31

sonic-cpp

A fast JSON serializing & deserializing library, accelerated by SIMD.
C++
811
star
32

godlp

sensitive information protection toolkit
Go
770
star
33

MVDream

Multi-view Diffusion for 3D Generation
Python
744
star
34

res-adapter

Official implementation of "ResAdapter: Domain Consistent Resolution Adapter for Diffusion Models".
Python
724
star
35

bytemd

ByteMD v1 repository
TypeScript
679
star
36

tailor

C
669
star
37

ibot

iBOT 🤖: Image BERT Pre-Training with Online Tokenizer (ICLR 2022)
Jupyter Notebook
663
star
38

RealRichText

A Tricky Solution for Implementing Inline-Image-In-Text Feature in Flutter.
Dart
658
star
39

guide

A new feature guide component by react 🧭
TypeScript
651
star
40

mockey

a simple and easy-to-use golang mock library
Go
622
star
41

magic-microservices

Make Web Components easier and powerful!😘
TypeScript
570
star
42

Fastbot_iOS

About Fastbot(2.0) is a model-based testing tool for modeling GUI transitions to discover app stability problems
Objective-C
553
star
43

flow-builder

A highly customizable streaming flow builder.
TypeScript
526
star
44

MVDream-threestudio

3D generation code for MVDream
Python
473
star
45

effective_transformer

Running BERT without Padding
C++
457
star
46

ByteTransformer

optimized BERT transformer inference on NVIDIA GPU. https://arxiv.org/abs/2210.03052
C++
449
star
47

Next-ViT

Python
426
star
48

matxscript

A high-performance, extensible Python AOT compiler.
C++
408
star
49

byteir

A model compilation solution for various hardware
MLIR
362
star
50

syllepsis

Syllepsis is an out-of-the-box rich text editor.
TypeScript
355
star
51

uss

This is the PyTorch implementation of the Universal Source Separation with Weakly labelled Data.
Python
324
star
52

OMGD

Online Multi-Granularity Distillation for GAN Compression (ICCV2021)
Python
323
star
53

neurst

Neural end-to-end Speech Translation Toolkit
Python
298
star
54

danmu.js

HTML5 danmu (danmaku) plugin for any DOM element
JavaScript
292
star
55

vArmor

vArmor is a cloud native container sandbox system based on AppArmor/BPF/Seccomp. It also includes multiple built-in protection rules that are ready to use out of the box.
Go
263
star
56

particle-sfm

ParticleSfM: Exploiting Dense Point Trajectories for Localizing Moving Cameras in the Wild. ECCV 2022.
C++
263
star
57

CloudShuffleService

Cloud Shuffle Service(CSS) is a general purpose remote shuffle solution for compute engines, including Spark/Flink/MapReduce.
Java
245
star
58

lynx-llm

paper: https://arxiv.org/abs/2307.02469 page: https://lynx-llm.github.io/
Python
227
star
59

g3

Enterprise-oriented Generic Proxy Solutions
Rust
227
star
60

xgplayer-vue

Vue component for xgplayer, a HTML5 video player with a parser that saves traffic
JavaScript
219
star
61

DEADiff

[CVPR 2024] Official implementation of "DEADiff: An Efficient Stylization Diffusion Model with Disentangled Representations"
Python
209
star
62

flux

A fast communication-overlapping library for tensor parallelism on GPUs.
C++
201
star
63

trace-irqoff

Interrupts-off or softirqs-off latency tracer
C
195
star
64

ParaGen

ParaGen is a PyTorch deep learning framework for parallel sequence generation.
Python
186
star
65

ByteMLPerf

AI Accelerator Benchmark focuses on evaluating AI Accelerators from a practical production perspective, including the ease of use and versatility of software and hardware.
Python
181
star
66

MoMA

MoMA: Multimodal LLM Adapter for Fast Personalized Image Generation
Jupyter Notebook
177
star
67

AWERTL

An non-invasive iOS framework for quickly adapting Right-To-Left style UI
Objective-C
175
star
68

Bytedance-UnionAD

Ruby
170
star
69

keyhouse

Keyhouse is a skeleton of general-purpose Key Management System written in Rust.
Rust
163
star
70

react-model

The next generation state management library for React
TypeScript
162
star
71

LargeBatchCTR

Large batch training of CTR models based on DeepCTR with CowClip.
Python
162
star
72

ic_flow_platform

IFP (ic flow platform) is an integrated circuit design flow platform, mainly used for IC process specification management and data flow contral.
Python
154
star
73

primus

Java
148
star
74

diat

A CLI tool to help with diagnosing Node.js processes basing on inspector.
JavaScript
146
star
75

coconut_cvpr2024

Jupyter Notebook
143
star
76

Hammer

An efficient toolkit for training deep models.
Python
138
star
77

ns-x

An easy-to-use, flexible network simulator library in Go.
Go
116
star
78

pv3d

Python
113
star
79

fc-clip

This repo contains the code for our paper Convolutions Die Hard: Open-Vocabulary Segmentation with Single Frozen Convolutional CLIP
Python
109
star
80

RLFN

Winner of runtime track in NTIRE 2022 challenge on Efficient Super-Resolution
Python
106
star
81

DCFrame

DCFrame is a Swift UI collection framework, which can easily create complex UI.
Swift
100
star
82

trace-noschedule

Trace noschedule thread
C
99
star
83

decoupleQ

A quantization algorithm for LLM
Cuda
99
star
84

tar-wasm

A faster experimental wasm-based tar implementation for browsers.
Rust
95
star
85

TWIST

Official codes: Self-Supervised Learning by Estimating Twin Class Distribution
Python
95
star
86

magic-portal

⚡ A blazing fast micro-component and micro-frontend solution uses web-components under the hood.
TypeScript
91
star
87

xgplayer-react

React component for xgplayer, a HTML5 video player with a parser that saves traffic
JavaScript
84
star
88

fe-foundation

UI Foundation for React Hooks and Vue Composition Api
TypeScript
80
star
89

nnproxy

Scalable NameNode RPC Proxy for HDFS Federation
Java
79
star
90

dbatman

Go
74
star
91

Elkeid-HUB

Elkeid HUB is a rule/event processing engine maintained by the Elkeid Team that supports streaming/offline (not yet supported by the community edition) data processing. The original intention is to solve complex data/event processing and external system linkage requirements through standardized rules.
Python
74
star
92

FreeSeg

Python
69
star
93

pull_to_refresh

Flutter pull_to_refresh widget
Dart
67
star
94

Jeddak-DPSQL

DPSQL (Privacy Protection SQL Query Service) - This project is a microservice Middleware located between the database engine ( Hive , Clickhouse , etc.) and the application system. It provides transparent SQL query result desensitization capabilities.
Python
62
star
95

terark-zip

A data structure and algorithm library built for TerarkDB
C++
62
star
96

trace-runqlat

C
61
star
97

ipmb

An interprocess message bus system built in Rust.
Rust
60
star
98

X-Portrait

Source code for the SIGGRAPH 2024 paper "X-Portrait: Expressive Portrait Animation with Hierarchical Motion Attention"
Python
59
star
99

kernel

ByteDance kernel for use on cloud.
C
57
star
100

scroll_kit

Dart
56
star