FFmpeg的API使用篇(二):转封装(不涉及转码)

1、前言

本文不涉及音频和视频的编解码操作,仅仅是转换视频的封装格式,比如mp4转flv,mp4转mkv等,也可以认为仅仅是为文件重命名,更改了文件后缀而已。

由于不涉及音视频的转码操作,因此此程序处理速度极快。需要知道的是,音视频编解码的算法非常复杂,占用了很多的CPU,这部分也消耗了是视频转码的绝大部分时间。关于视频转码的API使用方法将在之后的博客中详细介绍,本文只关注于转封装。

只转封装的工作原理如下图所示:

2、转封装流程

FFmpeg转封装API

3、代码

  • 类头文件代码(remuxing.h)
// Copyright (c) 2021 LucasNan <nanche@mail.hfut.edu.cn> <www.kevinnan.org.cn>

// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:

// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

#ifndef REMUXING_H
#define REMUXING_H

#include <iostream>
#include <string>

extern "C"{
   

    #include "libavformat/avformat.h"
    #include "libavcodec/avcodec.h"
}


class ReMuxing
{
   
public:
    ReMuxing();

    ~ReMuxing();

    //@brief: 得到输入文件
    //@param: input_file: 输入文件
    //@ret  : void
    //@birth: created by LucasNan on 20210220
    void getInputFile(std::string input_file){
   
        this->input_file_ = input_file;
    }

    //@brief: 得到输出文件
    //@param: output_file: 输出文件
    //@ret  : void
    //@birth: created by LucasNan on 20210220
    void getOutputFile(std::string output_file){
   
        this->output_file_ = output_file;
    }

    //@brief: 视频转封装
    //@param: void
    //@ret  : void
    //@birth: created by LucasNan on 20210220
    void reMuxing();

private:
    //输出文件AVFormatContext
    AVFormatContext* ifmt_ctx_;
    //输出文件AVFormatContext
    AVFormatContext* ofmt_ctx_;

    std::string input_file_;
    std::string output_file_;

};

#endif // REMUXING_H
  • 类实现代码(remuxing.cpp)
// Copyright (c) 2021 LucasNan <nanche@mail.hfut.edu.cn> <www.kevinnan.org.cn>

// Permission is hereby granted, free of char
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值