FFMPeg异常setDataSource失败:status = 0xFFFFFFFF

时间:2015-07-13 12:41:15

标签: exception ffmpeg

我有175 mp4文件。当我将文件从索引0处理到索引65(或66)时,我得到异常:

java.lang.IllegalArgumentException: setDataSource failed: status = 0xFFFFFFFF
at wseemann.media.FFmpegMediaMetadataRetriever.setDataSource(Native Method)
at com.jni.utils.Mp4ParserUsingFFMpeg.createThumbnail(Mp4ParserUsingFFMpeg.java:518)
at com.example.readmdtfile.activity.MainActivity$createMp4Async.createThumbnail(MainActivity.java:71)
at com.example.readmdtfile.activity.MainActivity$createMp4Async.doInBackground(MainActivity.java:55)
at com.example.readmdtfile.activity.MainActivity$createMp4Async.doInBackground(MainActivity.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)

如果我从索引65(或附近)运行进程,则处理文件65成功。但有时它仍然有例外 这是我正在使用的代码:

public static Bitmap createThumbnail (String videoPath) {
    FFmpegMediaMetadataRetriever retriever = new  FFmpegMediaMetadataRetriever();
    Bitmap bitmap = null;
    try {
        retriever.setDataSource(videoPath); //file's path
        String key;
        String value;
        for (int i = 0; i < MetadataKey.METADATA_KEYS.length; i++) {
            key = MetadataKey.METADATA_KEYS[i];
            value = retriever.extractMetadata(key);
            if (value != null) {
                // metadata.add(new Metadata(key, value));
                Log.i(TAG, "Key: " + key + " Value: " + value);
            }
        }

        bitmap = retriever.getFrameAtTime();

        if (bitmap != null) {
            Log.d(TAG, "Extracted frame");
            Bitmap b2 = retriever.getFrameAtTime(4000000,
                    FFmpegMediaMetadataRetriever.OPTION_CLOSEST_SYNC);
            if (b2 != null) {
                bitmap = b2;
            }
        } else {
            Log.d(TAG, "Failed to extract frame");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        retriever.release();
    }

    return bitmap;
}

https://github.com/wseemann/FFmpegMediaMetadataRetriever/issues/59

请帮帮我。

3 个答案:

答案 0 :(得分:1)

错误很简单,IllegalArgumentException表示视频URI无效,如果发生这种情况则会引发异常。在尝试将URI用于FFmpegMediaMetadataRetriever之前验证URI是否有效。

答案 1 :(得分:0)

你只需要给setDataSource一个字符串,将你的路径或网址保存在这样的字符串中:

String url;
mmr = new FFmpegMediaMetadataRetriever();
url = "http://www.stephaniequinn.com/Music/Commercial%20DEMO%20-%2009.mp3";
mmr.setDataSource(url, new HashMap<String, String>());

或:

mmr = new FFmpegMediaMetadataRetriever();
string s="path"
mmr.setDataSource(path);

答案 2 :(得分:0)

错误很简单,RuntimeException表示视频URI无效。在尝试将其与FFmpegMediaMetadataRetriever一起使用之前,请验证格式为.mp4的有效视频URI。

ImageView thumbnail1 =(ImageView)findViewById(R.id.video1); thumbnail1.setImageBitmap(retriveVideoFrameFromVideo(“ http://techslides.com/demos/sample-videos/small.mp4”)));

公共位图retriveVideoFrameFromVideo(String videoPath){

    Bitmap bitmap = null;
    MediaMetadataRetriever mediaMetadataRetriever = null;
    try {
        mediaMetadataRetriever = new MediaMetadataRetriever();
        if (Build.VERSION.SDK_INT >= 14)
            mediaMetadataRetriever.setDataSource(videoPath, new HashMap<String, String>());
        else
            mediaMetadataRetriever.setDataSource(videoPath);
        //   mediaMetadataRetriever.setDataSource(videoPath);
        bitmap = mediaMetadataRetriever.getFrameAtTime(1, MediaMetadataRetriever.OPTION_CLOSEST);
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    } finally {
        if (mediaMetadataRetriever != null) {
            mediaMetadataRetriever.release();
        }
    }
    return bitmap;
}