HDR, או טווח דינמי גבוה, מספק טווח צבעים רחב יותר וניגודיות גדולה יותר בין הגוונים הבהירים ביותר של הלבן לבין הצללים הכהים ביותר. כך מתקבלת איכות וידאו שדומה יותר למה שהעין האנושית רואה.
אתם יכולים להגדיר הפעלה של סרטוני HDR באפליקציה כדי לצפות בתצוגה מקדימה של תוכן וידאו ב-HDR ולהפעיל אותו.
במאמר הזה אנחנו מניחים שכבר הוספתם לאפליקציה תמיכה בסיסית בהפעלת וידאו. לפרטים נוספים על הפעלה, עיינו במסמכי התיעוד של ExoPlayer.
דרישות מקדימות למכשיר
לא כל מכשירי Android תומכים בהפעלה של HDR. לפני שאתם מפעילים קטע וידאו ב-HDR באפליקציה, אתם צריכים לבדוק אם המכשיר עומד בדרישות הבאות:
- מטרגטת ל-Android מגרסה 7.0 ומעלה (שכבת API 24).
- יש לו מפענח שתומך ב-HDR וגישה למסך שתומך ב-HDR.
איך בודקים אם המכשיר תומך בהפעלה באיכות HDR
אפשר להשתמש ב-Display.getHdrCapabilities() כדי לשלוח שאילתה לגבי יכולות ה-HDR של המסך. השיטה מחזירה מידע על פרופילי ה-HDR הנתמכים וטווח הבהירות של המסך.
הקוד הבא בודק אם המכשיר תומך בהפעלה של HLG10. החל מ-Android 13, HLG10 הוא התקן המינימלי שיצרני המכשירים חייבים לתמוך בו אם המכשיר מסוגל להפעיל תוכן באיכות HDR:
Kotlin
// Check if display supports the HDR type val capabilities = display?.hdrCapabilities?.supportedHdrTypes ?: intArrayOf() if (!capabilities.contains(HDR_TYPE_HLG)) { throw RuntimeException("Display does not support desired HDR type"); }
Java
// Check if display supports the HDR type int[] list = getDisplay().getHdrCapabilities().getSupportedHdrTypes(); Listcapabilities = Arrays.stream(list).boxed().collect(Collectors.toList()); if (!capabilities.contains(HDR_TYPE_HLG)) { throw new RuntimeException("Display does not support desired HDR type"); }
הגדרת הפעלה של HDR באפליקציה
אם האפליקציה שלכם משתמשת ב-ExoPlayer, היא תומכת בהפעלה באיכות HDR כברירת מחדל. בקטע בדיקת התמיכה בהפעלת HDR מפורטים השלבים הבאים.
אם האפליקציה לא משתמשת ב-ExoPlayer, צריך להגדיר הפעלה של HDR באמצעות MediaCodec דרך SurfaceView.
הגדרת MediaCodec באמצעות SurfaceView
מגדירים תהליך הפעלה רגיל של MediaCodec באמצעות SurfaceView. כך אפשר להציג קטע וידאו ב-HDR בלי טיפול מיוחד בהפעלה של HDR:
-
MediaCodec: מפענח תוכן וידאו ב-HDR. -
SurfaceView: הצגת קטע וידאו ב-HDR.
הקוד הבא בודק אם הקודק תומך בפרופיל HDR, ואז מגדיר את MediaCodec באמצעות SurfaceView:
Kotlin
// Check if there's a codec that supports the specific HDR profile val list = MediaCodecList(MediaCodecList.REGULAR_CODECS) var format = MediaFormat() /* media format from the container */; format.setInteger(MediaFormat.KEY_PROFILE, MediaCodecInfo.CodecProfileLevel.AV1ProfileMain10) val codecName = list.findDecoderForFormat (format) ?: throw RuntimeException ("No codec supports the format") // Here is a standard MediaCodec playback flow val codec: MediaCodec = MediaCodec.createByCodecName(codecName); val surface: Surface = surfaceView.holder.surface val callback: MediaCodec.Callback = (object : MediaCodec.Callback() { override fun onInputBufferAvailable(codec: MediaCodec, index: Int) { queue.offer(index) } override fun onOutputBufferAvailable( codec: MediaCodec, index: Int, info: MediaCodec.BufferInfo ) { codec.releaseOutputBuffer(index, timestamp) } override fun onError(codec: MediaCodec, e: MediaCodec.CodecException) { // handle error } override fun onOutputFormatChanged( codec: MediaCodec, format: MediaFormat ) { // handle format change } }) codec.setCallback(callback) codec.configure(format, surface, crypto, 0 /* flags */) codec.start() while (/* until EOS */) { val index = queue.poll() val buffer = codec.getInputBuffer(index) buffer?.put(/* write bitstream */) codec.queueInputBuffer(index, offset, size, timestamp, flags) } codec.stop() codec.release()
Java
// Check if there's a codec that supports the specific HDR profile MediaCodecList list = new MediaCodecList(MediaCodecList.REGULAR_CODECS); MediaFormat format = /* media format from the container */; format.setInteger( MediaFormat.KEY_PROFILE, CodecProfileLevel.AV1ProfileMain10); String codecName = list.findDecoderForFormat(format); if (codecName == null) { throw new RuntimeException("No codec supports the format"); } // Below is a standard MediaCodec playback flow MediaCodec codec = MediaCodec.getCodecByName(codecName); Surface surface = surfaceView.getHolder().getSurface(); MediaCodec.Callback callback = new MediaCodec.Callback() { @Override void onInputBufferAvailable(MediaCodec codec, int index) { queue.offer(index); } @Override void onOutputBufferAvailable(MediaCodec codec, int index) { // release the buffer for render codec.releaseOutputBuffer(index, timestamp); } @Override void onOutputFormatChanged(MediaCodec codec, MediaFormat format) { // handle format change } @Override void onError(MediaCodec codec, MediaCodec.CodecException ex) { // handle error } }; codec.setCallback(callback); codec.configure(format, surface, crypto, 0 /* flags */); codec.start(); while (/* until EOS */) { int index = queue.poll(); ByteBuffer buffer = codec.getInputBuffer(index); buffer.put(/* write bitstream */); codec.queueInputBuffer(index, offset, size, timestamp, flags); } codec.stop(); codec.release();
להטמעות נוספות של MediaCodec באמצעות SurfaceView, אפשר לעיין בדוגמאות למצלמות Android.
משאבים
מידע נוסף על הפעלת HDR זמין במקורות המידע הבאים:
HDR
- צילום וידאו ב-HDR: איך להגדיר צילום וידאו ב-HDR באמצעות ממשקי ה-API של Camera2.
- דוגמה ל-Camera2Video ב-GitHub: אפליקציה פעילה עם פונקציונליות של צילום והפעלה ב-HDR.
מדיה
- מאמרי העזרה של Media API: מידע נוסף על ממשקי Media API.
- ExoPlayer: איך להגדיר את האפליקציה עם ספריית ExoPlayer.