首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用AndroidSequenceEncoder时收到"No frames“

使用AndroidSequenceEncoder时收到"No frames“
EN

Stack Overflow用户
提问于 2017-12-01 15:10:24
回答 1查看 204关注 0票数 2

我正在尝试使用AndroidSequenceEncoder创建一个视频幻灯片。为此,我有一个方法可以检索位图的ArrayList和表示视频文件名的字符串。下面是我的方法的代码:

代码语言:javascript
复制
public class ImageToVideo
{
    //used to input frames (images) into the video file
    private AndroidSequenceEncoder ase;
    //Arraylist containing the frames to input
    private ArrayList<Bitmap> bi;
    //temporary variable used for AsyncTask below
    private Bitmap image;
    //This method is called until main code can be written to retrieve the proper length of the audio file
    public AndroidSequenceEncoder videoEncode(final ArrayList<Bitmap> images, String filename) throws  IOException
    {
        ase = AndroidSequenceEncoder.createSequenceEncoder(new File(filename), 3);
        bi = images;
        Log.d("SEQUENCEENCODER", "SequenceEncoder created");
        //outer for-loop; goes through each image individually
        for(int i = 0; i < images.size(); i++)
        {
            Log.d("SEQUENCEENCODER", "Retrieving image " + i + " of " + (images.size() - 1));
        //inner for-loop; adds the given image a number of times determined by how long each image is on-screen
        //since encoder's fps is currently set to 3, this loops once for each second the picture should be on-screen times 3
        for(int j = 0; j < 3; j++)
        {
            Log.d("SEQUENCEENCODER", "Encoding image " + i + ", " + (j+1) + " of " + 3);
            image = bi.get((i));
            //used because of error "Choreographer: Skipped ~90 frames! The application may be doing too much work on its main thread"
            AsyncTask.execute(new Runnable()
            {
                @Override
                public void run()
                {
                    try
                    {
                        ase.encodeImage(image);
                    }
                    catch(IOException e)
                    {
                        e.printStackTrace();
                    }
                }
            });
        }
    }
    ase.finish();
    return ase;
}

AndroidSequenceEncoder的fps设置为3作为临时值;当我进一步处理代码时,我希望此方法也获取视频的长度,以便该方法根据每个图像在屏幕上显示的时间长度来确定fps,因为它们都有相等的时间。当对4个图像运行此方法时,我得到以下消息

代码语言:javascript
复制
D/SEQUENCEENCODER: SequenceEncoder created
D/SEQUENCEENCODER: Retrieving image 0 of 3
D/SEQUENCEENCODER: Encoding image 0, 1 of 3
D/SEQUENCEENCODER: Encoding image 0, 2 of 3
D/SEQUENCEENCODER: Encoding image 0, 3 of 3
D/SEQUENCEENCODER: Retrieving image 1 of 3
D/SEQUENCEENCODER: Encoding image 1, 1 of 3
D/SEQUENCEENCODER: Encoding image 1, 2 of 3
D/SEQUENCEENCODER: Encoding image 1, 3 of 3
D/SEQUENCEENCODER: Retrieving image 2 of 3
D/SEQUENCEENCODER: Encoding image 2, 1 of 3
D/SEQUENCEENCODER: Encoding image 2, 2 of 3
D/SEQUENCEENCODER: Encoding image 2, 3 of 3
D/SEQUENCEENCODER: Retrieving image 3 of 3
D/SEQUENCEENCODER: Encoding image 3, 1 of 3
D/SEQUENCEENCODER: Encoding image 3, 2 of 3
D/SEQUENCEENCODER: Encoding image 3, 3 of 3
I/System.out: [WARN]    . (:0): No frames output.
D/EGL_emulation: eglMakeCurrent: 0xa8a05240: ver 2 0 (tinfo 0xa8a03250)
D/EGL_emulation: eglMakeCurrent: 0xa8a05240: ver 2 0 (tinfo 0xa8a03250)
I/chatty: uid=10080(projectname) RenderThread identical 1 line
D/EGL_emulation: eglMakeCurrent: 0xa8a05240: ver 2 0 (tinfo 0xa8a03250)
I/zygote: Do partial code cache collection, code=122KB, data=94KB
I/zygote: After code cache collection, code=117KB, data=92KB
I/zygote: Increasing code cache capacity to 512KB

然后是指向该命令的一长串系统错误

代码语言:javascript
复制
ase.encodeImage(image);

一个新的视频文件确实会在Android虚拟设备中创建,但它在播放后几乎立即结束,尽管它说它的长度是4秒。我想知道我在代码中做错了什么导致了这一点。

EN

回答 1

Stack Overflow用户

发布于 2017-12-07 00:06:21

有多种方法可以实现这一点:

  1. 在异步任务中完全移动你的循环,然后是finish;
  2. 如果只有一个执行线程,你也可以在异步任务中执行'finish‘,这样你就可以依靠内部执行器队列在最后执行'finish’;
  3. 使用线程同步原语,比如'wait/notify‘。因此,在主线程中,你可以在调用“finish”之前“等待”,而在异步任务中,你可以“通知”。虽然这是一个可行的选择,但我强烈建议您不要出于各种其他原因使用它。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47588301

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档