b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

Bili Bili视频与音频文件流合并

电脑杂谈  发布时间:2020-04-04 02:03:22  来源:网络整理

播放264文件_flv是什么格式的文件 如何下载打开播放_哔哩哔哩播放本地文件

#3:9:f:4:1:d:8:3:5:d:1:b:a:a:4:6:3:9:c:9哔哩哔哩播放本地文件:1:7:e:b:4:0:2:5哔哩哔哩播放本地文件:0:1:2:5#

播放264文件_哔哩哔哩播放本地文件_flv是什么格式的文件 如何下载打开播放

ffmpeg下载地址:

播放264文件_哔哩哔哩播放本地文件_flv是什么格式的文件 如何下载打开播放

在此处下载Windows版本: ffmpeg-4.2.2-win64-static.zip

哔哩哔哩播放本地文件_播放264文件_flv是什么格式的文件 如何下载打开播放

解压后bin目录的内容(假设它在驱动器D的bin路径中):

播放264文件_哔哩哔哩播放本地文件_flv是什么格式的文件 如何下载打开播放

哔哩哔哩视频与音频文件流合并

public class App {
    // ffmpeg.exe全路径
    private static final String FFMPEG_PATH = "D:/bin/ffmpeg.exe";
    public static void main(String[] args) throws Exception {
        File rootDir = new File("C:"+File.separator+"哔哩哔哩"+File.separator+"xx视频");
        String outputDir = rootDir.getAbsolutePath() + File.separator + "out";
        // 开始处理文件
        renameAndCopyFile(rootDir, outputDir);
    }
    /**
     * 具体合成视频函数
     * 
     * @param videoInputPath    原视频的全路径
     * 
     * @param audioInputPath    音频的全路径
     * 
     * @param videoOutPath      视频与音频结合之后的视频的路径
     */
    public static void convetor(String videoInputPath, String audioInputPath, String videoOutPath) throws Exception {
        Process process = null;
        InputStream errorStream = null;
        InputStreamReader inputStreamReader = null;
        BufferedReader br = null;
        try {
            // ffmpeg命令
            String command = FFMPEG_PATH + " -i " + videoInputPath + " -i " + audioInputPath
                    + " -c:v copy -c:a aac -strict experimental " + " -map 0:v:0 -map 1:a:0 " + " -y " + videoOutPath;
            process = Runtime.getRuntime().exec(command);
            errorStream = process.getErrorStream();
            inputStreamReader = new InputStreamReader(errorStream);
            br = new BufferedReader(inputStreamReader);
            // 用来收集错误信息的
            String str = "";
            while ((str = br.readLine()) != null) {
                System.out.println(str);
            }
            process.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                br.close();
            }
            if (inputStreamReader != null) {
                inputStreamReader.close();
            }
            if (errorStream != null) {
                errorStream.close();
            }
        }
    }
    // 遍历每个路径,找到entry.json文件所在路径
    public static void renameAndCopyFile(File rootDir, String outputDir) throws Exception {
        File dir = rootDir;
        if (dir == null) {
            return;
        }
        File[] files = dir.listFiles();
        if (files == null || files.length == 0) {
            return;
        }
        String fileName = null;
        for (File f : files) {
            if (f.isFile()) {
                fileName = f.getName();
                if ("entry.json".equalsIgnoreCase(fileName)) {
                    String jsonStr = FileUtils.readFileToString(f, "UTF-8");
                    if (jsonStr == null || jsonStr.isEmpty()) {
                        return;
                    }
                    Entry entry = getEntry(jsonStr);
                    // 文件名
                    String realFileName = entry.page_data.part;
                    realFileName = realFileName.replaceAll("\\s+", "-");
                    // 开始迭代查找视频和音频文件,并将数据拷贝到其他地方
                    List<FileInfo> fileList = findVideoAudioFile(dir);
                    // 对文件进行合并
                    String videoInputPath = null;
                    String audioInputPath = null;
                    String videoOutPath = outputDir + File.separator + realFileName + ".mp4";
                    System.out.println(videoOutPath);
                    for (FileInfo info : fileList) {
                        if ("audio.m4s".equalsIgnoreCase(info.fileName)) {
                            audioInputPath = info.file.getAbsolutePath();
                        }
                        if ("video.m4s".equalsIgnoreCase(info.fileName)) {
                            videoInputPath = info.file.getAbsolutePath();
                        }
                    }
                    convetor(videoInputPath, audioInputPath, videoOutPath);
                }
            } else if (f.isDirectory()) {
                renameAndCopyFile(f, outputDir);
            }
        }
    }
    private static List<FileInfo> findVideoAudioFile(File dir) {
        if (dir == null) {
            return new ArrayList<FileInfo>();
        }
        File[] files = dir.listFiles();
        if (files == null || files.length == 0) {
            return new ArrayList<FileInfo>();
        }
        List<FileInfo> result = new ArrayList<FileInfo>();
        String fileName = null;
        for (File f : files) {
            if (f.isFile()) {
                fileName = f.getName();
                if (fileName.endsWith("m4s")) {
                    result.add(new FileInfo(f));
                }
            } else if (f.isDirectory()) {
                result.addAll(findVideoAudioFile(f));
            }
        }
        return result;
    }
    public static class FileInfo {
        public File file;
        public String fileName;
        public FileInfo(File file) {
            this.file = file;
            if (file != null) {
                fileName = file.getName();
            }
        }
    }
    // 解析bilibili下的entry.json文件
    public static Entry getEntry(String jsonText) {
        return JSON.parseObject(jsonText, Entry.class);
    }
    public static class PageData {
        // 文件名
        public String part;
    }
    public static class Entry {
        // 是否已经下载完成
        public boolean is_completed;
        // 课程名/专辑名
        public String title;
        // 文件信息
        public PageData page_data;
    }
}

ffmpeg相关说明:


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/bofangqi/article-163101-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...