티스토리 뷰
728x90
출처 : Record RTSP stream with FFmpeg libavformat
Android NDK FFmpeg 컴파일 강좌 (1/4)
환경
wowza 2.2.4, ffmpeg-0.10.3, cygwin, windows 7
압축풀기
$ tar xvfz ffmpeg-0.10.3.tar.gz
configure
config.sh 파일
export TMPDIR=c:/ffmpegtmp ./configure --disable-doc \ --disable-ffmpeg \ --disable-ffplay \ --disable-ffprobe \ --disable-ffserver \ --disable-avdevice \ --disable-devices \ --disable-filters \ --disable-yasm \ --enable-network \ --enable-protocol=tcp \ --enable-demuxer=rtsp \ --enable-decoder=h264
$ ./config.sh
$ make
testmain.c
#include <stdio.h> #include <stdlib.h> #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libavformat/avio.h> int main(int argc, char** argv) { AVFormatContext* context = avformat_alloc_context(); int video_stream_index; av_register_all(); avcodec_register_all(); avformat_network_init(); //if(avformat_open_input(&context, "rtmp://192.168.0.40/vod/sample.mp4",NULL,NULL) != 0){ //if(avformat_open_input(&context, "d:\\windows\\b.mp4",NULL,NULL) != 0){ //open rtsp if(avformat_open_input(&context, "rtsp://192.168.0.40/vod/mp4:sample.mp4",NULL,NULL) != 0){ return EXIT_FAILURE; } if(avformat_find_stream_info(context,NULL) < 0){ return EXIT_FAILURE; } //search video stream int i; for(i =0;i<context->nb_streams;i++){ if(context->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) video_stream_index = i; } AVPacket packet; av_init_packet(&packet); //open output file AVOutputFormat* fmt = av_guess_format(NULL,"test2.avi",NULL); AVFormatContext* oc = avformat_alloc_context(); oc->oformat = fmt; avio_open2(&oc->pb, "test.avi", AVIO_FLAG_WRITE,NULL,NULL); AVStream* stream=NULL; int cnt = 0; //start reading packets from stream and write them to file av_read_play(context);//play RTSP while(av_read_frame(context,&packet)>=0 && cnt <100){//read 100 frames if(packet.stream_index == video_stream_index){//packet is video if(stream == NULL){//create stream in file stream = avformat_new_stream(oc,context->streams[video_stream_index]->codec->codec); avcodec_copy_context(stream->codec,context->streams[video_stream_index]->codec); stream->sample_aspect_ratio = context->streams[video_stream_index]->codec->sample_aspect_ratio; avformat_write_header(oc,NULL); } packet.stream_index = stream->id; av_write_frame(oc,&packet); cnt++; } av_free_packet(&packet); av_init_packet(&packet); } av_read_pause(context); av_write_trailer(oc); avio_close(oc->pb); avformat_free_context(oc); return (EXIT_SUCCESS); }
Makefile
TARGET = hello2 FFMPEGDIR = /home/bluesanta/ffmpeg-0.10.3 LIBDIR = /lib CC = gcc AR = ar LD = ld NM = nm RANLIB = ranlib STRIP = strip INCLUDE = -I$(FFMPEGDIR) CFLAGS = -Wall LDFFMPEG = -L$(FFMPEGDIR)/libavformat -L$(FFMPEGDIR)/libavcodec -L$(FFMPEGDIR)/libavutil LDFLAGS = -L$(LIBDIR) $(LDFFMPEG) -lavformat -lavcodec -lavutil -lkernel32 -lcygwin -lm -lgcc -lc # application file APPSOURCES = testmain.c APPOBJS = $(APPSOURCES:.c=.o) # define the rule .SUFFIXES:.c .o .c.o: @echo Compiling: $< $(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $< all: app app: $(APPOBJS) @echo Linking: $(TARGET) $(CC) -o $(TARGET) $(APPOBJS) $(LDFLAGS) $(STRIP) -s $(TARGET) clean: @rm -vf $(APPOBJS) $(TARGET)
컴파일, 실행
댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- KOBA
- 전예희
- 튜닝쇼 2008
- NDK
- 일본여행
- SAS
- 레이싱모델 익스트림 포토 페스티벌
- 서울오토살롱
- Delphi Tip
- ffmpeg
- flex
- 동경
- koba2010
- BPI-M4
- ble
- ubuntu
- Spring MVC
- android
- sas2009
- Java
- Mac
- oracle
- Xcode
- MySQL
- Linux
- Delphi
- JavaScript
- 지스타2007
- 송주경
- Spring
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함