libavcodec ve libavformat ile video bilgilerini öğrenmek

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

#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;
}

Örnek kod

Vigenere Şifrelemesi (Vigenere Cipher)

180px-Vigenere.jpg

Vigenere Şifreleme tekniği, 16. yüzyılda Fransa 3. Henry Kraliyet üyesi Blaise de Vigenere tarafından bulunmuştur. Burada birbiri yerine kullanılacak harfleri belirlemek için Vigenere Tablosu kullanılır. İngiliz Alfabesi için Tablo 26×26 boyutlarındadır.

180px-Confederate_cipher_disk.jpg

Şifreleme bir anahtar kullanılarak yapılır ve anahtardaki harfler tablonun başlık satırında aranır. Buna karşılık düz metindeki harf tablonun başlık sütununda aranır. Bulunan satır ve sütunun kesiştiği yerdeki harf, düz metindeki harfin yerine konarak şifreleme işlemi gerçekleştirilir.

320px-Vigenere-square.jpg

Şöyle bir örnek verebiliriz:

Anahtar kelime :LEMONLEMONLE

Düz Metin :ATTACKATDAWN

Şifreli Metin :LXFOPVEFRNHR

400px-Vigenere_letter_frequencies.PNG

Şifreli metindeki tekrar eden desenler bulunup, bunlar arasındaki uzaklık hesaplanarak anahtar uzunluğu belirlenebilir. Örneğin anahtar uzunluğu N olarak bulunursa, N tane (Anahtardaki harfler birbirinden farklı ise) tek alfabeli Yerine-Koyma şifreleme tekniği kullanıldığı anlaşılır. Bu aşamada artık her bir tek alfabeli şifreli metne, ayrı ayrı, düz metin harflerinin frekans karakteristiklerini kullanan bir saldırı gerçekleştirilebilir.

Vigenere Şifreleme tekniği ilk kez 1854’de Charles Babbage tarafından kırılmıştır. Charles’ın kullandığı frekans analizi yaklaşımı, kripto analistlere bir araç olmuştur.

Visual C++ 6 Proje dosyaları – Gozat

C# – Gözat

Kaynaklar :

http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher
http://ab.org.tr/ab05/tammetin/22.doc

-- Genel | 239 Kelime | Yorum

write in C :)

WRITE IN C
(sung to The Beatles “Let it Be”)

When I find my code in tons of trouble,
Friends and colleagues come to me,
Speaking words of wisdom:
“Write in C.”

As the deadline fast approaches,
And bugs are all that I can see,
Somewhere, someone whispers”
“Write in C.”

Write in C, write in C,
Write in C, write in C.
LISP is dead and buried,
Write in C.

I used to write a lot of FORTRAN,
for science it worked flawlessly.
Try using it for graphics!
Write in C.

If you’ve just spent nearly 30 hours
Debugging some assembly,
Soon you will be glad to
Write in C.

Write in C, write in C,
Write In C, yeah, write in C.
Only wimps use BASIC.
Write in C.

Write in C, write in C,
Write in C, oh, write in C.
Pascal won’t quite cut it.
Write in C.

Guitar Solo

Write in C, write in C,
Write in C, yeah, write in C.
Don’t even mention COBOL.
Write in C.

And when the screen is fuzzy,
And the edior is bugging me.
I’m sick of ones and zeroes.
Write in C.

A thousand people people swear that T.P.
Seven is the one for me.
I hate the word PROCEDURE,
Write in C.

Write in C, write in C,
Write in C, yeah, write in C.
PL1 is 80’s,
Write in C.

Write in C, write in C,
Write in C, yeah, write in C.
The government loves ADA,
Write in C.