File存本地

    public File savePic(File file) {
        File fileDir = new File("D:\\marTemp");
        InputStream inputStream = null;
        OutputStream os = null;
        if(!fileDir.exists()){
            System.out.println("mkdir");
            fileDir.mkdir();
        }

        try {
            byte[] bs = new byte[1024 * 1024 * 5];//1k * 1024 * 5
            int len;
            inputStream = new FileInputStream(file);
            logger.info("inputStream:"+inputStream);
            os = new FileOutputStream(fileDir.getPath()+File.separator+file.getName());
            logger.info("os:"+os);
            while ((len = inputStream.read(bs)) != -1) {
                os.write(bs, 0, len);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            logger.info("FileNotFoundException:--------"+e.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
            logger.info("IOException:--------"+e.getMessage());
        }finally {
            try {
                os.close();
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
                logger.info("FinallyIOException:--------"+e.getMessage());
            }
        }
        File sendFile = new File(fileDir.getPath()+File.separator+file.getName());
        return sendFile;
    }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C++是一种通用的编程语言,泛应用于软件开发领域。它具有高效、灵活和可扩展的特性,被广泛用于开发各种类型的应用程序,包括嵌入式系统、桌面应用、游戏开发等。 FFmpeg是一个开源的跨平台音视频处理工具库,它提供了一组丰富的功能和接口,可以用于音视频的编解码、转码、流媒体处理等。在C++中使用FFmpeg进行拉流并储到本地的例子如下: ```cpp #include <iostream> extern "C" { #include <libavformat/avformat.h> } int main() { av_register_all(); AVFormatContext* formatContext = nullptr; AVPacket packet; // 打开输入文件 if (avformat_open_input(&formatContext, "input_url", nullptr, nullptr) != 0) { std::cout << "无法打开输入文件" << std::endl; return -1; } // 查找流信息 if (avformat_find_stream_info(formatContext, nullptr) < 0) { std::cout << "无法获取流信息" << std::endl; return -1; } // 打开输出文件 FILE* outputFile = fopen("output_file", "wb"); if (!outputFile) { std::cout << "无法打开输出文件" << std::endl; return -1; } // 遍历所有流 for (int i = 0; i < formatContext->nb_streams; i++) { if (formatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { AVCodecParameters* codecParameters = formatContext->streams[i]->codecpar; // 可以在这里进行视频流的处理 } else if (formatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { AVCodecParameters* codecParameters = formatContext->streams[i]->codecpar; // 可以在这里进行音频流的处理 } } // 读取数据包并写入输出文件 while (av_read_frame(formatContext, &packet) >= 0) { fwrite(packet.data, 1, packet.size, outputFile); av_packet_unref(&packet); } // 关闭文件和释放资源 fclose(outputFile); avformat_close_input(&formatContext); return 0; } ``` 这个例子演示了如何使用FFmpeg库进行拉流并将数据储到本地文件中。你可以根据自己的需求对视频流和音频流进行处理。请注意,你需要先安装FFmpeg库,并在编译时链接相应的库文件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值