MPVPlayer: Support for software decoding + clean up
This commit is contained in:
parent
0baef5ec2e
commit
64b86f2b40
5 changed files with 40 additions and 27 deletions
|
@ -1,14 +1,11 @@
|
|||
#vo=mediacodec_embed
|
||||
# hwdec: try to use hardware decoding
|
||||
hwdec=mediacodec-copy
|
||||
hwdec-codecs="h264,hevc,mpeg4,mpeg2video,vp8,vp9,av1"
|
||||
gpu-dumb-mode=auto
|
||||
# tls: allow self signed certificate
|
||||
tls-verify=no
|
||||
tls-ca-file=""
|
||||
# demuxer: limit cache to 32 MiB, the default is too high for mobile devices
|
||||
demuxer-max-bytes=32MiB
|
||||
demuxer-max-back-bytes=32MiB
|
||||
# sub: scale subtitles with video
|
||||
sub-scale-with-window=no
|
||||
sub-use-margins=no
|
||||
### hwdec: try to use hardware decoding
|
||||
# hwdec=mediacodec-copy
|
||||
# hwdec-codecs="h264,hevc,mpeg4,mpeg2video,vp8,vp9,av1"
|
||||
|
||||
### tls: allow self signed certificate
|
||||
# tls-verify=no
|
||||
# tls-ca-file=""
|
||||
|
||||
### sub: scale subtitles with video
|
||||
# sub-scale-with-window=no
|
||||
# sub-use-margins=no
|
||||
|
|
BIN
app/src/main/assets/subfont.ttf
Normal file
BIN
app/src/main/assets/subfont.ttf
Normal file
Binary file not shown.
|
@ -40,7 +40,8 @@ import java.util.concurrent.CopyOnWriteArraySet
|
|||
class MPVPlayer(
|
||||
context: Context,
|
||||
requestAudioFocus: Boolean,
|
||||
preferredLanguages: Map<String, String>
|
||||
preferredLanguages: Map<String, String>,
|
||||
disableHardwareDecoding: Boolean
|
||||
) : BasePlayer(), MPVLib.EventObserver, AudioManager.OnAudioFocusChangeListener {
|
||||
|
||||
private val audioManager: AudioManager by lazy { context.getSystemService()!! }
|
||||
|
@ -50,13 +51,11 @@ class MPVPlayer(
|
|||
|
||||
init {
|
||||
require(context is Application)
|
||||
@Suppress("DEPRECATION")
|
||||
val mpvDir = File(context.getExternalFilesDir(null) ?: context.filesDir, "mpv")
|
||||
if (!mpvDir.exists()) {
|
||||
mpvDir.mkdirs()
|
||||
}
|
||||
// https://github.com/mpv-android/mpv-android/commit/12d4d78
|
||||
arrayOf("mpv.conf", "subfont.ttf"/*, "cacert.pem"*/).forEach { fileName ->
|
||||
arrayOf("mpv.conf", "subfont.ttf").forEach { fileName ->
|
||||
val file = File(mpvDir, fileName)
|
||||
Log.i("mpv", "File ${file.absolutePath}")
|
||||
if (!file.exists()) {
|
||||
|
@ -64,24 +63,43 @@ class MPVPlayer(
|
|||
}
|
||||
}
|
||||
MPVLib.create(context)
|
||||
MPVLib.setOptionString("config", "yes")
|
||||
|
||||
// General
|
||||
MPVLib.setOptionString("config-dir", mpvDir.path)
|
||||
// vo: set display fps as reported by android
|
||||
MPVLib.setOptionString("vo", "gpu")
|
||||
MPVLib.setOptionString("gpu-context", "android")
|
||||
MPVLib.setOptionString("ao", "audiotrack,opensles")
|
||||
|
||||
MPVLib.init()
|
||||
// Hardware video decoding
|
||||
if (disableHardwareDecoding) {
|
||||
MPVLib.setOptionString("hwdec", "no")
|
||||
} else {
|
||||
MPVLib.setOptionString("hwdec", "mediacodec-copy")
|
||||
}
|
||||
MPVLib.setOptionString("hwdec-codecs", "h264,hevc,mpeg4,mpeg2video,vp8,vp9,av1")
|
||||
|
||||
// hardcoded options
|
||||
// TLS
|
||||
MPVLib.setOptionString("tls-verify", "no")
|
||||
|
||||
// Cache
|
||||
MPVLib.setOptionString("cache", "yes")
|
||||
MPVLib.setOptionString("cache-pause-initial", "yes")
|
||||
MPVLib.setOptionString("demuxer-max-bytes", "32MiB")
|
||||
MPVLib.setOptionString("demuxer-max-back-bytes", "32MiB")
|
||||
|
||||
// Subs
|
||||
MPVLib.setOptionString("sub-scale-with-window", "no")
|
||||
MPVLib.setOptionString("sub-use-margins", "no")
|
||||
|
||||
// Other options
|
||||
MPVLib.setOptionString("force-window", "no")
|
||||
MPVLib.setOptionString("keep-open", "always")
|
||||
MPVLib.setOptionString("save-position-on-quit", "no")
|
||||
MPVLib.setOptionString("sub-font-provider", "none")
|
||||
MPVLib.setOptionString("ytdl", "no")
|
||||
|
||||
MPVLib.init()
|
||||
|
||||
for (preferredLanguage in preferredLanguages) {
|
||||
when (preferredLanguage.key) {
|
||||
TrackType.AUDIO -> {
|
||||
|
@ -1281,7 +1299,6 @@ class MPVPlayer(
|
|||
COMMAND_PREPARE_STOP,
|
||||
COMMAND_SET_SPEED_AND_PITCH,
|
||||
COMMAND_GET_CURRENT_MEDIA_ITEM,
|
||||
//COMMAND_GET_MEDIA_ITEMS,
|
||||
COMMAND_GET_MEDIA_ITEMS_METADATA,
|
||||
COMMAND_CHANGE_MEDIA_ITEMS,
|
||||
COMMAND_SET_VIDEO_SURFACE,
|
||||
|
@ -1455,8 +1472,6 @@ class MPVPlayer(
|
|||
return Triple(tracks, trackGroupArray, trackSelectionArray)
|
||||
}
|
||||
|
||||
const val PLAYER_NAME = "MPV Player"
|
||||
|
||||
/**
|
||||
* Merges multiple [subtitleSources] into a single [videoSource]
|
||||
*/
|
||||
|
|
|
@ -59,7 +59,7 @@ constructor(
|
|||
|
||||
if (useMpv) {
|
||||
val preferredLanguages = mapOf(TrackType.AUDIO to preferredAudioLanguage, TrackType.SUBTITLE to preferredSubtitleLanguage)
|
||||
player = MPVPlayer(application, false, preferredLanguages)
|
||||
player = MPVPlayer(application, false, preferredLanguages, sp.getBoolean("mpv_disable_hwdec", false))
|
||||
} else {
|
||||
val renderersFactory =
|
||||
DefaultRenderersFactory(application).setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON)
|
||||
|
@ -101,7 +101,7 @@ constructor(
|
|||
|
||||
when (player) {
|
||||
is MPVPlayer -> {
|
||||
player.setMediaItem(mediaItems[0])
|
||||
player.setMediaItems(mediaItems)
|
||||
player.prepare()
|
||||
player.play()
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
app:title="MPV Player"
|
||||
app:summary="Use the experimental MPV Player to play videos. MPV has support for more video, audio and subtitle codecs."/>
|
||||
<SwitchPreference
|
||||
app:key="mpv_disable_hwdec"
|
||||
app:dependency="mpv_player"
|
||||
app:title="Force software decoding"
|
||||
app:summary="Disable hardware decoding and use software decoding. Can be useful if hardware decoding gives weird artifacts."/>
|
||||
|
|
Loading…
Reference in a new issue