当前位置: 首页 > 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/387470.html

相关文章:

  • b2b商城网站建设竞价网络推广培训
  • 西安楼市最新情况seo怎么赚钱
  • 宁波seo推广优化哪家强网店seo名词解释
  • 网站时间特效电商网
  • 党建网站建设方案chrome下载
  • 积分网站建设seo营销推广公司
  • JSP做网站起到的作用拉新平台
  • 什么网站动物和人做的商务软文写作300字
  • 做网站报价出名的廊坊百度推广seo
  • 我想做代加工怎么找厂家什么叫做优化
  • 什么网站做执法仪网络营销课程学什么
  • 云南微网站建设营销软文的范文
  • 上海企业网站建设报价软文代写公司
  • 网站群建设技术方案网站批量收录
  • 杭州互联网网站公司潍坊百度网站排名
  • 免费网站封装app云南疫情最新情况
  • 学生网站做兼职百度如何推广产品
  • 亚马逊网站托管怎么做怎样宣传自己的品牌
  • 外贸网站建设哪家公司好网站内搜索
  • 网站开发模块磁力宝
  • 安徽省公共资源交易中心网站做关键词优化的公司
  • 广州市官方网站东莞网络营销公司
  • dw做网站怎么上线网站seo百度百科
  • 网站搭建思路湖南seo优化推荐
  • 做投票链接的网站上海网络推广联盟
  • 厦门制作网站哪家好外贸网站营销推广
  • 提示网站建设页面重庆seo和网络推广
  • 自己做的主页网站怕被劫持应用商店关键词优化
  • 湘潭网站建设 找磐石网络一流2021百度热搜年度榜
  • 东莞科技网站建设班级优化大师网页版