How to get raw jpeg data (but no metatags / proprietary markers)

偶尔善良 提交于 2021-02-11 13:03:09

问题


I want to get raw jpeg data - no metadata. I'm very confused looking at the jpeg "standards".

How correct is my understanding of the marker "tree"?

0xFFD8 - Identifies the file as an image
    0xFFE? - EXIF, JFIF, SPIFF, ICC, etc 
        0x???? - the length of the tag
    0xFFD8 - Start of Image
        0xFFE0 - should follow SOI as per spec, but often preceded by comments ???
        0x???? - Matrices, tags, random data ???

        There are never other markers in-between these markers? 
        Or these include the matrices and such?
        0xFFDA - Start of Stream - This is what I want, yes?
            0xXXXX - length of stream
            0xFFD9 - End of Stream (EOI)

        0x???? - Comment tags, extra exif, jfif info???
0xFFD9 - End of Image

0xFF00 - escaped 0xFF, not to be confused with a marker

This has been my reading material:

http://en.wikipedia.org/wiki/JPEG

https://ExifTool.org/TagNames/JPEG.html

http://www.media.mit.edu/pia/Research/deepview/exif.html

http://www.faqs.org/faqs/jpeg-faq/part1/section-15.html


回答1:


Besides the SOS (0xFFDA), you may also want the following:

0xFFDB DQT Quantization Table 0xFFC4 DHT Define Huffman Table




回答2:


There's a fairly reasonable "Anatomy of a JPEG" here which shows you how to use grep to extract JPEG markers and sections from JPEG files, e.g. for SOF marker:

xxd -c16 -g1 -u testimg.jpg | grep --color=always -C2 "FF C0"
0000090: 32 32 32 32 32 32 32 32 32 32 32 32 32 32 FF C0  22222222222222..
00000a0: 00 11 08 00 95 00 E3 03 01 22 00 02 11 01 03 11  ........."......
00000b0: 01 FF C4 00 1F 00 00 01 05 01 01 01 01 01 01 00  ................

Explanation

0xFF, 0xC0,             // SOF0 segement
0x00, 0x11,             // length of segment depends on the number of components
0x08,                   // bits per pixel
0x00, 0x95,             // image height
0x00, 0xE3,             // image width
0x03,                   // number of components (should be 1 or 3)
0x01, 0x22, 0x00,       // 0x01=Y component, 0x22=sampling factor, quantization table number
0x02, 0x11, 0x01,       // 0x02=Cb component, ...
0x03, 0x11, 0x01        // 0x03=Cr component, ...

And there's a complete, highly detailed and thorough series of videos here on YouTube that tell you more than you could possibly ever want to know about JPEG.


Note also that you can extract and examine the JPEG markers in a file with exiftool, like this:

exiftool -v -v -v image.jpg

Sample Output

  ExifToolVersion = 12.00
  FileName = iphone.jpg
  Directory = .
  FileSize = 2219100
  FileModifyDate = 1596126733
  FileAccessDate = 1610564128
  FileInodeChangeDate = 1596126733
  FilePermissions = 33188
  FileType = JPEG
  FileTypeExtension = JPG
  MIMEType = image/jpeg
JPEG APP1 (12284 bytes):
    0006: 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 0b [Exif..MM.*......]
    0016: 01 0f 00 02 00 00 00 06 00 00 00 92 01 10 00 02 [................]
    0026: 00 00 00 09 00 00 00 98 01 12 00 03 00 00 00 01 [................]
    0036: 00 01 00 00 01 1a 00 05 00 00 00 01 00 00 00 a2 [................]
    0046: 01 1b 00 05 00 00 00 01 00 00 00 aa 01 28 00 03 [.............(..]
    0056: 00 00 00 01 00 02 00 00 01 31 00 02 00 00 00 06 [.........1......]
    0066: 00 00 00 b2 01 32 00 02 00 00 00 14 00 00 00 b8 [.....2..........]
    [snip 12172 bytes]
  ExifByteOrder = MM
  + [IFD0 directory with 11 entries]
  | 0)  Make = Apple
  |     - Tag 0x010f (6 bytes, string[6]):
  |         009e: 41 70 70 6c 65 00                               [Apple.]
  | 1)  Model = iPhone 4
  |     - Tag 0x0110 (9 bytes, string[9]):
  |         00a4: 69 50 68 6f 6e 65 20 34 00                      [iPhone 4.]
  | 2)  Orientation = 1
  |     - Tag 0x0112 (2 bytes, int16u[1]):
  |         0036: 00 01                                           [..]
  | 3)  XResolution = 72 (72/1)
  |     - Tag 0x011a (8 bytes, rational64u[1]):
  |         00ae: 00 00 00 48 00 00 00 01                         [...H....]
  | 4)  YResolution = 72 (72/1)
  |     - Tag 0x011b (8 bytes, rational64u[1]):
  |         00b6: 00 00 00 48 00 00 00 01                         [...H....]
  | 5)  ResolutionUnit = 2
  |     - Tag 0x0128 (2 bytes, int16u[1]):
  |         005a: 00 02                                           [..]
  | 6)  Software = 6.1.2
  |     - Tag 0x0131 (6 bytes, string[6]):
  |         00be: 36 2e 31 2e 32 00                               [6.1.2.]
  | 7)  ModifyDate = 2013:03:09 08:59:50
  |     - Tag 0x0132 (20 bytes, string[20]):
  |         00c4: 32 30 31 33 3a 30 33 3a 30 39 20 30 38 3a 35 39 [2013:03:09 08:59]
  |         00d4: 3a 35 30 00                                     [:50.]
  | 8)  YCbCrPositioning = 1
  |     - Tag 0x0213 (2 bytes, int16u[1]):
  |         007e: 00 01                                           [..]
  | 9)  ExifOffset (SubDirectory) -->
  |     - Tag 0x8769 (4 bytes, int32u[1]):
  |         008a: 00 00 00 cc                                     [....]
  | + [ExifIFD directory with 24 entries]
  | | 0)  ExposureTime = 0.001094091904 (1/914)
  | |     - Tag 0x829a (8 bytes, rational64u[1]):
  | |         01fe: 00 00 00 01 00 00 03 92                         [........]
  | | 1)  FNumber = 2.8 (14/5)
  | |     - Tag 0x829d (8 bytes, rational64u[1]):
  | |         0206: 00 00 00 0e 00 00 00 05                         [........]
  | | 2)  ExposureProgram = 2
  | |     - Tag 0x8822 (2 bytes, int16u[1]):
  | |         00fa: 00 02                                           [..]
  | | 3)  ISO = 80
  | |     - Tag 0x8827 (2 bytes, int16u[1]):
  | |         0106: 00 50                                           [.P]
  | | 4)  ExifVersion = 0221
  | |     - Tag 0x9000 (4 bytes, undef[4]):
  | |         0112: 30 32 32 31                                     [0221]
  | | 5)  DateTimeOriginal = 2013:03:09 08:59:50
  | |     - Tag 0x9003 (20 bytes, string[20]):
  | |         020e: 32 30 31 33 3a 30 33 3a 30 39 20 30 38 3a 35 39 [2013:03:09 08:59]
  | |         021e: 3a 35 30 00                                     [:50.]
  | | 6)  CreateDate = 2013:03:09 08:59:50
  | |     - Tag 0x9004 (20 bytes, string[20]):
  | |         0222: 32 30 31 33 3a 30 33 3a 30 39 20 30 38 3a 35 39 [2013:03:09 08:59]
  | |         0232: 3a 35 30 00                                     [:50.]
  | | 7)  ComponentsConfiguration = 1 2 3 0
  | |     - Tag 0x9101 (4 bytes, undef[4] read as int8u[4]):
  | |         0136: 01 02 03 00                                     [....]
  | | 8)  ShutterSpeedValue = 9.83619211 (11469/1166)
  | |     - Tag 0x9201 (8 bytes, rational64s[1]):
  | |         0236: 00 00 2c cd 00 00 04 8e                         [..,.....]
  | | 9)  ApertureValue = 2.970853574 (4281/1441)
  | |     - Tag 0x9202 (8 bytes, rational64u[1]):
  | |         023e: 00 00 10 b9 00 00 05 a1                         [........]
  | | 10) BrightnessValue = 8.880310458 (21739/2448)
  | |     - Tag 0x9203 (8 bytes, rational64s[1]):
  | |         0246: 00 00 54 eb 00 00 09 90                         [..T.....]
  | | 11) MeteringMode = 5
  | |     - Tag 0x9207 (2 bytes, int16u[1]):
  | |         0166: 00 05                                           [..]
  | | 12) Flash = 0
  | |     - Tag 0x9209 (2 bytes, int16u[1]):
  | |         0172: 00 00                                           [..]
  | | 13) FocalLength = 3.85 (77/20)
  | |     - Tag 0x920a (8 bytes, rational64u[1]):
  | |         024e: 00 00 00 4d 00 00 00 14                         [...M....]
  | | 14) FlashpixVersion = 0100
  | |     - Tag 0xa000 (4 bytes, undef[4]):
  | |         018a: 30 31 30 30                                     [0100]
  | | 15) ColorSpace = 1
  | |     - Tag 0xa001 (2 bytes, int16u[1]):
  | |         0196: 00 01                                           [..]
  | | 16) ExifImageWidth = 2592
  | |     - Tag 0xa002 (4 bytes, int32u[1]):
  | |         01a2: 00 00 0a 20                                     [... ]
  | | 17) ExifImageHeight = 1936
  | |     - Tag 0xa003 (4 bytes, int32u[1]):
  | |         01ae: 00 00 07 90                                     [....]
  | | 18) SensingMethod = 2
  | |     - Tag 0xa217 (2 bytes, int16u[1]):
  | |         01ba: 00 02                                           [..]
  | | 19) CustomRendered = 2
  | |     - Tag 0xa401 (2 bytes, int16u[1]):
  | |         01c6: 00 02                                           [..]
  | | 20) ExposureMode = 0
  | |     - Tag 0xa402 (2 bytes, int16u[1]):
  | |         01d2: 00 00                                           [..]
  | | 21) WhiteBalance = 0
  | |     - Tag 0xa403 (2 bytes, int16u[1]):
  | |         01de: 00 00                                           [..]
  | | 22) FocalLengthIn35mmFormat = 35
  | |     - Tag 0xa405 (2 bytes, int16u[1]):
  | |         01ea: 00 23                                           [.#]
  | | 23) SceneCaptureType = 0
  | |     - Tag 0xa406 (2 bytes, int16u[1]):
  | |         01f6: 00 00                                           [..]
  | 10) GPSInfo (SubDirectory) -->
  |     - Tag 0x8825 (4 bytes, int32u[1]):
  |         0096: 00 00 02 4a                                     [...J]
  | + [GPS directory with 9 entries]
  | | 0)  GPSLatitudeRef = N
  | |     - Tag 0x0001 (2 bytes, string[2]):
  | |         0260: 4e 00                                           [N.]
  | | 1)  GPSLatitude = 20 50.66 0 (20/1 5066/100 0/1)
  | |     - Tag 0x0002 (24 bytes, rational64u[3]):
  | |         02c8: 00 00 00 14 00 00 00 01 00 00 13 ca 00 00 00 64 [...............d]
  | |         02d8: 00 00 00 00 00 00 00 01                         [........]
  | | 2)  GPSLongitudeRef = E
  | |     - Tag 0x0003 (2 bytes, string[2]):
  | |         0278: 45 00                                           [E.]
  | | 3)  GPSLongitude = 107 5.46 0 (107/1 546/100 0/1)
  | |     - Tag 0x0004 (24 bytes, rational64u[3]):
  | |         02e0: 00 00 00 6b 00 00 00 01 00 00 02 22 00 00 00 64 [...k......."...d]
  | |         02f0: 00 00 00 00 00 00 00 01                         [........]
  | | 4)  GPSAltitudeRef = 0
  | |     - Tag 0x0005 (1 bytes, int8u[1]):
  | |         0290: 00                                              [.]
  | | 5)  GPSAltitude = 1.12868102 (4561/4041)
  | |     - Tag 0x0006 (8 bytes, rational64u[1]):
  | |         02f8: 00 00 11 d1 00 00 0f c9                         [........]
  | | 6)  GPSTimeStamp = 1 59 48.81 (1/1 59/1 4881/100)
  | |     - Tag 0x0007 (24 bytes, rational64u[3]):
  | |         0300: 00 00 00 01 00 00 00 01 00 00 00 3b 00 00 00 01 [...........;....]
  | |         0310: 00 00 13 11 00 00 00 64                         [.......d]
  | | 7)  GPSImgDirectionRef = T
  | |     - Tag 0x0010 (2 bytes, string[2]):
  | |         02b4: 54 00                                           [T.]
  | | 8)  GPSImgDirection = 324.4435484 (40231/124)
  | |     - Tag 0x0011 (8 bytes, rational64u[1]):
  | |         0318: 00 00 9d 27 00 00 00 7c                         [...'...|]
  + [IFD1 directory with 6 entries]
  | 0)  Compression = 6
  |     - Tag 0x0103 (2 bytes, int16u[1]):
  |         032a: 00 06                                           [..]
  | 1)  XResolution = 72 (72/1)
  |     - Tag 0x011a (8 bytes, rational64u[1]):
  |         036e: 00 00 00 48 00 00 00 01                         [...H....]
  | 2)  YResolution = 72 (72/1)
  |     - Tag 0x011b (8 bytes, rational64u[1]):
  |         0376: 00 00 00 48 00 00 00 01                         [...H....]
  | 3)  ResolutionUnit = 2
  |     - Tag 0x0128 (2 bytes, int16u[1]):
  |         034e: 00 02                                           [..]
  | 4)  ThumbnailOffset = 882
  |     - Tag 0x0201 (4 bytes, int32u[1]):
  |         035a: 00 00 03 72                                     [...r]
  | 5)  ThumbnailLength = 7847
  |     - Tag 0x0202 (4 bytes, int32u[1]):
  |         0366: 00 00 1e a7                                     [....]
JPEG DQT (130 bytes):
    3006: 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 [................]
    3016: 04 02 02 02 02 02 04 03 03 02 04 05 05 06 06 05 [................]
    3026: 05 05 05 06 07 09 07 06 06 08 06 05 05 08 0a 08 [................]
    3036: 08 09 09 0a 0a 0a 06 07 0b 0c 0b 0a 0c 09 0a 0a [................]
    3046: 09 01 01 01 01 02 02 02 04 02 02 04 09 06 05 06 [................]
    3056: 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 [................]
    3066: 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 [................]
    [snip 18 bytes]
JPEG SOF0 (15 bytes):
    308c: 08 07 90 0a 20 03 01 22 00 02 11 01 03 11 01    [.... ..".......]
  ImageWidth = 2592
  ImageHeight = 1936
  EncodingProcess = 0
  BitsPerSample = 8
  ColorComponents = 3
  YCbCrSubSampling = 2 2
JPEG DHT (416 bytes):
    309f: 00 00 01 05 01 01 01 01 01 01 00 00 00 00 00 00 [................]
    30af: 00 00 01 02 03 04 05 06 07 08 09 0a 0b 10 00 02 [................]
    30bf: 01 03 03 02 04 03 05 05 04 04 00 00 01 7d 01 02 [.............}..]
    30cf: 03 00 04 11 05 12 21 31 41 06 13 51 61 07 22 71 [......!1A..Qa."q]
    30df: 14 32 81 91 a1 08 23 42 b1 c1 15 52 d1 f0 24 33 [.2....#B...R..$3]
    30ef: 62 72 82 09 0a 16 17 18 19 1a 25 26 27 28 29 2a [br........%&'()*]
    30ff: 34 35 36 37 38 39 3a 43 44 45 46 47 48 49 4a 53 [456789:CDEFGHIJS]
    [snip 304 bytes]
JPEG SOS
JPEG EOI

Keywords: JPEG, marker, anatomy, SOF, DQT, DHT, prime.



来源:https://stackoverflow.com/questions/1976500/how-to-get-raw-jpeg-data-but-no-metatags-proprietary-markers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!