728x90

ffmpeg 라이브러리를 이용해서 wowza서버를 사용하는 rtsp 플레이어를 제작해보았습니다.
소스는 iFrameExtractor 프로젝트에서 파일 오픈하는 부분을 rtsp 주소를 사용했고,
ffmpeg 라이브러리 경로를 따로 설정해서 컴파일 했습니다.

설치한 ffmpeg 라이브러리가 ios용으로 컴파일 되어 있어서
시뮬레이터에서는 테스트 할 수가 없네요.

iFrameExtractor 프로젝트는 ffmpeg 라이브러리만 사용했기 때문에 플레이는 되지만,
속도는 나오지 않습니다. OpenGL ES / SDL 라이브러리 이용해야 될 것 같네요.

출처

How can you pass YUV frames from FFmpeg to OpenGL ES?
TECH TUTORIAL ? HOW TO SETUP A SDL-READY XCODE4 PROJECT
CODEC_TYPE_VIDEO undefined
ffmpeg을 이용한 iOS 동영상 플레이어
<video> 태그를 이용하여 rstp 프로토콜의 스트리밍을 재생하고자 하고싶은데요...
Audio and Video HTML
myoutube or RTSP streaming support on chrome

소스 다운로드

jayrparro / iFrameExtractor

ffmpeg 라이브러리 경로 설정

오류 수정

CODEC_TYPE_VIDEO undefined 발생 한다면,
AVMEDIA_TYPE_VIDEO 로 수정

rtsp 주소 설정
iFrameExtractorAppDelegate.m

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
	//self.video = [[VideoFrameExtractor alloc] initWithVideo:[Utilities bundlePath:@"sophie.mov"]];
    //self.video = [[VideoFrameExtractor alloc] initWithVideo:[Utilities bundlePath:@"oh.mp4"]];
    self.video = [[VideoFrameExtractor alloc] initWithVideo:@"rtsp://192.168.0.13/vod/mp4:sample.mp4"];
	[video release];

	// set output image size
	video.outputWidth = 426;
	video.outputHeight = 320;
	
	// print some info about the video
	NSLog(@"video duration: %f",video.duration);
	NSLog(@"video size: %d x %d", video.sourceWidth, video.sourceHeight);
	
	// video images are landscape, so rotate image view 90 degrees
	[imageView setTransform:CGAffineTransformMakeRotation(M_PI/2)];
    [window makeKeyAndVisible];
}

YUV 데이터 -> RGB 데이터 소스
VideoFrameExtractor.m

-(void)convertFrameToRGB {	
	sws_scale (img_convert_ctx, pFrame->data, pFrame->linesize,
			   0, pCodecCtx->height,
			   picture.data, picture.linesize);	
}

실행


728x90
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) 

컴파일, 실행

728x90

+ Recent posts