You are on page 1of 56

Multimedia

A Fourth Year Course


For
CS and IT Students
Multimedia

Chapter 1 Intro.: Multimedia Systems & Components

Chapter 2 Text: Fonts – Hypertext – Arithmetic Coding

Chapter 3 Audio: Digital Audio – Audio Coding – Editing

Chapter 4 Image: Digital Cameras – Image Compression – Editing

Chapter 5,6 Video: Digital Video - Video Coding – Video Editing

Chapter 7 Media Delivery: Multimedia & Networks – QoS


Data Compression
Organizing Files for Performance
‫ضغط البيانات‬
‫• ضغط البيان‪+‬ات أو مص در الترم يز ‪ Data compression‬في عل وم‬
‫الحاس وب والمعلوم ات النظري ة‪ ،‬ه و عملي ة تكوي د المعلوم ات بحيث‬
‫تأخذ حيزا اقل من المساحة‬
‫• مميزاته‬
‫‪ .1‬تشغل البيانات بعد الضغط مساحة اقل فى الذاكرة‬
‫‪ .2‬يتم نقل البيانات بعد الضغط بشكل اسرع‬
‫‪ .3‬معالجة البيانات بشكل اسرع‬
Organizing Files for Performance
Organizing Files for Performance
‫أنواع ضغط البيانات‬
‫الص نف ض غط البيان ات غ ير المنق وص (‪)Lossless Compression :‬‬ ‫‪.1‬‬
‫طريقة ضغط بيانات تضغط ملف ًا من خالل تسجيل البيانات التي تحتوي عليها‬
‫و ال ت ؤدي طريق ة الض غط ه ذه إلى خس ارة أي بيان ات أص لية عن د إلغ اء‬
‫الضغط‪.‬‬
‫ضغط البيان ات المنق وص ‪ Lossy Compression‬أي طريق ة ض غط‬ ‫‪.2‬‬
‫بيان ات تض غط ملف ًا من خالل تجاه ل أي بيان ات تق رر أنه ا غ ير ض رورية‪.‬‬
‫استعمل الضغط المنقوص لتقليص ملفات األصوات أو الصور إذا كانت الدقة‬
‫المطلقة غير مطلوبة وإذا كانت خسارة بعض البيانات ال يمكن مالحظتها‪.‬‬

‫كل عملية ضغط تقابلها عملية فك معاكسة‪.‬‬ ‫•‬


‫درج ة الض غط = ( حجم البيان ات قب ل الض غط – حجم البيان ات بع د الض غط ) ‪/‬‬ ‫•‬
‫حجم البيانات بعد الضغط‬

‫‪8‬‬
Organizing Files for Performance
Organizing Files for Performance
Organizing Files for Performance
Organizing Files for Performance
Organizing Files for Performance
‫‪RLE‬‬
‫طريقة‪RLE‬‬
‫طريقة‬
‫بط‪+‬ول‬ ‫الترم‪+‬يز‬ ‫تع‪+‬ني‬ ‫و‬ ‫‪Run‬‬ ‫‪Length‬‬ ‫‪Encoding‬‬
‫• هي اختص ار ل ‪ Run Length Encoding‬و تع ني الترم يز بط ول‬ ‫ل‬ ‫اختص‪+‬ار‬ ‫هي‬ ‫•‬
‫التعداد‪.‬‬
‫التعداد‪.‬‬
‫الالمصدري‪.‬‬ ‫الصنف‬ ‫من‬ ‫و‬ ‫فاقدة‬ ‫غير‬ ‫ضغط‬ ‫طريقة‬ ‫••‬
‫طريق ة ض غط غ ير فاق دة ومن أبس ط و أس هل الط رق وس ريعة و هي‬
‫بكثرة‪.‬ن‪+‬وع ال‪+‬ذي يتك‪+‬رر‬
‫الواحدس‪+‬بة لل‬
‫‪Bytes‬هي منا‬
‫ال‪+‬ريعة و‬
‫‪+‬رقفيهوس‬ ‫‪+‬هل الط‬
‫يتكرر‬ ‫للنوع أس‬
‫الذي‬ ‫• من أب‬
‫مناسبةس‪+‬ط و‬
‫تبديل سلسلة من ال ‪ Bytes‬أو من البيانات‬ ‫علىبكثرة‪.‬‬ ‫الواحد‬ ‫‪Bytes‬‬
‫الطريقة‬ ‫تعتمدالهذه‬
‫• فيه‬
‫إحداها‪.‬س‪+‬لة من ال ‪ Bytes‬أو من البيان‪+‬ات‬‫تاركة‪+‬ديل سل‬
‫تكرارهاعلى تب‬
‫بعددالطريق‪+‬ة‬ ‫• تعتم‪+‬د‬
‫المتكررةه‪+‬ذه‬
‫إحداها‪.‬وي المل ف على سالس ل بط ول‬ ‫تاركةدما يحت‬
‫تكرارهاط عن‬
‫بعددفعال ة فق‬ ‫المتكررة‬
‫الطريق ة‬ ‫• هذه‬
‫‪+‬ول‬ ‫من بط‪+‬‬
‫ثالث‬ ‫سالس‪++‬ل‬
‫على أك ثر‬ ‫الملا‪++‬ف‬
‫الرم ز‬ ‫‪+‬ويفيه‬
‫يحت‪+‬رر‬ ‫عن‪++‬طثالثعن‪+‬ة‪+‬دما‬
‫أي يتك‬ ‫فعال‪+‬د‪+‬ة فق‬
‫‪+‬ة يزي‬
‫منه‪ +‬ا‬
‫الطريق‬ ‫• هذه‬
‫الواح دة‬
‫الواح‪++‬دة منه‪++‬ا يزي‪++‬د عن ثالث‪++‬ة أي يتك‪++‬رر فيه‪++‬ا الرم‪++‬ز أك‪++‬ثر من ثالث‬ ‫مرات‪.‬‬
‫مناس بة ج دًا إذا ك ثرت السالس ل من البيان ات المتك ررة في المل ف‬ ‫مرات‪.‬‬ ‫• هي‬
‫الواحدمناس‪+‬بة ج‪+‬دًا إذا ك‪+‬ثرت السالس‪+‬ل من البيان‪+‬ات المتك‪+‬ررة في المل‪+‬ف‬ ‫• هي‬
‫الواح‪+‬د‪ ,‬مث‪+‬ل الص‪+‬ور ال‪+‬تي تحت‪+‬وي الكث‪+‬ير من البي‪+‬اض أو ص‪+‬فحة فيه‪+‬ا‬
‫الكثير من الفراغات‪.‬‬
‫• تدعم نماذج ‪ PDF‬و ‪. TIFF‬‬
‫‪14‬‬
‫‪14‬‬
Organizing Files for Performance
Organizing Files for Performance
Purpose of Huffman Coding

• Proposed by Dr. David A. Huffman in 1952


– “A Method for the Construction of Minimum
Redundancy Codes”
• Applicable to many forms of data
transmission
– Our example: text files
The Basic Algorithm
• Huffman coding is a form of statistical coding
• Not all characters occur with the same
frequency!
• Yet all characters are allocated the same amount
of space
– 1 char = 1 byte, be it e or x
The Basic Algorithm

• Any savings in tailoring codes to frequency of


character?
• Code word lengths are no longer fixed like
ASCII.
• Code word lengths vary and will be shorter
for the more frequently used characters.
The (Real) Basic Algorithm
1. Scan text to be compressed and tally
occurrence of all characters.
2. Sort or prioritize characters based on number of
occurrences in text.
3. Build Huffman code tree based on prioritized
list.
4. Perform a traversal of tree to determine all code
words.
5. Scan text again and create new file using the
Huffman codes.
Building a Tree
Scan the original text

• Consider the following short text:

 Eerie eyes seen near lake.


• Count up the occurrences of all characters in the
text
Building a Tree
Scan the original text
Eerie eyes seen near lake.
• What characters are present?

E e r i space
ysnarlk.
Building a Tree
Scan the original text
Eerie eyes seen near lake.
• What is the frequency of each character in the text?

Char Freq. Char Freq. Char Freq.


E 1 y 1 k 1
e 8 s 2 . 1
r 2 n 2
i 1 a 2
space 4 l 1
Building a Tree
• inserting all nodes

E i y l k . r s n a sp e
1 1 1 1 1 1 2 2 2 2 4 8
Building a Tree

E i y l k . r s n a sp e
1 1 1 1 1 1 2 2 2 2 4 8
Building a Tree

y l k . r s n a sp e
1 1 1 1 2 2 2 2 4 8

E i
Building a Tree

y l k . r s n a sp e
1 1 1 1 2 2 2 2 4 8
E i
Building a Tree

k . r s n a sp e
1 1 2 2 2 2 4 8
E i

y l
Building a Tree

2
k . r s n a 2 sp e
1 1 2 2 2 2 4 8
y l
E i
Building a Tree

r s n a 2 2 sp e
2 2 2 2 4 8
y l
E i

k .
Building a Tree

r s n a 2 2 sp e
2
2 2 2 2 4 8
E i y l k .
Building a Tree

n a 2 sp e
2 2
2 2 4 8
E i y l k .

r s

CS 102
Building a Tree

n a 2 sp e
2 4
2
2 2 4 8

E i y l k . r s
Building a Tree

2 4 e
2 2 sp
8
4
y l k . r s
E i

n a
Building a Tree

2 4 4 e
2 2 sp
8
4
y l k . r s n a
E i
Building a Tree

4 4 e
2 sp
8
4
k . r s n a

2 2

E i y l
Building a Tree

4 4 4
2 sp e
4 2 2 8
k . r s n a

E i y l
Building a Tree

4 4 4
e
2 2 8
r s n a

E i y l

2 sp

k .
Building a Tree

4 4 4 6 e
2 sp 8
r s n a 2 2
k .
E i y l

?What is happening to the characters with a low number of occurrences


Building a Tree

4 6 e
2 2 2 8
sp

E i y l k .
8

4 4

r s n a
Building a Tree

4 6 e 8
2 2 2 8
sp
4 4
E i y l k .
r s n a
Building a Tree

8
e
8
4 4
10
r s n a
4
6
2 2
2 sp
E i y l k .
Building a Tree

8 10
e
8 4
4 4
6
2 2 2
r s n a sp
E i y l k .
Building a Tree

10
16
4
6
2 2 e 8
2 sp
E i y l k . 4 4

r s n a
Building a Tree

10 16

4
6
e 8
2 2
2 sp
4 4
E i y l k .

r s n a
Building a Tree

26

16
10

4 e 8
6
2 2 2 sp 4 4

E i y l k .
r s n a
Building a Tree

26

16
10

4 e 8
6
2 2
2 sp 4 4

E i y l k .
r s n a
Building a Tree
Dequeue the single node left in
the queue.
26

This tree contains the new code 10


16
words for each character.
4 e 8
6
Frequency of root node should 2 2 2 sp 4 4
equal number of characters in
text. E i y l k .
r s n a

Eerie eyes seen near lake.  26 characters


Encoding the File
Traverse Tree for Codes

• Perform a traversal of the


tree to obtain new code
words 26
• Going left is a 0 going right is 16
10
a1
• code word is only completed 4 e 8
6
when a leaf node is reached 2 2 2 sp 4 4
E i y l k .
r s n a
Encoding the File
Traverse Tree for Codes
Char Code
E 0000
i 0001
y 0010 26
l 0011 16
k 0100 10
. 0101 4 e
space 011 6 8

e 10 2 2 2 sp 4 4
r 1100
E i y l k .
s 1101 r s n a
n 1110
a 1111
Encoding the File
• Rescan text and encode file
using new code words Char Code
E 0000
Eerie eyes seen near lake. i 0001
y 0010
l 0011
000010110000011001110001010110110
k 0100
. 0101
100111110101111110001100111111010 space 011
0100101 e 10
r 1100
s 1101
n 1110
a 1111
 Why is there no need for a
separator character?
.
Encoding the File
Results
• Have we made things any
000010110000011001110001010110110
better? 100111110101111110001100111111010
0100101
• 73 bits to encode the text
• ASCII would take 8 * 26 =
208 bits

If modified code used 4 bits per


character are needed. Total bits
4 * 26 = 104. Savings not as great.
Decoding the File

• How does receiver know what the codes are?


• Tree constructed for each text file.
– Considers frequency for each file
– Big hit on compression, especially for smaller files
• Tree predetermined
– based on statistical analysis of text files or file types
• Data transmission is bit based versus byte based
Decoding the File
• Once receiver has tree it
scans incoming bit stream 26

• 0  go left 10
16

• 1  go right 4 e 8
6
2 2 2 sp 4 4

10100011011110111101 E i y l k .
r s n a
111110000110101
‫طريقة هفمان ‪Huffman‬‬
‫اخترعها ديفيد هافمان و هي طريقة غير فاقدة و ال مصدرية‪.‬‬ ‫•‬
‫تعطي أحجامًا مختلفة لكل رمز حسب تردده بالملف الواحد‪.‬‬ ‫•‬
‫ب ‪ 2‬بت نستطيع تمثيل أربعة رموز مختلفة‪ ,‬و بثالثة بت نستطيع تمثيل‬ ‫•‬
‫ثمانية رموز‪.‬‬
‫فمثال إذا أردت أن تمثل خمسة من الرموز المختلفة فسيكون طول الرمز‬ ‫•‬
‫الواحد على األقل ‪ 3‬بت كما في الجدول أدناه‪:‬‬
‫عشري‬ ‫ثنائي‬ ‫الرمز‬
‫‪0‬‬ ‫‪000‬‬ ‫‪A‬‬
‫‪1‬‬ ‫‪001‬‬ ‫‪B‬‬
‫‪2‬‬ ‫‪010‬‬ ‫‪C‬‬
‫‪3‬‬ ‫‪011‬‬ ‫‪D‬‬
‫‪55‬‬
‫‪4‬‬ ‫‪100‬‬ ‫‪E‬‬
‫تابع طريقة هفمان ‪Huffman‬‬
‫• تب‪+‬نى ه‪+‬ذه الطريق‪+‬ة على إعط‪+‬اء الرم‪+‬ز المتك‪+‬رر كث‪+‬يرًا حجم‪ً+‬ا قلي‪+‬ل‪ ,‬و‬
‫الرمز النادر التكرار حجمًا أكبر و ذلك للتوفير بالمساحة الكلية‪.‬‬
‫خطوات هذه الطريقة باختصار هو أنك تقوم‪:‬‬
‫‪ .1‬بترتيب الرموز الواحد تلو اآلخر‪.‬‬
‫‪ .2‬ندون بجانب كل رمز عدد مرات تكراره‪.‬‬
‫‪ .3‬نب‪++‬دأ بجم‪++‬ع الرم‪++‬زين ال‪++‬ذين لهم أق‪++‬ل ع‪++‬دد م‪++‬رات تك‪++‬رار في نقط‪++‬ة‬
‫واحدة‪.‬‬
‫‪ .4‬نض‪+‬ع ‪ 0‬على الف‪+‬رع األق‪+‬ل حجم‪ً+‬ا للنقط‪+‬ة و ‪ 1‬على األك‪+‬بر حجم‪ً+‬ا‪ ,‬و‬
‫إذا تساوى الفرعان فتختار عشوائيًا‪.‬‬
‫• طريق‪+‬ة هفم‪+‬ان مناس‪+‬بة للملف‪+‬ات ال‪+‬تي تحت‪+‬وي نص‪+‬وص و ب‪+‬رامج و‬
‫تس‪+‬تخدم ع‪+‬ادًة في ب‪+‬رامج الض‪+‬غط و هي طريق‪+‬ة داعم‪+‬ة لط‪+‬رق الض‪+‬غط‬
‫‪. Jpeg, Mpeg‬‬
‫‪56‬‬

You might also like