Skip to content

Commit

Permalink
fix android mediacodec encoding align (#8121)
Browse files Browse the repository at this point in the history
* update ffmpeg, mediacodec encode align 64
* more d3d11 decode availablity check
* remove unused mediacodec info

Signed-off-by: 21pages <sunboeasy@gmail.com>
  • Loading branch information
21pages committed May 22, 2024
1 parent 91f07b4 commit 49b0630
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ class MainActivity : FlutterActivity() {
w = dm.widthPixels
h = dm.heightPixels
}
val align = 64
w = (w + align - 1) / align * align
h = (h + align - 1) / align * align
codecs.forEach { codec ->
val codecObject = JSONObject()
codecObject.put("name", codec.name)
Expand All @@ -281,21 +284,23 @@ class MainActivity : FlutterActivity() {
hw = true
}
}
if (hw != true) {
return@forEach
}
codecObject.put("hw", hw)
var mime_type = ""
codec.supportedTypes.forEach { type ->
if (listOf("video/avc", "video/hevc", "video/x-vnd.on2.vp8", "video/x-vnd.on2.vp9", "video/av01").contains(type)) {
if (listOf("video/avc", "video/hevc").contains(type)) { // "video/x-vnd.on2.vp8", "video/x-vnd.on2.vp9", "video/av01"
mime_type = type;
}
}
if (mime_type.isNotEmpty()) {
codecObject.put("mime_type", mime_type)
val caps = codec.getCapabilitiesForType(mime_type)
var usable = true;
if (codec.isEncoder) {
// Encoder‘s max_height and max_width are interchangeable
if (!caps.videoCapabilities.isSizeSupported(w,h) && !caps.videoCapabilities.isSizeSupported(h,w)) {
usable = false
return@forEach
}
}
codecObject.put("min_width", caps.videoCapabilities.supportedWidths.lower)
Expand All @@ -307,7 +312,7 @@ class MainActivity : FlutterActivity() {
val nv12 = caps.colorFormats.contains(COLOR_FormatYUV420SemiPlanar)
codecObject.put("nv12", nv12)
if (!(nv12 || surface)) {
usable = false
return@forEach
}
codecObject.put("min_bitrate", caps.videoCapabilities.bitrateRange.lower / 1000)
codecObject.put("max_bitrate", caps.videoCapabilities.bitrateRange.upper / 1000)
Expand All @@ -316,9 +321,10 @@ class MainActivity : FlutterActivity() {
codecObject.put("low_latency", caps.isFeatureSupported(MediaCodecInfo.CodecCapabilities.FEATURE_LowLatency))
}
}
if (usable) {
codecArray.put(codecObject)
if (!codec.isEncoder) {
return@forEach
}
codecArray.put(codecObject)
}
}
val result = JSONObject()
Expand Down
4 changes: 2 additions & 2 deletions libs/scrap/src/android/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ pub struct MediaCodecInfo {
#[derive(Debug, Deserialize, Clone)]
pub struct MediaCodecInfos {
pub version: usize,
pub w: usize,
pub h: usize,
pub w: usize, // aligned
pub h: usize, // aligned
pub codecs: Vec<MediaCodecInfo>,
}

Expand Down

0 comments on commit 49b0630

Please sign in to comment.