안녕하세요. dranger의 ffmpeg tutorial을 컴파일 하는과정에서 생긴 오류에 대해 궁금증이 있어서 글남깁니다.
안녕하세요. 이번에 linux 위에서 ffmpeg을 이용해 스트리밍을 받아들여 openCV로 라인트레이서를 구현하는 프로젝트를 하게 되었습니다.
동영상이나 코덱 부분에서 아는 것이 없어서, 구글링을 통해 하나하나 해결하고 있는데, 도저히 정보가 안나와서 질문드립니다.
정보를 찾아보는 중 ffmpeg라이브러리를 이용하는데 dranger의 tutorial이 좋다는 정보를 듣고 소스코드를 받아서 컴파일 하였습니다만
에러가 우수수 뜨더군요 ㅜㅜ
ffmpeg , libx264컴파일은 http://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide 싸이트를 참조하였습니다.
//--------------------------------------------------------------------------------------------------------------------------
xogml@xogml-desktop:~$ ffmpeg -codecs | grep h264
ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers
built on Jul 24 2014 15:05:26 with gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
configuration: --prefix=/home/xogml/ffmpeg_build --extra-cflags=-I/home/xogml/ffmpeg_build/include --extra-ldflags=-L/home/xogml/ffmpeg_build/lib --bindir=/home/xogml/bin --extra-libs=-ldl --enable-gpl --enable-libx264
libavutil 52. 92.101 / 52. 92.101
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 49.100 / 55. 49.100
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 11.102 / 4. 11.102
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (encoders: libx264 libx264rgb )
//----------------------------------------------------------------------------------------------------------------------------
ffmpeg 컴파일시 --enable-gpl --enable-libx264를 해줬음에도 불구하고
/home/xogml/ffmpeg_build/lib//libavcodec.a(libx264.o): In function `X264_frame':
/home/xogml/ffmpeg_source/ffmpeg/libavcodec/libx264.c:168: undefined reference to `x264_picture_init'
/home/xogml/ffmpeg_source/ffmpeg/libavcodec/libx264.c:170: undefined reference to `x264_bit_depth'
/home/xogml/ffmpeg_source/ffmpeg/libavcodec/libx264.c:188: undefined reference to `x264_encoder_reconfig'
/home/xogml/ffmpeg_source/ffmpeg/libavcodec/libx264.c:194: undefined reference to `x264_encoder_reconfig'
/home/xogml/ffmpeg_source/ffmpeg/libavcodec/libx264.c:201: undefined reference to `x264_encoder_reconfig'
/home/xogml/ffmpeg_source/ffmpeg/libavcodec/libx264.c:221: undefined reference to `x264_encoder_reconfig'
/home/xogml/ffmpeg_source/ffmpeg/libavcodec/libx264.c:261: undefined reference to `x264_encoder_reconfig'
/home/xogml/ffmpeg_source/ffmpeg/libavcodec/libx264.c:266: undefined reference to `x264_encoder_encode'
/home/xogml/ffmpeg_source/ffmpeg/libavcodec/libx264.c:214: undefined reference to `x264_encoder_reconfig'
/home/xogml/ffmpeg_source/ffmpeg/libavcodec/libx264.c:207: undefined reference to `x264_encoder_reconfig'
/home/xogml/ffmpeg_source/ffmpeg/libavcodec/libx264.c:272: undefined reference to `x264_encoder_delayed_frames'
/home/xogml/ffmpeg_source/ffmpeg/libavcodec/libx264.c:266: undefined reference to `x264_encoder_encode'
/home/xogml/ffmpeg_source/ffmpeg/libavcodec/libx264.c:227: undefined reference to `x264_encoder_reconfig'
//--------------------------------------------------------------------------------------------------------------------------------
이런 error 메세지가 우수수 발생합니다.
해당 C 파일과 Makefile은 첨부파일에 추가하였습니다.
어떻게 해결해야 할까요 ㅜㅜ
소스코드입니다.
// tutorial01.c // Code based on a tutorial by Martin Bohme (boehme@inb.uni-luebeckREMOVETHIS.de) // Tested on Gentoo, CVS version 5/01/07 compiled with GCC 4.1.1 // A small sample program that shows how to use libavformat and libavcodec to // read video from a file. // // Use // // gcc -o tutorial01 tutorial01.c -lavutil -lavformat -lavcodec -lz // // to build (assuming libavformat and libavcodec are correctly installed // your system). // // Run using // // tutorial01 myvideofile.mpg // // to write the first five frames from "myvideofile.mpg" to disk in PPM // format. #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libswscale/swscale.h> #include <stdio.h> void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame) { FILE *pFile; char szFilename[32]; int y; // Open file sprintf(szFilename, "frame%d.ppm", iFrame); pFile=fopen(szFilename, "wb"); if(pFile==NULL) return; // Write header fprintf(pFile, "P6\n%d %d\n255\n", width, height); // Write pixel data for(y=0; y<height; y++) fwrite(pFrame->data[0]+y*pFrame->linesize[0], 1, width*3, pFile); // Close file fclose(pFile); } int main(int argc, char *argv[]) { AVFormatContext *pFormatCtx; int i, videoStream; AVCodecContext *pCodecCtx; AVCodec *pCodec; AVFrame *pFrame; AVFrame *pFrameRGB; AVPacket packet; int frameFinished; int numBytes; uint8_t *buffer; if(argc < 2) { printf("Please provide a movie file\n"); return -1; } av_register_all(); if(av_open_input_file(&pFormatCtx, argv[1], NULL, 0, NULL)!=0) return -1; // Couldn't open file if(av_find_stream_info(pFormatCtx)<0) return -1; // Couldn't find stream information dump_format(pFormatCtx, 0, argv[1], 0); // Find the first video stream //pFormatCtx->stream 스트림의 데이터에 접근하는 포인터배열 //pFormatCtx->nb_stream 스트림의 크기. videoStream=-1; for(i=0; i<pFormatCtx->nb_streams; i++) if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) { videoStream=i; break; } if(videoStream==-1) return -1; // Didn't find a video stream // Get a pointer to the codec context for the video stream pCodecCtx=pFormatCtx->streams[videoStream]->codec; // Find the decoder for the video stream pCodec=avcodec_find_decoder(pCodecCtx->codec_id); if(pCodec==NULL) { fprintf(stderr, "Unsupported codec!\n"); return -1; // Codec not found } // Open codec if(avcodec_open2(pCodecCtx, pCodec,NULL)<0) return -1; // Could not open codec // codec을 찾아서 연다. // Allocate video frame // 프레임을 저장할 장소 선언. pFrame=avcodec_alloc_frame(); // Allocate an AVFrame structure pFrameRGB=avcodec_alloc_frame(); if(pFrameRGB==NULL) return -1; //-------------------------------------------------------------------------------- // Determine required buffer size and allocate buffer numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height); buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t)); //-------------------------------------------------------------------------------- // Assign appropriate parts of buffer to image planes in pFrameRGB // Note that pFrameRGB is an AVFrame, but AVFrame is a superset // of AVPicture avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height); // Read frames and save first five frames to disk i=0; while(av_read_frame(pFormatCtx, &packet)>=0) { // Is this a packet from the video stream? if(packet.stream_index==videoStream) { // Decode video frame avcodec_decode_video(pCodecCtx, pFrame, &frameFinished, packet.data, packet.size); // Did we get a video frame? if(frameFinished) { // Convert the image from its native format to RGB img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24, (AVPicture*)pFrame, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height); // Save the frame to disk if(++i<=5) SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, i); } } // Free the packet that was allocated by av_read_frame av_free_packet(&packet); } //----------------------------------------------------------------------------------- // Free the RGB image av_free(buffer); av_free(pFrameRGB); // Free the YUV frame av_free(pFrame); // Close the codec avcodec_close(pCodecCtx); // Close the video file av_close_input_file(pFormatCtx); return 0; }
Makefile 입니다.
CC = gcc TARGET = ffmpeg_tutorial OBJ = tutorial01_internet_ver.c LIBS = -L/home/xogml/ffmpeg_build/lib/ -lavformat -lavcodec -lavutil -lswscale INCLUDE_PATH1 = -I/home/xogml/ffmpeg_source/ffmpeg INCLUD_PATH2 = -I/home/xogml/ffmpeg_build/include INCLUDE_PATH3 = -I/home/xogml/ffmpeg_build/include FLAGS = -lz -lm $(TARGET): $(CC) -o $(TARGET) $(OBJ) $(INCLUDE_PATH2) $(INCLUDE_PATH1) $(LIBS) $(FLAGS)
첨부 | 파일 크기 |
---|---|
tutorial.tar | 10 KB |
댓글 달기