当前位置: 首页 > wzjs >正文

网站建设招标文件范本试用型网站怎么做

网站建设招标文件范本,试用型网站怎么做,公司官网静态,上线了小程序怎么收费1. AVFormatContext 的通用性 1.1 通用结构 AVFormatContext 是 FFmpeg 中的一个通用结构体,用于描述多媒体文件或流的上下文信息。它既可以用于输入文件/流,也可以用于输出文件/流。关键字段(如 iformat 和 oformat)决定了 AVF…

1. AVFormatContext 的通用性

1.1 通用结构

  • AVFormatContext 是 FFmpeg 中的一个通用结构体,用于描述多媒体文件或流的上下文信息。
  • 它既可以用于输入文件/流,也可以用于输出文件/流。
  • 关键字段(如 iformatoformat)决定了 AVFormatContext 是用于输入还是输出。

1.2 输入和输出的区别

  • 输入 AVFormatContext
    • 用于描述输入文件或流的上下文信息。
    • 通过 iformat 字段(AVInputFormat)指定输入格式。
    • 通过 avformat_open_input 自动分配和初始化。
  • 输出 AVFormatContext
    • 用于描述输出文件或流的上下文信息。
    • 通过 oformat 字段(AVOutputFormat)指定输出格式。
    • 通过 avformat_alloc_output_context2avformat_alloc_context 手动分配和初始化。

2. avformat_alloc_context 的作用

2.1 通用分配函数

  • avformat_alloc_context 是一个通用的分配函数,用于分配并初始化一个空的 AVFormatContext
  • 它不会自动设置 iformatoformat,需要手动设置。

2.2 使用场景

  • 输入文件/流
    • 通常不直接使用 avformat_alloc_context,而是通过 avformat_open_input 自动分配和初始化 AVFormatContext
  • 输出文件/流
    • 通常使用 avformat_alloc_output_context2,它会自动设置 oformat

3. 输入和输出的 AVFormatContext 的创建方式

3.1 输入 AVFormatContext

  • 使用 avformat_open_input 打开输入文件/流时,FFmpeg 会自动分配并初始化一个 AVFormatContext
  • 示例:
    import Foundation
    import FFmpegclass FFmpegInputManager {static func openInputFile(filePath: String) -> UnsafeMutablePointer<AVFormatContext>? {var formatContext: UnsafeMutablePointer<AVFormatContext>? = nil// 打开输入文件if avformat_open_input(&formatContext, filePath, nil, nil) < 0 {print("Failed to open input file: \(filePath)")return nil}print("Input file opened successfully: \(filePath)")return formatContext}
    }// 调用示例
    if let inputContext = FFmpegInputManager.openInputFile(filePath: "input.mp4") {// 使用 inputContextprint("Input context created: \(inputContext)")// 打印文件信息av_dump_format(inputContext, 0, "input.mp4", 0)// 释放资源avformat_close_input(&inputContext)
    }
    
关键点
  • avformat_open_input 会自动分配并初始化 AVFormatContext
  • iformat 字段会被设置为输入文件的格式(AVInputFormat)。

3.2 输出 AVFormatContext

  • 使用 avformat_alloc_output_context2avformat_alloc_context 手动分配和初始化一个 AVFormatContext
  • 示例:
    import Foundation
    import FFmpegclass FFmpegOutputManager {static func createOutputFile(filePath: String, formatName: String) -> UnsafeMutablePointer<AVFormatContext>? {var formatContext: UnsafeMutablePointer<AVFormatContext>? = nil// 创建输出文件if avformat_alloc_output_context2(&formatContext, nil, formatName, filePath) < 0 {print("Failed to create output file: \(filePath)")return nil}print("Output file created successfully: \(filePath)")return formatContext}
    }// 调用示例
    if let outputContext = FFmpegOutputManager.createOutputFile(filePath: "output.mp4", formatName: "mp4") {// 使用 outputContextprint("Output context created: \(outputContext)")// 释放资源avformat_free_context(outputContext)
    }
    
关键点
  • avformat_alloc_output_context2 会自动分配并初始化 AVFormatContext,并设置 oformat 字段为输出格式(AVOutputFormat)。
  • 如果使用 avformat_alloc_context,需要手动设置 oformat

4. 输入和输出的 AVFormatContext 的区别

属性输入 AVFormatContext输出 AVFormatContext
创建方式使用 avformat_open_input 自动分配和初始化使用 avformat_alloc_output_context2avformat_alloc_context 手动分配
格式字段iformatAVInputFormatoformatAVOutputFormat
用途描述输入文件/流的上下文信息描述输出文件/流的上下文信息
流信息包含输入文件/流的所有流信息包含输出文件/流的所有流信息
常见操作打开文件、读取数据写入文件头、写入数据、写入文件尾

5. 示例:完整的输入和输出处理流程

以下是一个完整的示例,展示如何使用 输入 AVFormatContext输出 AVFormatContext 处理音频文件。

5.1 示例代码

import Foundation
import FFmpegclass FFmpegProcessor {static func processFile(inputFile: String, outputFile: String) {var inputContext: UnsafeMutablePointer<AVFormatContext>? = nilvar outputContext: UnsafeMutablePointer<AVFormatContext>? = nil// 打开输入文件if avformat_open_input(&inputContext, inputFile, nil, nil) < 0 {print("Failed to open input file: \(inputFile)")return}// 创建输出文件if avformat_alloc_output_context2(&outputContext, nil, "mp4", outputFile) < 0 {print("Failed to create output file: \(outputFile)")avformat_close_input(&inputContext)return}// 添加流到输出文件for i in 0..<inputContext!.pointee.nb_streams {let inStream = inputContext!.pointee.streams[Int(i)]!let outStream = avformat_new_stream(outputContext, nil)if outStream == nil {print("Failed to allocate output stream")avformat_close_input(&inputContext)avformat_free_context(outputContext)return}// 复制流参数if avcodec_parameters_copy(outStream!.pointee.codecpar, inStream.pointee.codecpar) < 0 {print("Failed to copy codec parameters")avformat_close_input(&inputContext)avformat_free_context(outputContext)return}outStream!.pointee.codecpar.pointee.codec_tag = 0}// 打开输出文件if avio_open(&outputContext!.pointee.pb, outputFile, AVIO_FLAG_WRITE) < 0 {print("Failed to open output file")avformat_close_input(&inputContext)avformat_free_context(outputContext)return}// 写入文件头if avformat_write_header(outputContext, nil) < 0 {print("Failed to write header")avformat_close_input(&inputContext)avformat_free_context(outputContext)return}// 释放资源avformat_close_input(&inputContext)avformat_free_context(outputContext)print("Processing completed successfully")}
}// 调用示例
FFmpegProcessor.processFile(inputFile: "input.mp4", outputFile: "output.mp4")

6. 总结

  • AVFormatContext 是通用的结构体,既可以用于输入,也可以用于输出。
  • 输入和输出的区别
    • 输入通过 iformatAVInputFormat)描述。
    • 输出通过 oformatAVOutputFormat)描述。
  • 创建方式
    • 输入:使用 avformat_open_input 自动分配和初始化。
    • 输出:使用 avformat_alloc_output_context2avformat_alloc_context 手动分配和初始化。

通过这种方式,FFmpeg 可以灵活地处理多媒体文件和流。

http://www.dtcms.com/wzjs/797097.html

相关文章:

  • 酒类产品网站设计做网站公司东莞
  • 为什么一个网站做中英文双语版微信公众号做微网站吗
  • 宣城 网站建设最好的自助建站系统
  • 温州网站优化排名wordpress 分享 朋友圈
  • 制作网站的最新软件是什么wordpress生成多个尺寸图片
  • 用wordpress做外贸网站做网站能给公司带来什么好处
  • discuz网站搬家教程宁波北仑装修公司排行
  • 做网站开发的薪酬怎么样网站建设从零开始教程
  • 河南省住房和城乡建设厅门户网站织梦手机网站教程
  • 手机做网站的软件可以免费发广告的app
  • 安装网站程序要给那个目录设置权限关于网站建设的问卷调查
  • 电子商务网站项目计划wordpress留白
  • 东莞松山湖招聘网站优化报价单
  • 网站建设比较好的手机网站建设文章
  • 深圳微商城网站设计电话wordpress 适合做什么网站
  • 医药网站建设需要注意点dw新建站点
  • 上海市网站建设公叿品牌推广总监
  • 关于干外贸的一些好的学习网站龙岩天宫山攻略
  • 做一个网站需要哪些资源网页模板简单
  • 网站建设色彩合肥的网站建设
  • 江西宜春市建设局网站上国外网站的dns
  • 义乌网站建设多少钱网站建设过程中服务器的搭建方式
  • 自己买服务器可以搭建网站吗用户界面设计原则
  • 万网速成网站有哪些 功能济南市个人网站制作
  • 潍坊网站建设推广公司王战营
  • 中国质量建设协会网站wordpress使用步骤
  • 网站建设河北石家庄做网站的开发工具
  • 网站如何安装源码h5制作公司
  • 网站悬浮窗广告怎么做东莞专业设计网站
  • 微商城手机网站设计谷歌怎么做网站优化