1

对不起,快速提问:

我有这个视频流例程,我接收数据包,将它们转换为 byte[] ,然后转换为位图,然后将它们显示在屏幕上:

dsocket.receive(packetReceived); // receive packet
byte[] buff = packetReceived.getData(); // convert packet to byte[]
final Bitmap ReceivedImage = BitmapFactory.decodeByteArray(buff, 0, buff.length); // convert byte[] to bitmap image

runOnUiThread(new Runnable()
{
    @Override
    public void run()
    {
        // this is executed on the main (UI) thread
        imageView.setImageBitmap(ReceivedImage);
    }
});

现在,我想实现一个录制功能。建议说我需要使用 FFmpeg(我不知道如何使用),但首先,我需要准备一个有序图像的目录,然后将其转换为视频文件。这样做我将在内部保存所有图像,并且我正在使用这个答案来保存每个图像:

if(RecordVideo && !PauseRecording) {
    saveToInternalStorage(ReceivedImage, ImageNumber);
    ImageNumber++;
}
else
{
    if(!RecordVideo)
        ImageNumber = 0;
}

// ...

private void saveToInternalStorage(Bitmap bitmapImage, int counter){
        ContextWrapper cw = new ContextWrapper(getApplicationContext());

        // path to /data/data/yourapp/app_data/imageDir
        File MyDirectory = cw.getDir("imageDir", Context.MODE_PRIVATE);

        // Create imageDir
        File MyPath = new File(MyDirectory,"Image" + counter + ".jpg");

        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(MyPath);

            // Use the compress method on the BitMap object to write image to the OutputStream
            bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //return MyDirectory.getAbsolutePath();
    }

但我似乎无法在我的设备上找到目录(实际查看我是否成功创建目录)具体// path to /data/data/yourapp/app_data/imageDir位于哪里?

4

1 回答 1

1

如果根据文档该目录尚不存在,的getDir方法ContextWrapper将自动创建该目录。此外,除非您具有 root 访问权限,否则您无法访问应用程序代码之外的目录中的任何内容。如果您想查看保存在此目录中的图像,可以在命令提示符下运行该工具以将图像移动到可公开访问的目录中:imageDir/dataadb

adb shell run-as com.your.packagename cp -r /data/data/com.your.packagename/app_data/imageDir /sdcard/imageDir

请注意,该run-as命令仅在您的应用程序可调试时才有效。

您可以替换/sdcard/imageDir为您有权在设备上访问的任何目录。如果您想随后将文件从设备上移到您的机器上,您可以使用adb pull从公共目录中提取文件:

adb pull /sdcard/myDir C:\Users\Desktop

同样,用适当的源目录和目标目录替换/sdcard/myDir和。C:\Users\Desktop

于 2016-10-29T20:21:24.210 回答