Skip to content

Commit

Permalink
Merge branch 'ass'
Browse files Browse the repository at this point in the history
* ass: (182 commits)
  bump k0.11.0
  fix  clang15 (Xcode15) ld: archive member '/' not a mach-o file in 'xxx.a' error
  support microdvd subtitle decoder
  when detect subtitle encoding need close exSub before close subComponent
  optimize frame queue subtitle pts, in especial queue size is 1
  when select stream failed set IJKM_KEY_TIMEDTEXT_STREAM to -1
  when select stream failed send FFP_MSG_SELECTING_STREAM_FAILED msg
  handle reselected same internal subtitle stream
  no need convert to ms
  fix can't peek first frame bug
  fix can't find subtitle decoder crash
  fix overflow crash
  unify external subtitle count to 512
  save chapter meta info to IJKFFMonitor's chapterMetaArr property
  fix SDL_WaitThread abort : when open external input failed, read_thread is NULL.
  update changelog
  say goodbye to iOS OpenGL renderer.
  rename ijksdl_gpu_opengl_compiler_macos to ijksdl_gpu_opengl_shader_compiler
  after exchange internal stream will seek file, so need flush the backup queue.
  when close subtitle stream need notify msg
  ...

# Conflicts:
#	examples/ios/Podfile.lock
#	examples/macos/Podfile.lock
#	ijkmedia/ijksdl/metal/IJKMetalView.m
  • Loading branch information
debugly committed May 11, 2024
2 parents ded6aa4 + fd6f35e commit 9ea3715
Show file tree
Hide file tree
Showing 186 changed files with 12,039 additions and 10,868 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
tag k0.11.0
--------------------------------

- support ass subtitle effects, and adjust position and scale in real time
- support display multiple pgs bitmap subtitle at the same moment, and adjust position and scale in real time
- dropped old subtitle renderer (text->image(Core Graphics)->CVPixelBuffer->Texture)
- subtitle preference move to player from view
- dropped iOS OpenGL renderer
- support http gzip and deflate use headers
- restore ijk dns cache and http event hook
- enable microdvd subtitle decoder
- meta add chapter info

tag k0.10.5
--------------------------------

Expand All @@ -10,7 +23,7 @@ tag k0.10.4
- support install third pre-compiled libs
- external subtitle support GBK、BIG5-2003 character set
- fix subtitle display more bigger bug on non-retina screen using metal
- support render P216YUV422P16P416YUV444P16AYUV64YUVA444P16 pixel format directly
- support render P216YUV422P16P416YUV444P16AYUV64YUVA444P16 pixel format directly
- upgrade ffmpeg to 5.1.4,openssl to 1.1.1w,opus to 1.4,dav1d to 1.3.0,bluray to 1.3.4

tag k0.10.3
Expand Down
24 changes: 19 additions & 5 deletions IJKMediaPlayerKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'IJKMediaPlayerKit'
s.version = '0.10.5'
s.version = '0.11.0'
s.summary = 'IJKMediaPlayerKit for ios/macOS.'

# This description is used to generate tags and improve search results.
Expand Down Expand Up @@ -37,6 +37,7 @@ TODO: Add long description of the pod here.
'${PODS_TARGET_SRCROOT}/shell/build/product/macos/universal/ffmpeg/include',
'${PODS_TARGET_SRCROOT}/shell/build/product/macos/universal/bluray/include',
'${PODS_TARGET_SRCROOT}/shell/build/product/macos/universal/dvdread/include',
'${PODS_TARGET_SRCROOT}/shell/build/product/macos/universal/ass/include',
'${PODS_TARGET_SRCROOT}/ijkmedia'
],
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) IJK_USE_METAL_2=1',
Expand All @@ -50,6 +51,7 @@ TODO: Add long description of the pod here.
'$(inherited)',
'${PODS_TARGET_SRCROOT}/shell/build/product/ios/universal/ffmpeg/include',
'${PODS_TARGET_SRCROOT}/shell/build/product/ios/universal/dvdread/include',
'${PODS_TARGET_SRCROOT}/shell/build/product/macos/universal/ass/include',
'${PODS_TARGET_SRCROOT}/ijkmedia'
],
'EXCLUDED_ARCHS' => 'armv7',
Expand Down Expand Up @@ -77,7 +79,8 @@ TODO: Add long description of the pod here.
s.source_files =
'ijkmedia/ijkplayer/**/*.{h,c,m,cpp}',
'ijkmedia/ijksdl/**/*.{h,c,m,cpp,metal}',
'ijkmedia/wrapper/apple/*.{h,m}'
'ijkmedia/wrapper/apple/*.{h,m}',
'ijkmedia/tools/*.{h,c}'
# s.project_header_files = 'ijkmedia/**/*.{h}'
s.public_header_files =
'ijkmedia/wrapper/apple/IJKMediaPlayback.h',
Expand All @@ -90,19 +93,30 @@ TODO: Add long description of the pod here.
'ijkmedia/wrapper/apple/IJKKVOController.h',
'ijkmedia/wrapper/apple/IJKVideoRenderingProtocol.h',
'ijkmedia/wrapper/apple/IJKMediaPlayerKit.h',
'ijkmedia/wrapper/apple/IJKInternalRenderView.h'
'ijkmedia/wrapper/apple/IJKInternalRenderView.h',
'ijkmedia/ijkplayer/ff_subtitle_def.h',
'ijkmedia/ijksdl/ijksdl_rectangle.h',
'ijkmedia/tools/*.{h}'
s.exclude_files =
'ijkmedia/ijksdl/ijksdl_extra_log.c',
'ijkmedia/ijkplayer/ijkversion.h',
'ijkmedia/ijkplayer/ijkavformat/ijkioandroidio.c',
'ijkmedia/ijkplayer/android/**/*.*',
'ijkmedia/ijksdl/android/**/*.*',
'ijkmedia/ijksdl/ijksdl_egl.*',
'ijkmedia/ijksdl/ijksdl_container.*',
'ijkmedia/ijksdl/ffmpeg/ijksdl_vout_overlay_ffmpeg.{h,c}'
s.osx.exclude_files =
'ijkmedia/ijksdl/ijksdl_egl.*',
'ijkmedia/ijksdl/ios/*.*',
'ijkmedia/wrapper/apple/IJKAudioKit.*'
s.ios.exclude_files = 'ijkmedia/ijksdl/mac/*.*'
s.ios.exclude_files =
'ijkmedia/ijksdl/mac/*.*',
'ijkmedia/ijksdl/apple/ijksdl_gpu_opengl_macos.{h,m}',
'ijkmedia/ijksdl/apple/ijksdl_gpu_opengl_fbo_macos.{h,m}',
'ijkmedia/ijksdl/apple/ijksdl_gpu_opengl_renderer_macos.{h,m}',
'ijkmedia/ijksdl/apple/ijksdl_gpu_opengl_shader_compiler.{h,m}',
'ijkmedia/ijksdl/gles2/**/*.*',
'ijkmedia/ijksdl/ijksdl_gles2.h'

s.osx.vendored_libraries = 'shell/build/product/macos/universal/**/*.a'
s.ios.vendored_libraries = 'shell/build/product/ios/universal/**/*.a'
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ sudo dpkg-reconfigure dash
```
git clone https://github.com/debugly/ijkplayer.git ijkplayer
cd ijkplayer
git checkout -B latest k0.10.5
git checkout -B latest k0.11.0
cd shell
./init-any.sh macos
Expand All @@ -135,7 +135,7 @@ open ../../examples/macos/IJKMediaMacDemo.xcworkspace
```
git clone https://github.com/debugly/ijkplayer.git ijkplayer
cd ijkplayer
git checkout -B latest k0.10.5
git checkout -B latest k0.11.0
cd shell
./init-any.sh ios
Expand All @@ -150,7 +150,7 @@ open ../../examples/macos/IJKMediaDemo.xcworkspace
```
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-android
cd ijkplayer-android
git checkout -B latest k0.10.5
git checkout -B latest k0.11.0
./init-android.sh
Expand Down
4 changes: 2 additions & 2 deletions android/ijkplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ ext {

targetSdkVersion = 25

versionCode = 1000500
versionName = "0.10.5"
versionCode = 1100000
versionName = "0.11.0"
}

wrapper {
Expand Down
4 changes: 2 additions & 2 deletions android/ijkplayer/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

VERSION_NAME=0.10.5
VERSION_CODE=1000500
VERSION_NAME=0.11.0
VERSION_CODE=1100000
GROUP=tv.danmaku.ijk.media

# http://central.sonatype.org/pages/requirements.html
Expand Down
20 changes: 10 additions & 10 deletions android/ijkplayer/ijkplayer-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ dependencies {
all64Compile project(':ijkplayer-x86')
all64Compile project(':ijkplayer-x86_64')

// compile 'tv.danmaku.ijk.media:ijkplayer-java:0.10.5'
// compile 'tv.danmaku.ijk.media:ijkplayer-exo:0.10.5'
// compile 'tv.danmaku.ijk.media:ijkplayer-java:0.11.0'
// compile 'tv.danmaku.ijk.media:ijkplayer-exo:0.11.0'

// all32Compile 'tv.danmaku.ijk.media:ijkplayer-armv5:0.10.5'
// all32Compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.10.5'
// all32Compile 'tv.danmaku.ijk.media:ijkplayer-x86:0.10.5'
// all32Compile 'tv.danmaku.ijk.media:ijkplayer-armv5:0.11.0'
// all32Compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.11.0'
// all32Compile 'tv.danmaku.ijk.media:ijkplayer-x86:0.11.0'

// all64Compile 'tv.danmaku.ijk.media:ijkplayer-armv5:0.10.5'
// all64Compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.10.5'
// all64Compile 'tv.danmaku.ijk.media:ijkplayer-arm64:0.10.5'
// all64Compile 'tv.danmaku.ijk.media:ijkplayer-x86:0.10.5'
// all64Compile 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.10.5'
// all64Compile 'tv.danmaku.ijk.media:ijkplayer-armv5:0.11.0'
// all64Compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.11.0'
// all64Compile 'tv.danmaku.ijk.media:ijkplayer-arm64:0.11.0'
// all64Compile 'tv.danmaku.ijk.media:ijkplayer-x86:0.11.0'
// all64Compile 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.11.0'

// armv5Compile project(':player-armv5')
// armv7aCompile project(':player-armv7a')
Expand Down
2 changes: 1 addition & 1 deletion android/ijkplayer/ijkplayer-exo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
compile 'com.google.android.exoplayer:exoplayer:r1.5.11'

compile project(':ijkplayer-java')
// compile 'tv.danmaku.ijk.media:ijkplayer-java:0.10.5'
// compile 'tv.danmaku.ijk.media:ijkplayer-java:0.11.0'
}

gradle.startParameter.taskNames.each { task ->
Expand Down
129 changes: 129 additions & 0 deletions doc/ass-blend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
## ass 字幕渲染

以下是解决 ass字幕渲染时颜色存在偏差问题的备忘。

### 颜色混合原理

将要画上去的颜色称为“源颜色”,把原来的颜色称为“目标颜色”;
视频画面就是目标颜色,字幕就是源颜色。

定义如下:

```
源颜色 (Rs,Gs,Bs,As),源因子 (Sr,Sg,Sb,Sa)
目标颜色 (Rd,Gd,Bd,Ad),目标因子 (Dr,Dg,Db,Da)
颜色混合基础公式:
(Rs*Sr+Rd*Dr, Gs*Sg+Gd*Dg, Bs*Sb+Bd*Db, As*Sa+Ad*Da)
```

令:

```
Sr=Sg=Sb=Sa
Dr=Dg=Db=Da
```

则源公式简化为:

```
(Rs*Sa+Rd*Da, Gs*Sa+Gd*Da, Bs*Sa+Bd*Da, As*Sa+Ad*Da)
```

再令 `Da = 1-Sa` 可推导出:

`(Rs*Sa+Rd*(1-Sa), Gs*Sa+Gd**(1-Sa), Bs*Sa+Bd**(1-Sa), As*Sa+Ad**(1-Sa))`

可根据这个公式编写 ass layer 合成的逻辑:

```
static void draw_ass_rgba(unsigned char *src, int src_w, int src_h,
int src_stride, unsigned char *dst, size_t dst_stride,
int dst_x, int dst_y, uint32_t color)
{
const unsigned int sr = (color >> 24) & 0xff;
const unsigned int sg = (color >> 16) & 0xff;
const unsigned int sb = (color >> 8) & 0xff;
const unsigned int _sa = 0xff - (color & 0xff);
#define COLOR_BLEND(_sa,_sc,_dc) ((_sc * _sa + _dc * (65025 - _sa)) >> 16 & 0xFF)
for (int y = 0; y < src_h; y++) {
uint32_t *dstrow = (uint32_t *) dst;
for (int x = 0; x < src_w; x++) {
const uint32_t sa = _sa * src[x];
uint32_t dstpix = dstrow[x];
uint32_t dstr = dstpix & 0xFF;
uint32_t dstg = (dstpix >> 8) & 0xFF;
uint32_t dstb = (dstpix >> 16) & 0xFF;
uint32_t dsta = (dstpix >> 24) & 0xFF;
dstr = COLOR_BLEND(sa, sr, dstr);
dstg = COLOR_BLEND(sa, sg, dstg);
dstb = COLOR_BLEND(sa, sb, dstb);
dsta = COLOR_BLEND(sa, 255, dsta);
dstrow[x] = dstr | (dstg << 8) | (dstb << 16) | (dsta << 24);
}
dst += dst_stride;
src += src_stride;
}
#undef COLOR_BLEND
}
static void blend_single(FFSubtitleBuffer * frame, ASS_Image *img, int layer)
{
if (img->w == 0 || img->h == 0)
return;
//printf("blend %d rect:{%d,%d}{%d,%d}\n", layer, img->dst_x, img->dst_y, img->w, img->h);
unsigned char *dst = frame->data;
dst += img->dst_y * frame->stride + img->dst_x * 4;
draw_ass_rgba(img->bitmap, img->w, img->h, img->stride, dst, frame->stride, img->dst_x, img->dst_y, img->color);
}
static void blend(FFSubtitleBuffer * frame, ASS_Image *img)
{
int cnt = 0;
while (img) {
++cnt;
blend_single(frame, img, cnt);
img = img->next;
}
}
```

以上是 ass image 混合到一张大的 rgba bitmap 的过程。

### 渲染 rgba bitmap

字幕的渲染和视频是分开的,分别有一套纹理上传和渲染的过程,然后做混合。这是由于在集成 libass 之前字幕功能就已经实现了,通过 Core Graphic API 将 文本转成一张刚好装下内容的图片,而 ass 的渲染逻辑则是将多层透明通道的图层混合到一张和视频大小一样的大图上。

此处省去纹理上传的相关逻辑。接入 ass 后渲染总是不对,于是将渲染前的 rgba 保存成本地图片查看颜色是正常的,最终定位到是 OpenGl blend 方式的问题!



老版本的 OpenGL 不支持对每个颜色分量单独设置混合因子,而是所有分量统一使用一个因子,实际上使用的就是上面简化后的公式,
glBlendFunc 方法的第一个参数是上面公式的 Sa 参数,第二个参数是上面公式的 Da 参数。

OpenGL 里可用的常量:

```
GL_ZERO: 表示使用0.0作为因子,实际上相当于不使用这种颜色参与混合运算。
GL_ONE: 表示使用1.0作为因子,实际上相当于完全的使用了这种颜色参与混合运算。
GL_SRC_ALPHA:表示使用源颜色的alpha值来作为因子。
GL_DST_ALPHA:表示使用目标颜色的alpha值来作为因子。
GL_ONE_MINUS_SRC_ALPHA:表示用1.0减去源颜色的alpha值来作为因子。
GL_ONE_MINUS_DST_ALPHA:表示用1.0减去目标颜色的alpha值来作为因子。
```

解决 ass 字幕渲染问题,需要设置正确的混合模式:

glEnable(GL_BLEND);
//之前使用的是 GL_SRC_ALPHA,而不是 GL_ONE
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

改成 GL_ONE 之后,原本的 Core Graphic API 生成的图片仍旧正常显示。

## end

到此问题解决,你能想明白为什么 ass 字幕的图片需要使用 GL_ONE 这个源因子吗?
6 changes: 6 additions & 0 deletions examples/ios/IJKMediaDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
TARGETED_DEVICE_FAMILY = 1;
VALID_ARCHS = "arm64 x86_64";
WRAPPER_EXTENSION = app;
Expand Down Expand Up @@ -507,6 +510,9 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
TARGETED_DEVICE_FAMILY = 1;
VALID_ARCHS = "arm64 x86_64";
WRAPPER_EXTENSION = app;
Expand Down
4 changes: 2 additions & 2 deletions examples/ios/IJKMediaDemo/IJKMoviePlayerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ - (void)viewDidLoad
self.player.scalingMode = IJKMPMovieScalingModeAspectFit;
self.player.shouldAutoplay = YES;

IJKSDLSubtitlePreference p = self.player.view.subtitlePreference;
IJKSDLSubtitlePreference p = self.player.subtitlePreference;
p.color = 16776960;
self.player.view.subtitlePreference = p;
self.player.subtitlePreference = p;
self.view.autoresizesSubviews = YES;
[self.view addSubview:self.player.view];
[self.view addSubview:self.mediaControl];
Expand Down
6 changes: 3 additions & 3 deletions examples/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- IJKMediaPlayerKit (0.10.5)
- IJKMediaPlayerKit (0.11.0)

DEPENDENCIES:
- IJKMediaPlayerKit (from `../../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../../"

SPEC CHECKSUMS:
IJKMediaPlayerKit: 65b39f55bda0e03320d1fe72ac7824c99f230468
IJKMediaPlayerKit: b70eef8376bfc532e26524ae8c55112e5ae5821a

PODFILE CHECKSUM: cd296d63e0523ffeac3abedb895edb14934a2d48

COCOAPODS: 1.15.0
COCOAPODS: 1.15.2
6 changes: 0 additions & 6 deletions examples/macos/IJKMediaDemo/2e0fb226-d7c3-4672-a4bc.m3u8

This file was deleted.

Loading

0 comments on commit 9ea3715

Please sign in to comment.