我正试图把我的图像转换成视频。我找到了示例代码,并将其用于我的应用程序中。但我的错误就像
java.io.FileNotFoundException: output.mp4 (Read-only file system)
下面是我的代码片段:
public class Main2Activity extends AppCompatActivity {
AndroidSequenceEncoder encoder;
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
ArrayList<Bitmap> arrayList = new ArrayList<>();
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.empty_collage);
Bitmap a = BitmapFactory.decodeResource(getResources(),R.drawable.images);
arrayList.add(a);
arrayList.add(b);
File file = new File("output.mp4");
SeekableByteChannel out = null;
try {
out = (SeekableByteChannel) NIOUtils.writableFileChannel(String.valueOf(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.e("msg",e.toString());
}
try {
encoder = new AndroidSequenceEncoder((org.jcodec.common.io.SeekableByteChannel) out, Rational.R(25,1));
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(this, "in for loop", Toast.LENGTH_SHORT).show();
for(int i=0 ;i<arrayList.size() ; i++){
try {
encoder.encodeImage(arrayList.get(i));
} catch (IOException e) {
e.printStackTrace();
}
}
Toast.makeText(this, "out of loop", Toast.LENGTH_SHORT).show();
try {
encoder.finish();
} catch (IOException e) {
e.printStackTrace();
}
NIOUtils.closeQuietly(out);
}
}
}希望我能很快得到回应。谢谢。
发布于 2017-09-22 11:52:47
File file = new File("output.mp4");这并没有指出任何有用的地方。始终使用方法派生要写入的根位置。
例如,可以将其更改为:
File file = new File(getFilesDir(), "output.mp4");或者:
File file = new File(getExternalFilesDir(null), "output.mp4");https://stackoverflow.com/questions/46364126
复制相似问题