AVCHD MTS file tags position

Started by Serjone, October 18, 2018, 07:49:39 AM

Previous topic - Next topic

Serjone

Hello.
I have one problem. My HDD wiht mts video was broken and i try to recover any data. I have HDD image file and try to find HEX signatures to find files. I can foun some files by data recovery software, but all software I used cant find file completely - they are found mts file chunks, because file vas fragmented on HDD.

I want to find chunks and join each other.

For search and join I need to know MTS file signature and metadata position, but I cant find amy information about it.
Do anybody know where I can find it?
I start to explore ExifTool source code, but I am not good in programming and english language =(

ExifTool Version Number         : 11.14
File Name                       : 00004.MTS
Directory                       : //ts/Video//PRIVATE/AVCHD/BDMV/STREAM
File Size                       : 2027 MB
File Modification Date/Time     : 2017:12:10 06:09:29+03:00
File Access Date/Time           : 2018:10:01 19:46:51+03:00
File Creation Date/Time         : 2018:10:01 19:46:51+03:00
File Permissions                : rw-rw-rw-
File Type                       : M2TS
File Type Extension             : mts
MIME Type                       : video/m2ts
Video Stream Type               : H.264 Video
Audio Stream Type               : A52/AC-3 Audio
Audio Bitrate                   : 448 kbps
Surround Mode                   : Not indicated
Audio Channels                  : 3/2
Image Width                     : 1920
Image Height                    : 1080
Date/Time Original              : 2017:12:10 05:52:24+00:00
Aperture Setting                : Auto
Gain                            : 0 dB
Exposure Program                : Program AE
White Balance                   : Auto
Focus                           : Auto (0.2)
Image Stabilization             : On (0x3f)
Exposure Time                   : 1/60
F Number                        : 3.4
Make                            : Sony
Camera Model Name               : HDR-CX625
Warning                         : [minor] The ExtractEmbedded option may find more tags in the video data
Audio Sample Rate               : 48000
Duration                        : 0:17:01
Aperture                        : 3.4
Image Size                      : 1920x1080
Megapixels                      : 2.1
Shutter Speed                   : 1/60





I need some data:
- how can I identify MTS tile?
- how can I get :
   -Date/Time Original ?
   -Make (Sony)
   -Camera Model Name (HDR-CX625)
   -Duration 

Is there any information about filesize, or streamsize, or frames quantity in mts file?

I think it will be enougth for find chunks and join them to complete file.

Phil Harvey

Unfortunately for you, M2TS is not designed as a file format (it is a transmission format), so it has no strong magic number, and recognizing an M2TS is a bit of a problem (see my comments here).

But you may have some luck if you can recognize specific information written by your camera (the MDPM metadata for example).  First, try comparing a few "good" MTS files to see what byte combinations are common between them, then look for these byte sequences in the sectors on your disk.

The M2TS packets are either 188 or 192 bytes long, depending on whether or not they have a timecode header.  Look for combinations of bytes that you may be able to recognize in the headers of each packet.

Good luck!

- Phil

Edit:  You are lucky... Your M2TS does contain the timecode header (as I see from your dump -- the first 4 bytes are the timecode), so the packets will be 192 bytes long, and you may be able to use the timecodes to arrange the sectors in the proper sequence.
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Serjone

________________________________________________
|Keyframe|frame1|frame2|,,,|frameN|keyframe2|frameN+2|
-------------------------------------------------------------------|
|chunk1.........................................|chunk2....................|
-------------------------------------------------------------------|

I found this strucrure of my MTS file. Keyframe contains all metadata which shows in ExifTool (i was try cut any chunk and open in ExifTool).

else i found camera name, bit it is not just string: дHDR-еCX62ж5
camera's name is HDR-CX625. Hoy you read this string in ExifTool correctly? And i cant find any "Sony" string in hex.
here is some SRID and CLID data, I dont know what is it
Else I found Date and Time in BCD format.


So, now i can find all chunks, but there are lots of them. Will find any ways to get whem all and compile.

maybe you know how to get chunk size, or frame size?

Do you know what format of timecod using in this file? Each next value increase on 0x8D0



this file for example https://drive.google.com/open?id=1GMcgzYcZHC3oDH5ONfSDkyja5yQAgjQ3

Phil Harvey

I don't have time to explain all of the details about the M2TS and H264 decoding... it gets very involved.  Take a look at M2TS.pm and H264.pm in the ExifTool source code for details about how ExifTool decodes these files.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Serjone

#4
Hello.
I have question again.
I make programm, which scan MTS file and copy packets (192 bytes) to new file. And now i need separate files (from one raw file). Now i search it by timecode, but it not stable.

as you say, my M2TS does contain the timecode header. There is different between timecode usualy 2256, but sometimes it can be another number:


do you know how timecode is calculating? maybe there some information about it in packet data?

Phil Harvey

You should be able to get the time scale from the H264 metadata and use this to convert the timecode to seconds.  I don't know why these values jump sometimes though.  If you find out please let me know.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).