Search in sources :

Example 96 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project android_frameworks_base by ResurrectionRemix.

the class CodecTest method getThumbnail.

//Test for mediaMeta Data Thumbnail
public static boolean getThumbnail(String filePath, String goldenPath) {
    Log.v(TAG, "getThumbnail - " + filePath);
    int goldenHeight = 0;
    int goldenWidth = 0;
    int outputWidth = 0;
    int outputHeight = 0;
    //This test is only for the short media file
    try {
        BitmapFactory mBitmapFactory = new BitmapFactory();
        MediaMetadataRetriever mMediaMetadataRetriever = new MediaMetadataRetriever();
        try {
            mMediaMetadataRetriever.setDataSource(filePath);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        Bitmap outThumbnail = mMediaMetadataRetriever.getFrameAtTime(-1);
        //Verify the thumbnail
        Bitmap goldenBitmap = mBitmapFactory.decodeFile(goldenPath);
        outputWidth = outThumbnail.getWidth();
        outputHeight = outThumbnail.getHeight();
        goldenHeight = goldenBitmap.getHeight();
        goldenWidth = goldenBitmap.getWidth();
        //check the image dimension
        if ((outputWidth != goldenWidth) || (outputHeight != goldenHeight))
            return false;
        // Check half line of pixel
        int x = goldenHeight / 2;
        for (int j = 1; j < goldenWidth / 2; j++) {
            if (goldenBitmap.getPixel(x, j) != outThumbnail.getPixel(x, j)) {
                Log.v(TAG, "pixel = " + goldenBitmap.getPixel(x, j));
                return false;
            }
        }
    } catch (Exception e) {
        Log.v(TAG, e.toString());
        return false;
    }
    return true;
}
Also used : Bitmap(android.graphics.Bitmap) MediaMetadataRetriever(android.media.MediaMetadataRetriever) BitmapFactory(android.graphics.BitmapFactory) IOException(java.io.IOException)

Example 97 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project android_frameworks_base by ResurrectionRemix.

the class MediaMetadataTest method validateMetatData.

private static void validateMetatData(int fileIndex, String[][] meta_data_file) {
    Log.v(TAG, "filePath = " + meta_data_file[fileIndex][0]);
    if ((meta_data_file[fileIndex][0].endsWith("wma") && !MediaProfileReader.getWMAEnable()) || (meta_data_file[fileIndex][0].endsWith("wmv") && !MediaProfileReader.getWMVEnable())) {
        return;
    }
    String value = null;
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(meta_data_file[fileIndex][0]);
    } catch (Exception e) {
        Log.v(TAG, "Failed: " + meta_data_file[fileIndex][0] + " " + e.toString());
        //Set the test case failure whenever it failed to setDataSource
        assertTrue("Failed to setDataSource ", false);
    }
    //METADATA_KEY_CD_TRACK_NUMBER should return the TCRK value
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER);
    Log.v(TAG, "CD_TRACK_NUMBER : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.CD_TRACK.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
    Log.v(TAG, "Album : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.ALBUM.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
    Log.v(TAG, "Artist : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.ARTIST.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_AUTHOR);
    Log.v(TAG, "Author : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.AUTHOR.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER);
    Log.v(TAG, "Composer : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.COMPOSER.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE);
    Log.v(TAG, "Date : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.DATE.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);
    Log.v(TAG, "Genre : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.GENRE.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
    Log.v(TAG, "Title : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.TITLE.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
    Log.v(TAG, "Year : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.YEAR.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
    Log.v(TAG, "Expected = " + meta_data_file[fileIndex][meta.DURATION.ordinal()] + "reult = " + value);
    // Only require that the returned duration is within 100ms of the expected
    // one as PV and stagefright differ slightly in their implementation.
    assertTrue(TAG, Math.abs(Integer.parseInt(meta_data_file[fileIndex][meta.DURATION.ordinal()]) - Integer.parseInt(value)) < 100);
    //METADATA_KEY_NUM_TRACKS should return the total number of tracks in the media
    //include the video and audio
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS);
    Log.v(TAG, "Track : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.NUM_TRACKS.ordinal()], value);
    value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_WRITER);
    Log.v(TAG, "Writer : " + value);
    assertEquals(TAG, meta_data_file[fileIndex][meta.WRITER.ordinal()], value);
    retriever.release();
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 98 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project react-native-android-video-editor by RZulfikri.

the class VideoTrim method getVideoInfo.

//    public void setMaxTrimDuration(int maxTrimDuration){
//        this.maxTrimDuration = maxTrimDuration;
//    }
/**
     * Function to get Video Detail, used to get video Duration and Set Video Player Max Duration
     */
private void getVideoInfo(String source) {
    MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
    mediaMetadataRetriever.setDataSource(source);
    duration = Integer.parseInt(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
    if (duration / 60000 >= 10) {
        maxDuration = 600000;
        // videoPlayerControl.setEndPos(maxDuration);
        WritableMap event = Arguments.createMap();
        event.putInt(Events.END_POS, maxDuration);
        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_END_POS.toString(), event);
    } else {
        maxDuration = duration;
        rangeSeekEndPos = maxDuration;
        // videoPlayerControl.setEndPos(maxDuration);
        WritableMap event = Arguments.createMap();
        event.putInt(Events.END_POS, maxDuration);
        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_END_POS.toString(), event);
    }
    //         Log.e("DEBUG", " "+duration+" "+maxDuration+" "+((minTrimDuration * 100f) / (float)maxDuration));
    seekbar.setRangeMin((minTrimDuration * 100f) / (float) maxDuration);
    mediaMetadataRetriever.release();
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 99 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project react-native-android-video-editor by RZulfikri.

the class ImageTextureRenderer method setImage.

//    public void setImage(){
public void setImage(String path, int position, int filterCode) {
    //         Log.e("DEBUG", "MASUK IMAGE");
    MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
    mediaMetadataRetriever.setDataSource(path);
    photo = mediaMetadataRetriever.getFrameAtTime(position * 1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
    photoWidth = photo.getWidth();
    photoHeight = photo.getHeight();
    mediaMetadataRetriever.release();
    mediaMetadataRetriever = null;
    switch(filterCode) {
        case 0:
            fragmentShaderCode = new NoEffect();
            break;
        case 1:
            fragmentShaderCode = new BlackAndWhiteEffect();
            break;
        case 2:
            fragmentShaderCode = new BrightnessEffect(0.5f);
            break;
        case 3:
            fragmentShaderCode = new ContrastEffect(0.5f);
            break;
        case 4:
            fragmentShaderCode = new CrossProcessEffect();
            break;
        case 5:
            fragmentShaderCode = new DocumentaryEffect(photoWidth, photoHeight);
            break;
        case 6:
            fragmentShaderCode = new DuotoneEffect(Color.CYAN, Color.BLUE);
            break;
        case 7:
            fragmentShaderCode = new FillLightEffect(0.5f);
            break;
        case 8:
            fragmentShaderCode = new GammaEffect(1.0f);
            break;
        case 9:
            fragmentShaderCode = new GreyScaleEffect();
            break;
        case 10:
            fragmentShaderCode = new HueEffect(90f);
            break;
        case 11:
            fragmentShaderCode = new InvertColorsEffect();
            break;
        case 12:
            fragmentShaderCode = new LamoishEffect(photoWidth, photoHeight);
            break;
        case 13:
            fragmentShaderCode = new PosterizeEffect();
            break;
        case 14:
            fragmentShaderCode = new SaturationEffect(0.1f);
            break;
        case 15:
            fragmentShaderCode = new SepiaEffect();
            break;
        case 16:
            fragmentShaderCode = new SharpnessEffect(0.5f, photoWidth, photoHeight);
            break;
        case 17:
            fragmentShaderCode = new TemperatureEffect(0.5f);
            break;
        case 18:
            fragmentShaderCode = new TintEffect(Color.BLUE);
            break;
        case 19:
            fragmentShaderCode = new VignetteEffect(0.5f, photoWidth, photoHeight);
            break;
        default:
            fragmentShaderCode = new NoEffect();
            break;
    }
}
Also used : HueEffect(rahmatzulfikri.com.androidvideoedit.Effect.HueEffect) CrossProcessEffect(rahmatzulfikri.com.androidvideoedit.Effect.CrossProcessEffect) LamoishEffect(rahmatzulfikri.com.androidvideoedit.Effect.LamoishEffect) TemperatureEffect(rahmatzulfikri.com.androidvideoedit.Effect.TemperatureEffect) InvertColorsEffect(rahmatzulfikri.com.androidvideoedit.Effect.InvertColorsEffect) SaturationEffect(rahmatzulfikri.com.androidvideoedit.Effect.SaturationEffect) TintEffect(rahmatzulfikri.com.androidvideoedit.Effect.TintEffect) SharpnessEffect(rahmatzulfikri.com.androidvideoedit.Effect.SharpnessEffect) VignetteEffect(rahmatzulfikri.com.androidvideoedit.Effect.VignetteEffect) NoEffect(rahmatzulfikri.com.androidvideoedit.Effect.NoEffect) ContrastEffect(rahmatzulfikri.com.androidvideoedit.Effect.ContrastEffect) DocumentaryEffect(rahmatzulfikri.com.androidvideoedit.Effect.DocumentaryEffect) FillLightEffect(rahmatzulfikri.com.androidvideoedit.Effect.FillLightEffect) GammaEffect(rahmatzulfikri.com.androidvideoedit.Effect.GammaEffect) SepiaEffect(rahmatzulfikri.com.androidvideoedit.Effect.SepiaEffect) MediaMetadataRetriever(android.media.MediaMetadataRetriever) BrightnessEffect(rahmatzulfikri.com.androidvideoedit.Effect.BrightnessEffect) DuotoneEffect(rahmatzulfikri.com.androidvideoedit.Effect.DuotoneEffect) BlackAndWhiteEffect(rahmatzulfikri.com.androidvideoedit.Effect.BlackAndWhiteEffect) GreyScaleEffect(rahmatzulfikri.com.androidvideoedit.Effect.GreyScaleEffect) PosterizeEffect(rahmatzulfikri.com.androidvideoedit.Effect.PosterizeEffect)

Example 100 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project android_frameworks_base by crdroidandroid.

the class ThumbnailUtils method createVideoThumbnail.

/**
     * Create a video thumbnail for a video. May return null if the video is
     * corrupt or the format is not supported.
     *
     * @param filePath the path of video file
     * @param kind could be MINI_KIND or MICRO_KIND
     */
public static Bitmap createVideoThumbnail(String filePath, int kind) {
    Bitmap bitmap = null;
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(filePath);
        bitmap = retriever.getFrameAtTime(-1);
    } catch (IllegalArgumentException ex) {
    // Assume this is a corrupt video file
    } catch (RuntimeException ex) {
    // Assume this is a corrupt video file.
    } finally {
        try {
            retriever.release();
        } catch (RuntimeException ex) {
        // Ignore failures while cleaning up.
        }
    }
    if (bitmap == null)
        return null;
    if (kind == Images.Thumbnails.MINI_KIND) {
        // Scale down the bitmap if it's too large.
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int max = Math.max(width, height);
        if (max > 512) {
            float scale = 512f / max;
            int w = Math.round(scale * width);
            int h = Math.round(scale * height);
            bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
        }
    } else if (kind == Images.Thumbnails.MICRO_KIND) {
        bitmap = extractThumbnail(bitmap, TARGET_SIZE_MICRO_THUMBNAIL, TARGET_SIZE_MICRO_THUMBNAIL, OPTIONS_RECYCLE_INPUT);
    }
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Aggregations

MediaMetadataRetriever (android.media.MediaMetadataRetriever)105 Bitmap (android.graphics.Bitmap)40 FileOutputStream (java.io.FileOutputStream)15 IOException (java.io.IOException)15 BitmapFactory (android.graphics.BitmapFactory)7 TargetApi (android.annotation.TargetApi)5 File (java.io.File)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2 MediaItem (android.media.videoeditor.MediaItem)2 WritableMap (com.facebook.react.bridge.WritableMap)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 SuppressLint (android.annotation.SuppressLint)1 Notification (android.app.Notification)1 PendingIntent (android.app.PendingIntent)1 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1