레이블이 ffmpeg인 게시물을 표시합니다. 모든 게시물 표시
레이블이 ffmpeg인 게시물을 표시합니다. 모든 게시물 표시

2015년 10월 11일 일요일

mp4 save with ffmpeg

ip cam -> raw data(encoded) -> mp4 save

  AVCodec *ce;
  AVFormatContext *fc;
  AVOutputFormat *of;
  AVCodecContext *pcc;
  AVStream *pst;
  int vi;
  AVPacket pkt;

BOOL CCodec_Encoder_h264::FileInit(char *fname, int nWidth, int nHeight)
{
av_register_all();
avcodec_register_all();

of = av_guess_format(0, fname, 0);
fc = avformat_alloc_context();
fc->oformat = of;
strcpy(fc->filename, fname);

pst = avformat_new_stream(fc, 0);
vi = pst->index;

ce = avcodec_find_decoder(CODEC_ID_H264);

pcc = pst->codec;
avcodec_get_context_defaults3(pcc, ce);
pcc->codec_type = AVMEDIA_TYPE_VIDEO;
pcc->codec_id = CODEC_ID_H264;
pcc->profile= FF_PROFILE_H264_BASELINE;
pcc->bit_rate = 1280 * 960 * 2;
pcc->width = nWidth;
pcc->height = nHeight;
pcc->time_base.num = 1;
pcc->time_base.den = 30;
pcc->qcompress = 0.6;
pcc->qmin = 0;
pcc->qmax = 9;
pcc->pix_fmt = PIX_FMT_YUV420P;
pcc->gop_size = 150;

if ( !( fc->oformat->flags & AVFMT_NOFILE ) )
avio_open( &fc->pb, fc->filename, AVIO_FLAG_WRITE );

avformat_write_header(fc, NULL);

m_nFrmCnt = 0;

waitkey = 1;

return TRUE;
}

BOOL CCodec_Encoder_h264::FileAppend(BYTE *pData, int nSize, , DWORD key)
{
  AVPacket pkt;
  av_init_packet(&pkt);
  //pkt.flags |= (0 >= getVopType(pData, nSize )) ? AV_PKT_FLAG_KEY : 0;  
  pkt.flags |= key;
  //pkt.stream_index = m_nFrmCnt++;
  pkt.data = (uint8_t*)pData;
  pkt.size = nSize;

if ( waitkey )
if ( 0 == ( pkt.flags & AV_PKT_FLAG_KEY ) )
return TRUE;
else
waitkey = 0;

av_write_frame(fc, &pkt);

return TRUE;
}

BOOL CCodec_Encoder_h264::FileClose()
{
av_write_trailer(fc);

if ( fc->oformat && !( fc->oformat->flags & AVFMT_NOFILE ) && fc->pb )
        avio_close( fc->pb );

av_free(fc);

return TRUE;
}

2015년 7월 21일 화요일

simple rtsp by ffmpeg

vi /etc/ffserver.conf
HTTPPort 7000
RTSPPort 7001
BindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 1000

<Feed test.ffm>
        File /tmp/test.ffm
        FileMaxSize 1M
</Feed>

<Stream test.h264>
        Feed test.ffm
        Format rtp

        VideoSize 640x480
        VideoFrameRate 5
        #VideoBitrate 800
        #VideoBufferSize 40
        #VideoCodec libx264

        NoAudio

        MulticastAddress 239.255.0.1
        MulticastPort 20001
        MulticastTTL 4
        Metadata title "test"
</Stream>

<Stream test.rtsp>
        Feed test.ffm
        Format rtp
        VideoSize 640x480
        NoAudio
        Metadata title "test"
</Stream>

<Stream stat.html>
        Format status
        ACL allow 192.168.0.0 192.168.0.255
</Stream>

## rtsp start
ffserver

## input
ffmpeg -re -i ./source.mp4 -vcodec copy -acodec copy http://rtspip:7000/test.ffm

## recv renderring
rtsp://rtspip:7001/test.rtsp

## status check
http://rtspip:7000/stat.html

## ffmpeg info
ffserver version git-2015-05-25-e48a9ac Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-11)
  configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --pkg-config-flags=--static --enable-gpl --enable-nonfree --enable-libfreetype --enable-libx264
  libavutil      54. 23.101 / 54. 23.101
  libavcodec     56. 40.100 / 56. 40.100
  libavformat    56. 33.101 / 56. 33.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100

2015년 5월 26일 화요일

ffmpeg


FFmpeg provides various tools:
  • ffmpeg is a command line tool to convert multimedia files between formats.
  • ffserver is a multimedia streaming server for live broadcasts.
  • ffplay is a simple media player based on SDL and the FFmpeg libraries.
  • ffprobe is a is a simple multimedia stream analyzer.
and developers libraries:
  • libavutil is a library containing functions for simplifying programming, including random number generators, data structures, mathematics routines, core multimedia utilities, and much more.
  • libavcodec is a library containing decoders and encoders for audio/video codecs.
  • libavformat is a library containing demuxers and muxers for multimedia container formats.
  • libavdevice is a library containing input and output devices for grabbing from and rendering to many common multimedia input/output software frameworks, including Video4Linux, Video4Linux2, VfW, and ALSA.
  • libavfilter is a library containing media filters.
  • libswscale is a library performing highly optimized image scaling and color space/pixel format conversion operations.
  • libswresample is a library performing highly optimized audio resampling, rematrixing and sample format conversion operations.

2015년 5월 23일 토요일

install ffmpeg on centos

install with yum

vi /etc/yum.repos.d/dag.repo

[dag]
name=DAG RPM Repository
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1

save


rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt

yum search ffmpeg

yum install ffmpeg ffmpeg-devel ffmpeg-libpostproc


[root@localhost ~]# ffmpeg -version
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
  built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
  configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdc1394 --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libx264 --enable-gpl --enable-nonfree --enable-postproc --enable-pthreads --enable-shared --enable-swscale --enable-vdpau --enable-version3 --enable-x11grab
  libavutil     50.15. 1 / 50.15. 1
  libavcodec    52.72. 2 / 52.72. 2
  libavformat   52.64. 2 / 52.64. 2
  libavdevice   52. 2. 0 / 52. 2. 0
  libavfilter    1.19. 0 /  1.19. 0
  libswscale     0.11. 0 /  0.11. 0
  libpostproc   51. 2. 0 / 51. 2. 0
FFmpeg 0.6.5
libavutil     50.15. 1 / 50.15. 1
libavcodec    52.72. 2 / 52.72. 2
libavformat   52.64. 2 / 52.64. 2
libavdevice   52. 2. 0 / 52. 2. 0
libavfilter    1.19. 0 /  1.19. 0
libswscale     0.11. 0 /  0.11. 0
libpostproc   51. 2. 0 / 51. 2. 0


manual install

yum install autoconf automake cmake freetype-devel gcc gcc-c++ git libtool make mercurial nasm pkgconfig zlib-devel

mkdir ~/ffmpeg_sources

cd ~/ffmpeg_sources
git clone --depth 1 git://github.com/yasm/yasm.git
cd yasm
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install
make distclean

cd ~/ffmpeg_sources
git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git
cd libvpx
./configure --prefix="$HOME/ffmpeg_build" --disable-examples
make
make install
make clean

cd ~/ffmpeg_sources
git clone --depth 1 git://git.videolan.org/x264
cd x264
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
make
make install
make distclean

cd ~/ffmpeg_sources
git clone --depth 1 git://source.ffmpeg.org/ffmpeg
cd ffmpeg
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --pkg-config-flags="--static" --enable-gpl --enable-nonfree --enable-libfreetype --enable-libvpx --enable-libx264
make
make install
make distclean
hash -r

[root@localhost ffmpeg]# ffmpeg -version
ffmpeg version git-2015-05-25-e48a9ac Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-11)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --pkg-config-flags=--static --enable-gpl --enable-nonfree --enable-libfreetype --enable-libx264
libavutil      54. 23.101 / 54. 23.101
libavcodec     56. 40.100 / 56. 40.100
libavformat    56. 33.101 / 56. 33.101
libavdevice    56.  4.100 / 56.  4.100
libavfilter     5. 16.101 /  5. 16.101
libswscale      3.  1.101 /  3.  1.101
libswresample   1.  1.100 /  1.  1.100
libpostproc    53.  3.100 / 53.  3.100

2015년 3월 17일 화요일

how to ffmpeg install for ubuntu 14

사실 인터넷에 많은 자료 들이 있지만, 자신의 환경과 일치하는 버전와 tip 을 사용해야 한다

본 문서 작성 당시, ubuntu14.04.1, ffmpeg-2.61, sdl2-2.0.3  을 사용하는데, ffmpeg, sdl2 은 수 많은 외부 라이브러리들이 사용되므로, 구조적으로 함수들이 재정의 되거나, 없어지거나, 새로 만들어지는 경우가 허다 하다

인터넷 자료들은 믿을만한 내용을 찾기가 쉽지 않다

배포사 사이트에서 guide 를 찾는 것이 가장 현명 하다

https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu

위의 url 을 참조하는 것이 좋으며, ffmpeg 빌드만 아래 내용을 참조한다. 아직 sdl2 와 호환 되지 않는 부분이 있어, makefile 만들기가 만만치 않다

cd ~/ffmpeg_sources
wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xjvf ffmpeg-snapshot.tar.bz2
cd ffmpeg
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-nonfree
PATH="$HOME/bin:$PATH" make
make install
make distclean
hash -r

이것 저것 넣었다가 빼보고 테스트 하느라, 누락 된 부분이 있을 수 있어, 추후 ubuntu 초기화 하고 다시 정리해야 한다 ( remind )
libsdl1.2-dev : 현재 ubuntu bug 로 설치가 되지 않는다 ( remind )