Search in sources :

Example 71 with MediaMetadataRetriever

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

the class VideoEditorImpl method generateProjectThumbnail.

/*
     * Generate the project thumbnail
     */
private void generateProjectThumbnail() {
    /*
         * If a thumbnail already exists, then delete it first
         */
    if ((new File(mProjectPath + "/" + THUMBNAIL_FILENAME)).exists()) {
        (new File(mProjectPath + "/" + THUMBNAIL_FILENAME)).delete();
    }
    /*
         * Generate a new thumbnail for the project from first media Item
         */
    if (mMediaItems.size() > 0) {
        MediaItem mI = mMediaItems.get(0);
        /*
             * Keep aspect ratio of the image
             */
        int height = 480;
        int width = mI.getWidth() * height / mI.getHeight();
        Bitmap projectBitmap = null;
        String filename = mI.getFilename();
        if (mI instanceof MediaVideoItem) {
            MediaMetadataRetriever retriever = new MediaMetadataRetriever();
            retriever.setDataSource(filename);
            Bitmap bitmap = retriever.getFrameAtTime();
            retriever.release();
            retriever = null;
            if (bitmap == null) {
                String msg = "Thumbnail extraction from " + filename + " failed";
                throw new IllegalArgumentException(msg);
            }
            // Resize the thumbnail to the target size
            projectBitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
        } else {
            try {
                projectBitmap = mI.getThumbnail(width, height, 500);
            } catch (IllegalArgumentException e) {
                String msg = "Project thumbnail extraction from " + filename + " failed";
                throw new IllegalArgumentException(msg);
            } catch (IOException e) {
                String msg = "IO Error creating project thumbnail";
                throw new IllegalArgumentException(msg);
            }
        }
        try {
            FileOutputStream stream = new FileOutputStream(mProjectPath + "/" + THUMBNAIL_FILENAME);
            projectBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            stream.flush();
            stream.close();
        } catch (IOException e) {
            throw new IllegalArgumentException("Error creating project thumbnail");
        } finally {
            projectBitmap.recycle();
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) MediaItem(android.media.videoeditor.MediaItem) MediaMetadataRetriever(android.media.MediaMetadataRetriever) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 72 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project platform_frameworks_base by android.

the class EffectsVideoCapture method verify.

// Verify result code, result data, and the duration.
private void verify(CameraEffectsRecordingSample activity, Uri uri) throws Exception {
    assertNotNull(uri);
    // Verify the video file
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    retriever.setDataSource(activity, uri);
    String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
    assertNotNull(duration);
    int durationValue = Integer.parseInt(duration);
    Log.v(TAG, "Video duration is " + durationValue);
    assertTrue(durationValue > 0);
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 73 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project platform_frameworks_base by android.

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 74 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project platform_frameworks_base by android.

the class MediaRecorderTest method validateMetadata.

private boolean validateMetadata(String filePath, int captureRate) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    retriever.setDataSource(filePath);
    // verify capture rate meta key is present and correct
    String captureFps = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CAPTURE_FRAMERATE);
    if (captureFps == null) {
        Log.d(TAG, "METADATA_KEY_CAPTURE_FRAMERATE is missing");
        return false;
    }
    if (Math.abs(Float.parseFloat(captureFps) - captureRate) > 0.001) {
        Log.d(TAG, "METADATA_KEY_CAPTURE_FRAMERATE is incorrect: " + captureFps + "vs. " + captureRate);
        return false;
    }
    // verify other meta keys here if necessary
    return true;
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 75 with MediaMetadataRetriever

use of android.media.MediaMetadataRetriever in project platform_frameworks_base by android.

the class MediaMetadataRetrieverTest method testThumbnailCapture.

// Test frame capture
@LargeTest
public static void testThumbnailCapture() throws Exception {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    boolean supportWMA = MediaProfileReader.getWMAEnable();
    boolean supportWMV = MediaProfileReader.getWMVEnable();
    boolean hasFailed = false;
    Log.v(TAG, "Thumbnail processing starts");
    long startedAt = System.currentTimeMillis();
    for (int i = 0, n = MediaNames.THUMBNAIL_METADATA_TEST_FILES.length; i < n; ++i) {
        try {
            Log.v(TAG, "File " + i + ": " + MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
            if ((MediaNames.THUMBNAIL_METADATA_TEST_FILES[i].endsWith(".wma") && !supportWMA) || (MediaNames.THUMBNAIL_METADATA_TEST_FILES[i].endsWith(".wmv") && !supportWMV)) {
                Log.v(TAG, "windows media is not supported and thus we will skip the test for this file");
                continue;
            }
            retriever.setDataSource(MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
            Bitmap bitmap = retriever.getFrameAtTime(-1);
            assertTrue(bitmap != null);
            try {
                java.io.OutputStream stream = new FileOutputStream(MediaNames.THUMBNAIL_METADATA_TEST_FILES[i] + ".jpg");
                bitmap.compress(Bitmap.CompressFormat.JPEG, 75, stream);
                stream.close();
            } catch (Exception e) {
                Log.e(TAG, "Fails to convert the bitmap to a JPEG file for " + MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
                hasFailed = true;
                Log.e(TAG, e.toString());
            }
        } catch (Exception e) {
            Log.e(TAG, "Fails to setDataSource for file " + MediaNames.THUMBNAIL_METADATA_TEST_FILES[i]);
            hasFailed = true;
        }
        // Don't be evil
        Thread.yield();
    }
    long endedAt = System.currentTimeMillis();
    retriever.release();
    assertTrue(!hasFailed);
    Log.v(TAG, "Average processing time per thumbnail: " + (endedAt - startedAt) / MediaNames.THUMBNAIL_METADATA_TEST_FILES.length + " ms");
}
Also used : Bitmap(android.graphics.Bitmap) MediaMetadataRetriever(android.media.MediaMetadataRetriever) FileOutputStream(java.io.FileOutputStream)

Aggregations

MediaMetadataRetriever (android.media.MediaMetadataRetriever)106 Bitmap (android.graphics.Bitmap)40 IOException (java.io.IOException)16 FileOutputStream (java.io.FileOutputStream)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