FFmpeg Invalid data found when processing input

这篇具有很好参考价值的文章主要介绍了FFmpeg Invalid data found when processing input。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

说一下自己用ffmpeg合并视频出现的bug吧   直接上代码

/**
 * 批量转换某文件夹的视频   转换为ts文件 并生成txt文件
 * */


String videoPathList = "C:\\Users\\Administrator\\Desktop\\video\\";
File file = new File(videoPathList);

String txt = "C:\\Users\\Administrator\\Desktop\\video\\test.txt";
FileWriter fw = new FileWriter(new File(txt));
BufferedWriter bw = new BufferedWriter(fw);

if (null != file) {
    File[] fileList = file.listFiles();
    if (null != fileList && fileList.length > 0) {
        for (int i = 0; i < fileList.length; i++) {
            if (StrUtil.endWith(fileList[i].getName(), ".mp4")) {
                System.out.println(fileList[i].getName());
                String sourcePath = videoPathList + fileList[i].getName();
                String targetPath = videoPathList + "ts\\" + StrUtil.removeSuffix(fileList[i].getName(), ".mp4") + i + ".ts";
                if (mp4ToTs(sourcePath, targetPath)) {
                    bw.write("file " + "'" + targetPath + "'" + "\t\n");
                } else {
                    System.out.println("失败");
                    break;
                }
                System.out.println("成功");
            }
        }



        if (mp4Merge(txt, videoPathList + "ts\\aa.mp4")) {
            System.out.println("完成");
        } else {
            System.out.println("失败");
        }


    }
}

bw.close();
fw.close();

这段代码运行会直接报 Invalid data found when processing input  然后我去寻找这个文件的时候发现当中是有内容的  并且也真实存在这个文件  这时候我就有点疑惑为什么会报文件没有的异常  直到debug的时候我打开了这个txt文件  我才发现文件那时并没有真正的写入进去  只有close以后txt文件才算完成  但是在txt文件完成之前我就已经去合成了以后  抛出这个异常  

稍微修改一下就能正常的合成了文章来源地址https://www.toymoban.com/news/detail-499571.html

/**
 * 批量转换某文件夹的视频   转换为ts文件 并生成txt文件
 * */


String videoPathList = "C:\\Users\\Administrator\\Desktop\\video\\";
File file = new File(videoPathList);

String txt = "C:\\Users\\Administrator\\Desktop\\video\\test.txt";
FileWriter fw = new FileWriter(new File(txt));
BufferedWriter bw = new BufferedWriter(fw);

if (null != file) {
    File[] fileList = file.listFiles();
    if (null != fileList && fileList.length > 0) {
        for (int i = 0; i < fileList.length; i++) {
            if (StrUtil.endWith(fileList[i].getName(), ".mp4")) {
                System.out.println(fileList[i].getName());
                String sourcePath = videoPathList + fileList[i].getName();
                String targetPath = videoPathList + "ts\\" + StrUtil.removeSuffix(fileList[i].getName(), ".mp4") + i + ".ts";
                if (mp4ToTs(sourcePath, targetPath)) {
                    bw.write("file " + "'" + targetPath + "'" + "\t\n");
                } else {
                    System.out.println("失败");
                    break;
                }
                System.out.println("成功");
            }
        }
bw.close(); 
fw.close();



        if (mp4Merge(txt, videoPathList + "ts\\aa.mp4")) {
            System.out.println("完成");
        } else {
            System.out.println("失败");
        }


    }
}


顺便把合并类贴一下



public class Trans2 {

    static String ffmpegPath = "G:\\ffmpeg-4.4-essentials_build\\bin\\ffmpeg.exe";


    /**
     * 视频合成
     */

    public static boolean mp4Merge(String TxtPath, String targetPath) {
        List<String> cutpic = new LinkedList<>();
        cutpic.add(ffmpegPath);
        cutpic.add("-f");
        cutpic.add("concat");
        cutpic.add("-safe");
        cutpic.add("0");
        cutpic.add("-i");
        cutpic.add(TxtPath);

        cutpic.add("-c");
        cutpic.add("copy");
        cutpic.add("-y");
        cutpic.add(targetPath);


        System.out.println(cutpic.toString());
        return getMp4(cutpic, targetPath);
    }

    /**
     * mp4转换为ts
     */
    public static boolean mp4ToTs(String sourcePath, String targetPath) {
        // 创建一个List集合来保存命令
        List<String> cutpic = new LinkedList<>();
        cutpic.add(ffmpegPath);
        cutpic.add("-i");
        cutpic.add(sourcePath);
        cutpic.add("-y");

        cutpic.add("-c");
        cutpic.add("copy");//使用默认参数   增加转换速度
        cutpic.add("-acodec");
        cutpic.add("copy");
        cutpic.add(targetPath);
        return getMp4(cutpic, targetPath);
    }




    /**
     * ffmpeg运行cmd命令窗口生成mp4方法
     */
    private static boolean getMp4(List<String> cutpic, String imageGenerationPath) {
        try {

            Process process = new ProcessBuilder(cutpic).start();

            // 消耗缓冲区中的错误流
            new PrintStream(process.getErrorStream()).start();
            // 消耗缓冲区中的输入流
            new PrintStream(process.getInputStream()).start();

            process.waitFor();
            if (process.exitValue() != 0) {
                System.out.println("发生了错误==============错误为" + process.exitValue() + "::::::::::::::::::错误文件为" + imageGenerationPath);
                return false;
            }
            System.out.println(("生成完成,位置为:" + imageGenerationPath));

            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 内部类继承线程清理缓冲区
     */
    private static class PrintStream extends Thread {
        private InputStream stream;

        StringBuffer contentNum = new StringBuffer();

        public PrintStream(InputStream stream) {
            this.stream = stream;
        }

        @Override
        public void run() {
            try {
                while (null != stream) {
                    int content = stream.read();
                    if (content != -1) {
                        contentNum.append((char) content);
                    } else {
                        break;
                    }
                }
                System.out.println("FFmpeg  日志返回为" + contentNum.toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


}

到了这里,关于FFmpeg Invalid data found when processing input的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Pgsql报错: invalid input syntax for integer:‘ ‘

    业务sql偶尔会报错,意思是给integer了空字符串 起初我以为是alarm.status in () 这里传参问题, 因为我试了几次 把1换成2就不会报出这个错误,但看了很久也没发现1为什么会被认为是空字符 后来才发现,是因为 类型强转 的问题,应该是status为1时,camera.device_id为空了,导致强转为integer失

    2024年01月19日
    浏览(34)
  • ABAP 新语法--Data Processing

    新语法引入了字符串模板,用于处理字符串连接以及格式转换 字符串模板在 | … | 之间定义,主要分为两部分,固定文本和变量 其中,变量只能在 { … } 内使用,大括号之外的所有字符均作为固定文本使用,空格始终不会被忽略,见例1 在使用变量时,可以通过控制语句来指

    2024年02月12日
    浏览(19)
  • Git配置代理:fatal: unable to access*** github Failure when receiving data from

    github自从被微软收购以后,大多数情况没点科技上网都进不去了,还是怀念以前随时访问的时光。 我一直都是开着系统代理的,但是今天拉一个项目发现拉不下来了,报错: 这只能说明我自己的Git里面代理没生效咯~ 那就自己手动设置吧! 首先看一下自己的配置 设置代理

    2024年02月05日
    浏览(33)
  • packet tracer报错Invalid input detected at ‘^‘ marker.

    计算机网络实验2. 交换机MAC地址表建立与帧转发 本实验需要添加静态mac地址表项,老师的视频里是 输入enable,进入特权模式 输入config terminal 进入全局配置模式 输入mac-address-table static 【ip地址】 vlan 1 interface 【写错误端口】,分析错误端口的时候,转发数据和接受数据的情

    2024年02月12日
    浏览(24)
  • solidity报错处理:VM Exception while processing transaction: invalid opcode

    关于solidity开发时遇到的VM Exception while processing transaction: invalid opcode问题,我的代码如下: 发现在运行构造函数处提示VM Exception while processing transaction: invalid opcode错误。 改正方法如下: 然后将 修改后编译成功,运行不再报错。在改回原来的节点环境也能运行了。

    2024年02月14日
    浏览(32)
  • 安卓初始化项目报错An issue was found when checking AAR metadata

    解决办法,将com.google.android.material:material:1.10.0降为com.google.android.material:material:1.8.0

    2024年02月04日
    浏览(27)
  • Invalid bound statement (not found)

    目录 一、遇到的问题 二、分析思路 1、映射文件 2、测试类 三、解决方案 前几日,有个工作不久的同事找我帮他解决一个 Mybatis 的问题。他写了一个增删改查,但是在启动程序的时候报错:Invalid bound statement (not found) 。他试图解决该异常,花了一个小时还是没有解决,所以

    2024年02月01日
    浏览(39)
  • ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 128]

    因为用到了BatchNorm,所以batch_size要大于1,drop_last 参数设置为True。 如果是两个GPU训练,batch_size改为4。 参考 ValueError: Expected more than 1 value per channel when training, got input size [1, 16, 1, 1](解决方案) Pytorch遇到报错Expected more than 1 value per channel when training, got input size torch.Size

    2024年01月16日
    浏览(29)
  • Go 区块链 Input Data 解析

    input data 在以太坊协议中,当交易(transaction)为合约创建时,input data 是账户初始化程序的 EVM 代码; 而当交易(transaction)为消息调用时,input data 是合约函数调用数据。 正常情况下简单的消息调用如调用转账函数时需要填写你要转账的地址 _to 和你要转账的数量 _amount,这

    2024年02月11日
    浏览(27)
  • SQL 错误 [22007]: ERROR: invalid input syntax for type date: ““

    PG数据库一张表有这样一个 varchar 类型的字段 end_date ,存储的值是格式化后的年月日日期如 2024-08-10 现在我需要根据当前日期与end_date的差值作为where条件过滤,我的写法 报错 Caused by: org.postgresql.util.PSQLException: ERROR: invalid input syntax for type date: “” 这个错误翻译: 无效的类型da

    2024年02月11日
    浏览(36)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包