libavcodec,libavformat  free software/open source LGPL-lisanslı ffmpeg tarafından kullanılan codec çözme / işleme kütüphanesidir.
Ubuntu – Debian altında örnek kodu derleyebilmek için gerekli paketler :
$ sudo apt-get install libavcodec-dev libavformat-dev
Derlemek için :
g++ avf.cpp -I/usr/include/libavcodec -I/usr/include/libavformat -lavformat -lavcodec -L/usr/lib/libavformat.so -L/usr/lib/libavcodec.so -o avf
Örnek Kullanım :
./avf test.mp4
Çıktı :
Video codec    : mp42
Width     : 1920
Height     : 1080
Duration   : 300
Audio codec   : aac
Audio channels   : 2
Audio samplerate  : 44100
Audio bitrate   : 128
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
#ifndef INT64_C #define INT64_C(c) (c ## LL) #define UINT64_C(c) (c ## ULL) #endif extern "C" { #include <avcodec.h> #include <avformat.h> } #include <stdio.h> #include <stdlib.h> #include <iostream> //g++ avf.cpp -I/usr/include/libavcodec -I/usr/include/libavformat -lavformat -lavcodec -L/usr/lib/libavformat.so -L/usr/lib/libavcodec.so -o avf using namespace std; int main(int argc, char *argv[]) { av_log_set_level(0); av_register_all(); AVFormatContext *pFormatCtx; const char *filename=argv[1]; // Open video file if(av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL)!=0) { cout < < "can't open file" << endl; exit(-1); } // Retrieve stream information if(av_find_stream_info(pFormatCtx)<0) { cout << "can't get stream info" << endl; exit(-1); } //dump_format(pFormatCtx, 0, filename, false); int i, videoStream; AVCodecContext *pCodecCtx; //http://ffmpeg.org/doxygen/0.6/structAVCodecContext.html AVCodecContext *pCodecCtx2; pCodecCtx=pFormatCtx->streams[0]->codec; pCodecCtx2=pFormatCtx->streams[1]->codec; AVCodec* vCodec;//http://ffmpeg.org/doxygen/0.6/structAVCodec.html AVCodec* aCodec; vCodec=avcodec_find_decoder(pCodecCtx->codec_id); aCodec=avcodec_find_decoder(pCodecCtx2->codec_id); cout < < "Video codec : " << vCodec->name < < endl; cout << "Width : " << pCodecCtx->width < < endl; cout << "Height : " << pCodecCtx->height < < endl; cout << "Duration : " << pFormatCtx->duration < < endl; //cout << "codec id : " << (int)pCodecCtx2 << endl; cout << "Audio codec : " << aCodec->name < < endl; cout << "Audio channels : " << pCodecCtx2->channels < < endl; cout << "Audio samplerate : " << pCodecCtx2->sample_rate < < endl; cout << "Audio bitrate : " << pCodecCtx2->bit_rate < < endl; avcodec_close(pCodecCtx); avcodec_close(pCodecCtx2); av_close_input_file(pFormatCtx); return 0; } |