zoukankan      html  css  js  c++  java
  • 最简单的基于FFMPEG的Helloworld程序

    学习雷神的FFMPEG入门教程,本文基于命令行实现。

    文件结构

    G:CodingFFMpegProjConsole>dir
     驱动器 G 中的卷没有标签。
     卷的序列号是 0FD5-0CC8
    
     G:CodingFFMpegProjConsole 的目录
    
    2016/08/10  12:46    <DIR>          .
    2016/08/10  12:46    <DIR>          ..
    2016/04/14  11:08        24,464,896 avcodec-57.dll
    2016/04/14  11:08           168,948 avcodec.lib
    2016/04/14  11:08         1,363,968 avdevice-57.dll
    2016/04/14  11:08            15,628 avdevice.lib
    2016/04/14  11:08         3,799,552 avfilter-6.dll
    2016/04/14  11:08            50,364 avfilter.lib
    2016/04/14  11:08         4,929,536 avformat-57.dll
    2016/04/14  11:08           133,888 avformat.lib
    2016/04/14  11:08           604,672 avutil-55.dll
    2016/04/14  11:08           359,056 avutil.lib
    2016/06/23  09:59        21,987,736 bad.mp4
    2016/08/09  18:25               424 compile.bat
    2016/04/14  11:08    <DIR>          libavcodec
    2016/04/14  11:08    <DIR>          libavdevice
    2016/04/14  11:08    <DIR>          libavfilter
    2016/04/14  11:08    <DIR>          libavformat
    2016/04/14  11:08    <DIR>          libavutil
    2016/04/14  11:08    <DIR>          libpostproc
    2016/04/14  11:08    <DIR>          libswresample
    2016/04/14  11:08    <DIR>          libswscale
    2016/04/14  11:08           110,080 postproc-54.dll
    2016/04/14  11:08             8,904 postproc.lib
    2016/04/14  11:08           287,232 swresample-2.dll
    2016/04/14  11:08            17,944 swresample.lib
    2016/04/14  11:08           513,536 swscale-4.dll
    2016/04/14  11:08            27,064 swscale.lib
    2013/09/01  09:07             5,800 test.swf
    2016/08/09  18:01             4,334 tutorial.c
    2016/08/10  12:01             3,075 tutorial.cpp
                  21 个文件     58,856,637 字节
                  10 个目录 10,641,301,504 可用字节
    
    G:CodingFFMpegProjConsole>

    自己利用批处理写的一小段编译链接代码:

    @echo off
    color a
    call D:VS2013VCvcvarsall.bat x86
    cl /c tutorial.cpp
    if %errorlevel% == 0 (goto :LINK) else ((echo CL error) && goto :END)
    
    pause
    
    :LINK
    link tutorial.obj avformat.lib avfilter.lib avcodec.lib avutil.lib postproc.lib swresample.lib swscale.lib avdevice.lib
    if %errorlevel% == 0 (goto :RUN) else ((echo LINK error) && goto :END)
    
    :RUN
    tutorial.exe
    tutorial.exe > 1.txt
    1.txt
    
    :END
    @pause
    =====================================================

    最简单的基于FFmpeg的视频播放器系列文章列表:

    100行代码实现最简单的基于FFMPEG+SDL的视频播放器(SDL1.x)

    最简单的基于FFMPEG+SDL的视频播放器 ver2 (采用SDL2.0)

    最简单的基于FFmpeg的解码器-纯净版(不包含libavformat)

    最简单的基于FFMPEG+SDL的视频播放器:拆分-解码器和播放器

    最简单的基于FFMPEG的Helloworld程序

    =====================================================

    本文记录一个基于FFmpeg的HelloWorld程序。该程序可以打印出FFmpeg类库的基本信息。使用该程序通常可以验证FFmpeg是否正确的安装配置。

    源代码

    /**
     * 最简单的FFmpeg Helloworld程序
     * Simplest FFmpeg HelloWorld
     *
     * 雷霄骅 Lei Xiaohua
     * leixiaohua1020@126.com
     * 中国传媒大学/数字电视技术
     * Communication University of China / Digital TV Technology
     * http://blog.csdn.net/leixiaohua1020
     *
     * 
     * 本程序是基于FFmpeg函数的最简单的程序。它可以打印出FFmpeg类库的下列信息:
     * Protocol:  FFmpeg类库支持的协议
     * AVFormat:  FFmpeg类库支持的封装格式
     * AVCodec:   FFmpeg类库支持的编解码器
     * AVFilter:  FFmpeg类库支持的滤镜
     * Configure: FFmpeg类库的配置信息
     * 
     * This is the simplest program based on FFmpeg API. It can show following 
     * informations about FFmpeg library:
     * Protocol:  Protocols supported by FFmpeg.
     * AVFormat:  Container format supported by FFmpeg.
     * AVCodec:   Encoder/Decoder supported by FFmpeg.
     * AVFilter:  Filters supported by FFmpeg.
     * Configure: configure information of FFmpeg.
     *
     */
    
    #include <stdio.h>
    
    #define __STDC_CONSTANT_MACROS
    
    #ifdef _WIN32
    //Windows
    extern "C"
    {
    #include "libavcodec/avcodec.h"
    #include "libavformat/avformat.h"
    #include "libavfilter/avfilter.h"
    };
    #else
    //Linux...
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    #include <libavcodec/avcodec.h>
    #include <libavformat/avformat.h>
    #include <libavfilter/avfilter.h>
    #ifdef __cplusplus
    };
    #endif
    #endif
    
    //FIX
    struct URLProtocol;
    /**
     * Protocol Support Information
     */
    char * urlprotocolinfo(){
    	
    	char *info=(char *)malloc(40000);
    	memset(info,0,40000);
    
    	av_register_all();
    
    	struct URLProtocol *pup = NULL;
    	//Input
    	struct URLProtocol **p_temp = &pup;
    	avio_enum_protocols((void **)p_temp, 0);
    	while ((*p_temp) != NULL){
    		sprintf(info, "%s[In ][%10s]
    ", info, avio_enum_protocols((void **)p_temp, 0));
    	}
    	pup = NULL;
    	//Output
    	avio_enum_protocols((void **)p_temp, 1);
    	while ((*p_temp) != NULL){
    		sprintf(info, "%s[Out][%10s]
    ", info, avio_enum_protocols((void **)p_temp, 1));
    	}
    
    	return info;
    }
    
    /**
     * AVFormat Support Information
     */
    char * avformatinfo(){
    
    	char *info=(char *)malloc(40000);
    	memset(info,0,40000);
    
    	av_register_all();
    
    	AVInputFormat *if_temp = av_iformat_next(NULL);
    	AVOutputFormat *of_temp = av_oformat_next(NULL);
    	//Input
    	while(if_temp!=NULL){
    		sprintf(info, "%s[In ] %10s
    ", info, if_temp->name);
    		if_temp=if_temp->next;
    	}
    	//Output
    	while (of_temp != NULL){
    		sprintf(info, "%s[Out] %10s
    ", info, of_temp->name);
    		of_temp = of_temp->next;
    	}
    	return info;
    }
    
    /**
     * AVCodec Support Information
     */
    char * avcodecinfo()
    {
    	char *info=(char *)malloc(40000);
    	memset(info,0,40000);
    
    	av_register_all();
    
    	AVCodec *c_temp = av_codec_next(NULL);
    
    	while(c_temp!=NULL){
    		if (c_temp->decode!=NULL){
    			sprintf(info, "%s[Dec]", info);
    		}
    		else{
    			sprintf(info, "%s[Enc]", info);
    		}
    		switch (c_temp->type){
    		case AVMEDIA_TYPE_VIDEO:
    			sprintf(info, "%s[Video]", info);
    			break;
    		case AVMEDIA_TYPE_AUDIO:
    			sprintf(info, "%s[Audio]", info);
    			break;
    		default:
    			sprintf(info, "%s[Other]", info);
    			break;
    		}
    
    		sprintf(info, "%s %10s
    ", info, c_temp->name);
    
    		c_temp=c_temp->next;
    	}
    	return info;
    }
    
    /**
     * AVFilter Support Information
     */
    char * avfilterinfo()
    {
    	char *info=(char *)malloc(40000);
    	memset(info,0,40000);
    
    	avfilter_register_all();
    
    	AVFilter *f_temp = (AVFilter *)avfilter_next(NULL);
    	
    	while (f_temp != NULL){
    		sprintf(info, "%s[%15s]
    ", info, f_temp->name);
    		f_temp=f_temp->next;
    	}
    	return info;
    }
    
    /**
     * Configuration Information
     */
    char * configurationinfo()
    {
    	char *info=(char *)malloc(40000);
    	memset(info,0,40000);
    
    	av_register_all();
    
    	sprintf(info, "%s
    ", avcodec_configuration());
    
    	return info;
    }
    
    int main(int argc, char* argv[])
    {
    	char *infostr=NULL;
    	infostr=configurationinfo();
    	printf("
    <<Configuration>>
    %s",infostr);
    	free(infostr);
    
    	infostr=urlprotocolinfo();
    	printf("
    <<URLProtocol>>
    %s",infostr);
    	free(infostr);
    
    	infostr=avformatinfo();
    	printf("
    <<AVFormat>>
    %s",infostr);
    	free(infostr);
    
    	infostr=avcodecinfo();
    	printf("
    <<AVCodec>>
    %s",infostr);
    	free(infostr);
    
    	infostr=avfilterinfo();
    	printf("
    <<AVFilter>>
    %s",infostr);
    	free(infostr);
    
    	return 0;
    }

    输出




    Keep it simple!
    作者:N3verL4nd
    知识共享,欢迎转载。
  • 相关阅读:
    python学习
    当时的月亮 王菲
    谈谈写程序与学英语(转载)
    excel 列索引(数字)转列名
    爆款PHP面试题
    关于PDO取得结果集的数据类型为string的问题
    分享几款常用的API/文档浏览器
    php写错命名空间 导致catch不到异常
    iOS图片上传后被旋转的问题
    vi写完文件保存时才发现是readonly😂
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/5834653.html
Copyright © 2011-2022 走看看