마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 썸네일추출 API의 원리에 대한 궁금증

0 추천
안녕하세요.

오늘도 어김없이 궁금증이 있습니다.

다름이 아니라 안드로이드 썸네일 추출 API를 사용하면

동영상파일Path를 전달하면 API가 내부적으로 처리후에 썸네일 Bitmap을 리턴해주잖아요?

그런데 내부적으로 처리할때 동영상에 대한 썸네일 이미지를 추출하기 위해서

동영상의 헤더정보를 필요로 하는지 궁금합니다.

내부적으로 썸네일을 추출할때 동영상의 헤더정보를 가지고 어떤 작업을 할까요?

 

한줄요약 : 안드로이드API에서 썸네일을 추출하는 작업을 할때 내부적으로 동영상파일의 헤더정보를 필요로 하나?

입니다~!
갸아악 (21,260 포인트) 님이 2014년 1월 9일 질문

1개의 답변

+1 추천
 
채택된 답변

SDK에 포함되어 있는 ThumbnailUtils 의 createVideoThumbnail  소스입니다.

제가 미디어쪽은 문외한이라 잘 모르겠는데

metadata 와 헤더정보가 같은 거라면 헤더정보를 이용하는게 맞네요

 

/**
* 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;
}

 

 

Gradler (109,780 포인트) 님이 2014년 1월 9일 답변
갸아악님이 2014년 1월 10일 채택됨
정말로 감사드립니다.
많은 도움 되었습니다.
좋은 하루되세요 ㅎㅎ
...