android - 在 android 中拆分后文件不在本地播放

标签 android file video

您好,我正在使用下面的 jave 代码将每个 video 文件拆分为 1MB 并且它们拆分得很好,但是当我转到它们的物理本地路径并尝试播放他们没有播放,我也在使用 FFMpeg 来处理这个场景,但这对我来说也不起作用,显示异常,如 No such file or Dictionary

请帮我解决这个问题

代码:

 public static List<File> splitFile(File f) {

    try {

        int partCounter = 1;
        List<File> result = new ArrayList<>();
        int sizeOfFiles = 1024 * 1024;// 1MB
        byte[] buffer = new byte[sizeOfFiles];
        // create a buffer of bytes sized as the one chunk size

        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
        String name = f.getName();

        int tmp = 0;
        while ((tmp = bis.read(buffer)) > 0) {
            File newFile = new File(f.getParent(), name + "." + String.format("%03d", partCounter++));
            // naming files as <inputFileName>.001, <inputFileName>.002, ...
            FileOutputStream out = new FileOutputStream(newFile);
            out.write(buffer, 0, tmp);//tmp is chunk size. Need it for the last chunk,
            // which could be less then 1 mb.
            result.add(newFile);
        }
        return result;
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
    return null;
}

FFMpeg代码:-

     public void getSplitCommand(String inputFileUrl, String outputFileUrl) {

            inputFileUrl=  /storage/emulated/0/1492848702.mp4;
            outputFileUrl= /storage/emulated/0/1492848702.mp4;
      ;
 String cmd[] = new String[]{"-i ",inputFileUrl+" ","-c ","copy ","-map ","0 ",
                "-segment_time ","8 ","-f ","segment/sdcard/Download/output%03d.mp4"};
            executeBinaryCommand(fFmpeg, cmd);
        }


        /**
         * executeBinaryCommand
         *
         * @param ffmpeg
         * @param command
         */

        public void executeBinaryCommand(FFmpeg ffmpeg, String[] command) {

            try {

                if (ffmpeg != null) {

                    ffmpeg.execute(command,
                            new ExecuteBinaryResponseHandler() {

                                @Override
                                public void onFailure(String response) {
                                    System.out.println("failure====>" + response.toString());
                                }

                                @Override
                                public void onSuccess(String response) {
                                    System.out.println("resposense====>" + response.toString());
                                }

                                @Override
                                public void onProgress(String response) {
                                    System.out.println("on progress");
                                }

                                @Override
                                public void onStart() {
                                    System.out.println("start");
                                }

                                @Override
                                public void onFinish() {
                                    System.out.println("Finish");
                                }
                            });
                }
            } catch (FFmpegCommandAlreadyRunningException exception) {
                exception.printStackTrace();
            }


}

最佳答案

enter image description here使用 [FFMPEG][2] 库分割视频。您的拆分方法可能会损坏视频。 FFMPEG 不会发生这种情况

ffmpeg -i INPUT.mp4 -acodec copy -f segment -vcodec copy -reset_timestamps 1 -map 0 OUTPUT%d.mp4

[2]: https://github.com/WritingMinds/ffmpeg-android-java/tree/master/FFmpegAndroid我将视频分成每 8 秒一次。不要分成大小。总是在持续时间内 split

关于android - 在 android 中拆分后文件不在本地播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43773403/

相关文章:

android - 在 androidx 中更改 snackbar 字体

php - 如何使用 PHP 加密和解密 PDF?

在 html5 播放器中支持所有主要移动设备的视频编解码器设置?

android - Eclipse 开发困境

android - 多线程处理程序与 ThreadPoolExecutor

php - 使用 PHP 命令行或 SSH 运行多个 PHP 文件

c - 我怎样才能告诉 Linux 进程使用一个文件作为它的整个堆?

video - 使用 ffmpeg 将直播电视录制为 .ts 到 mp4

video - 如何在这个巨大的 ffmpeg 命令的视频部分添加水印,该命令通过交叉淡入淡出添加介绍和结尾?

android - 在 Android 库上添加 Google AdMob 时出错 - LIBGDX 项目