Java “接收”;“无帧输出”;使用AndroidSequenceEncoder时
我正在尝试使用AndroidSequenceEncoder创建视频幻灯片。为了做到这一点,我有一个方法可以检索位图的ArrayList和表示视频文件名的字符串。以下是我的方法的代码:Java “接收”;“无帧输出”;使用AndroidSequenceEncoder时,java,android,video,runtime-error,Java,Android,Video,Runtime Error,我正在尝试使用AndroidSequenceEncoder创建视频幻灯片。为了做到这一点,我有一个方法可以检索位图的ArrayList和表示视频文件名的字符串。以下是我的方法的代码: public class ImageToVideo { //used to input frames (images) into the video file private AndroidSequenceEncoder ase; //Arraylist containing the fra
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;
}
后面是一长串指向该命令的系统错误
ase.encodeImage(image);
Android虚拟设备中确实创建了一个新的视频文件,但它几乎在播放后立即结束,尽管它说它的长度是4秒。我想知道我在代码中做错了什么导致了这种情况。我看到上面代码的一个问题是,帧的实际编码发生在一个单独的(后台)线程中。因此,在某些情况下,在调用“finish”时,可能没有任何帧被实际编码。 您需要做的是确保在所有帧的编码实际发生后调用“finish”。实现这一点有多种方法:
ase.encodeImage(image);