利用pkf-config重写ffplay

声明:转载自 blog.fpzeng.com

1.首先写Makefile,由于ffmpeg提供了很多动态库,你首先需要指定gcc编译、链接的参数,这个可以用pkg-config命令来获取。

# use pkg-config for getting CFLAGS and LDLIBS
FFMPEG_LIBS=    libavformat                        \
                libavcodec                         \
                libavutil
 
CFLAGS += -Wall -O2 -g
CFLAGS += $(shell pkg-config --cflags $(FFMPEG_LIBS))
LDLIBS += $(shell pkg-config --libs $(FFMPEG_LIBS))
EXAMPLES=       player                  \
 
OBJS=$(addsuffix .o,$(EXAMPLES))
 
# the following examples make explicit use of the math library
#main:            LDLIBS += -lm
 
%: %.o
    $(CC) $< $(LDLIBS) -o $@
 
%.o: %.c
    $(CC) $< $(CFLAGS) -c -o $@
 
.phony: all help show clean
 
all: $(OBJS) $(EXAMPLES)
help:
    @echo "Makefile for ffmpeg and SDL Programs version 1.0"
    @echo "Copyright (C) 2012 Franken <zfpnuc@hotmail.com>"
    @echo "Usage: make [TARGET]"
    @echo "TARGETS:"
    @echo "  all       (=make) compile and link."
    @echo "  clean     clean objects and the executable file." 
    @echo "  show      show variables (for debug use only)."
    @echo "  help      print this message."
    @echo ""
    @echo "Report bugs to <zfpnuc@hotmail.com>."
show:  
    @echo "CFLAGS           :" $(CFLAGS)
    @echo "LDLIBS           :" $(LDLIBS)
clean:
    rm -rf $(EXAMPLES) $(OBJS)

2.然后再写一个最小的函数测试一下

#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
int main(int argc, char *argv[]) {
    av_register_all();
}

3.使用make 可以编译,make show 可以看装载了哪些信息

4.这是一个带有debug信息的版本

5.更详细的例子(获取视频播放文件时长)

#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/avstring.h"
 
void print_error(const char *filename, int err)
{
    char errbuf[128];
    const char *errbuf_ptr = errbuf;
  
    if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
        errbuf_ptr = strerror(AVUNERROR(err));
    av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
}
void print_duration(int seconds)
{
    av_log(NULL,0,"duration [hh]:[mm]:[ss] %02d:%02d:%02d\n",\
    seconds/60/60,seconds/60%60,seconds%60);
}
int main(int argc, char *argv[])
{
    int ret=0;
    AVFormatContext *ic = NULL;
    char filename[1024];
    AVInputFormat *iformat = NULL;
    AVDictionary *format_opts = NULL;
    AVDictionaryEntry *t;
    int err;
    av_strlcpy(filename, argv[1], sizeof(filename));
 
    av_register_all();
 
    err = avformat_open_input(&ic, filename, iformat, &format_opts);
    if (err < 0) {
        print_error(filename, err);
        ret = -1;
        goto fail;
    }
    print_duration(ic->duration/1000/1000);
  fail:
    if (ic) {
        avformat_close_input(&ic);
    }
    return ret;
}

备注:

1. http://blog.fpzeng.com/index.php/2012/05/ffplayer-2/

2.http://blog.fpzeng.com/index.php/2012/05/sdl/

 

转载于:https://www.cnblogs.com/ohmytime/archive/2013/03/25/ffplay_pkg-config.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值