MP4 STSD structure - mp4

I doubt in one thing. As described in ISO-14496-12 moov/mvhd/trak/mdia/minf/stbl/stsd should contain format specific box e.g. avc1 box described in ISO-14496-15 or mp42 described in ISO-14496-14. But it also contains fields in VideoSampleDescription from QuickTime Format specification such as 'version', 'revision_level','vendor', etc.
Could anyone explain this issue?

The stsd (Sample Description Box) can be treated like a box that contains other boxes. Each Sample Entry is also just a normal box:
4 bytes - length in total
4 bytes - 4 char code of sample description table (stsd)
4 bytes - version & flags
4 bytes - number of sample entries (num_sample_entries)
[
4 bytes - length of sample entry (len_sample_entry)
4 bytes - 4 char code of sample entry
('len_sample_entry' - 8) bytes of data
] (repeated 'num_sample_entries' times)
(4 bytes - optional 0x00000000 as end of box marker )

Related

iTextSharp BarcodePDF417, how to handle barcode with 2000 characters or more encoded in text

I'm trying to encoding more than 2000 characters in a barcode.
Random random = new Random();
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var text = new string(Enumerable.Repeat(chars, 2000)
.Select(s => s[random.Next(s.Length)]).ToArray());
var barcode = new BarcodePDF417();
barcode.SetText(text);
barcode.GetImage();
When trying to GetImage(), I recieve an Error.
System.ArgumentOutOfRangeException: 'Specified argument was out of the range of valid values. (Parameter 'The text is too big.')'
I understand that there is a Macro version where you can link data. However, the resulting barcode is no longer uniform. I want just 1 scannable barcode. Is this achievable using ITextSharp?
barcode.MacroFileId = "0"
barcode.MacroSegmentId = someIndexinLoop;
barcode.MacroSegmentCount = totalCount;
No, it is not possible within a single PDF417 complaint barcode.
You could use multiple barcodes or a link to more data as suggested, or if you have control over the application that will be reading the barcode then you can employ fancy tricks like short-codes within the barcode that can be expanded to some pre-set string by the application doing the scanning.
The PDF417 specification as shown in the ISO spec, or here does have limits:
PDF417 is capable of encoding more than 1100 bytes, 1800 text
characters or 2710 digits. Large data files can be encoded into a
series of linked PDF417 symbols using a standard methodology referred
to as Macro PDF417.
And there is some great information here:
It is recommended to limit the amount of data in each 2D barcode
symbol to 800 characters or less, using 20 columns or less. Although
the specification states that “up to 1100 bytes or 1800 ASCII
characters can be encoded in a PDF417 symbol,” it is not usually
achievable. The amount of data that can be encoded will vary
depending upon the type of data, the compaction type, the error
correction level chosen and the limitation of the scanner being
used. For example, in text compaction mode, the amount of compaction
varies due to mode switching between different types of
characters, such as between numbers, upper case, lower case and
punctuation. In addition, many PDF417 CCD scanners do not reliably
read more than 800 to 850 characters and some scanners have limits of
only 300 characters.

How to set lease time and server identifier fields in DHCPOFFER packet?

When I see the DHCP RFC at http://www.ietf.org/rfc/rfc2131.txt , it says that lease time and server identifier fields come under options. Which bits in the DHCP packet actually represent these field?
It's not possible to give you a specific byte offset to look at - you have to interpet the "Options" section of the packet. The Options can be given in any order.
Take a look at the definitions of the Options here: http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol#DHCP_options
Options are variable length octet strings. The first octet is the
option code, the second octet is the number of following octets and
the remaining octets are code dependent.
So if you have DHCPOFFER packet to decode, you need to start at the beginning of the Options section (octet offset 812 into the entire DHCPOFFER packet), and interpret each Option (code, length, data) until you reach the end of the packet. Then look at which Option had a code of 51 (lease time) followed by a length octet of value 4 and then 4 octets of data, or 54 (Server identifier) again followed by length 4 and 4 octets of data.

boot loader's size

I am reading brokenthorn.com ‘s O/S development tutorials one of the tutorials, the following code is there.
http://www.brokenthorn.com/Resources/OSDev3.html
I don’t understand why this code clear 510 bytes. org, bits, cli, hlt are there in the code too. Shouldn’t it be changed to less than 510 bytes? Could it be typo or something?
Thanks.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;*********************************************
; Boot1.asm
; - A Simple Bootloader
;
; Operating Systems Development Tutorial
;*********************************************
org 0x7c00 ; We are loaded by BIOS at 0x7C00
bits 16 ; We are still in 16 bit Real Mode
Start:
cli ; Clear all Interrupts
hlt ; halt the system
times 510 - ($-$$) db 0 ; We have to be 512 bytes. Clear the rest of the bytes with 0
dw 0xAA55 ; Boot Signiture
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
It's not clearing 510 bytes, it's clearing 510 - ($-$$) bytes. Since $ is the current position, and $$ is the start of the section, it's clearing 510 - (length of the section up to that point) bytes.
This will fill the block correctly up to two bytes from the 512 byte limit, and put the signature on the two last bytes.
The boot sector is 512 bytes long, and is identified as such by the final two bytes begin set to 0xAA55. This leaves 510 bytes for the loader's actual code, which is precisely what the provided example fills when assembled. If your resulting binary isn't precisely 512 bytes long then you may need to specify a plain binary output format, though in the case of nasm this is the default setting.
In practice there are other magic bytes which need to be present for partition tables and such, and typically the first stage loader is used for little more than reading in and executing some more code.

Is there any PDF parser written in objective-c or c?

I'm writing a pdf reader iPhone application.
I know how to show pdf file in view using CGPDF** classes in iOS.
What I want to do now is to search text in pdf file, and highlight the searched text.
So, I need a library which can detect what text is in what position.
Besides, I want the library able to handle unicode and Chinese characters.
I've searched for a few days but still cannot find anything suitable.
I've tried xpdf, but it is written in c++. I don't know how to use c++ code in iPhone app.
I've also tried
http://www.codeproject.com/KB/cpp/ExtractPDFText.aspx
but it does not handle Chinese characters.
I've tried to code by myself,
but the encoding in PDF is really complicated.
For example, I don't know what to refer to when I want to decode the text by the following font:
8 0 obj
<< /Type /Font /Subtype /Type0 /Encoding /Identity-H /BaseFont /RNXJTV+PMingLiU
/DescendantFonts [ 157 0 R ] >>
endobj
157 0 obj
<< /Type /Font /Subtype /CIDFontType2 /BaseFont /RNXJTV+PMingLiU /CIDSystemInfo
<< /Registry (Adobe) /Ordering (CNS1) /Supplement 0 >> /FontDescriptor 158 0 R
/W 161 0 R /DW 1000 /CIDToGIDMap 162 0 R >>
endobj
158 0 obj
<< /Type /FontDescriptor /Ascent 801 /CapHeight 711 /Descent -199 /Flags 32
/FontBBox [0 -199 999 801] /FontName /RNXJTV+PMingLiU /ItalicAngle 0 /StemV
0 /Leading 199 /MaxWidth 1000 /XHeight 533 /FontFile2 159 0 R >>
endobj
Take a look at the CGPDFScanner type; it can be used to parse through a PDF document for strings and particular PDF operators.
This code is having some bugs that can be easily fixable. Well presented Objective C code.
https://github.com/KurtCode/PDFKitten
CGPDFScanner can only scan the pdf contents but there is no way you can find the location of the word in the pdf. So highlighting is not possible using cgpdf functions. Also the scanner output is encoded text for flateDecoded and other types of pdf.
It can only scan simple pdfs i.e Linear pdfs. (Open the pdf as text file and at the top you will find the word Linearized pdf.)
Possible solution would be using a c or c+ parsing library if you get one.
Also the cpp project from the code project will only parse the content but wont give any location information.
Writing a pdf parser on your own is complex because pdf formats are complicated and not fixed. Pdf content can be encoded in different ways like FlateDecode type etc.

onMetaData marker in FLV file

I wanna know how the onMetaData marker in FLV files looks like. When i open FLV files as plain text I get this:
FLV[][][][][](TAB)[][][][][][][]8[][][][][][][][][]
onMetaData[]
duration...
The docs say the first 3 bytes are the signature "FLV" the next byte tells the flv version, the next byte is telling us if audio or video tags are present, the next 4 bytes are the data-offset(the size of the header), which is 9, in ascii its the TAB code. after the TAB starts the body with the fist "previous tag size field" which is 0(4 bytes) next, there is the Tag Type (1 byte) the data size (3 bytes) and the timestamp (4 bytes) the stream id (always 0, 3bytes). After that remains:
[]
onMetaData[]
[][][][][][]
duration...
I suppose the onMetaData marker is "1byte, newline"onMetaData"1byte,newline) but what are the 7 bytes between onMetaData marker and duration?
You would need to view this file in a hex editor to get anything useful from it; a text editor will just show you unprintable characters.
The ASCII "onMetaData" bit in the file is the tag header, which is wrapping the "duration" field. The three bytes immediately after "onMetaData" are the BodyLength of the tag (uint24, big-endian), and the next 4 bytes ("\x00\x00\x00\x08") describe the length of the name for the next tag, which is "duration."
I suggest you to use hexedit tool http://www.hexedit.com/
this will allow you to see all the info in string format..
as well as it has very nice navigation to analyze bytes.
In addition to it, use https://www.adobe.com/content/dam/Adobe/en/devnet/flv/pdfs/video_file_format_spec_v10.pdf to get details about all bytes in an flv file
Remember that the metadata is encoded using AMF. This means that after the string "onMetaData" you have a 0x08 to signify the start of an array and then 2 bytes to signify the length of the first element as number of character/bytes