PDA

View Full Version : How to read the regions off the DVD ?


GZZ
19th October 2002, 00:37
Anyone here can tell me how to read the region code off the DVD.

I got a little program I´m working on and I could really need a piece of code which can read which region the ifo file on the DVD is in.

I´m working in delphi, so if anyone can help me on this subject please help me.

Thanks

GZZ

mpucoder
19th October 2002, 00:51
Here's where you'll find that and a whole lot more (before you ask for it) http://mpucoder.kewlhair.com/dvd/
What you want to look at is offset 23h of video_ts.ifo
That is a mask of prohibited regions, bit 0 is region 1, bit 1 is region 2, etc.

GZZ
19th October 2002, 01:28
first of all I´m not that good at coding. :)

Second I can't find Offset 23H on that page. But you cold help me with a few lines of code. I think I need some blockreading. But thats all.

Could you help me a little bit ?


GZZ

int 21h
19th October 2002, 01:48
But if you just ask for the code, you'll never be good at coding.

mpucoder
19th October 2002, 02:28
Byte 23 is in the ifo header, so look in http://mpucoder.kewlhair.com/dvd/ifo.html
But I gave you the description anyway, the byte is a bit mask (Pascal would call it a packed record of type bool).

GZZ
20th October 2002, 11:18
Well MPUcoder. You where wrong about byte 23. Its byte 35 (offset 35) or maybe I did undeestand you wrong. HEHE

Anyway I got it working and here is the working code (in delphi) for reading the region code off a DVD. Its properly not the BEST code, but its working fine and I hope other people can learn from it aswell:

procedure TForm1.Button1Click(Sender: TObject);
var
Fil: File;
S: String;
Temp: Byte;
begin
Assignfile(Fil, 'E:\DVDfilm\VIDEO_TS.IFO');
FileMode := 0; //Read Only
Reset(Fil, 1);
Seek(Fil, 35); //Seek after Offset 35 (byte 35)
blockread(Fil, Temp, Sizeof(Temp)); //Temp is the result in decimal number and Sizeof is the just the size of the number.
closefile(Fil);

S := IntToBinary(Temp); //Converts the Decimal number to a Binary number.

S := BinaryToRegionCode(S); //Converts the Binary number to The Regions code.

Showmessage(S); //Shows the Result in Region Codes.
end;


function IntToBinary(Value: Integer): String;
begin
result:='';
while value > 0 do
begin
result := chr(ord('0') + (value and 1)) + result;
value := value shr 1;
end;

if result = '' then
result := '0';
end;


Function BinaryToRegionCode(Value: String): String;
var
I, Position, Counter: Integer;
Temp: String[8];
Begin
Temp := '';
For I := Length(Value) downto 0 do
Temp := Temp + Value[I];
Value := Temp;

For I := 0 to Length(value)-1 do
If Pos('0', Value) <> 0 then
Begin
Position := Pos('0', Value);
Case Position of
1: Result := Result + 'Region Code 1, ';
2: Result := Result + 'Region Code 2, ';
3: Result := Result + 'Region Code 3, ';
4: Result := Result + 'Region Code 4, ';
5: Result := Result + 'Region Code 5, ';
6: Result := Result + 'Region Code 6, ';
7: Result := Result + 'Region Code 7, '; //Not in use yet.
8: Result := Result + 'Region Code 8, '; //Not in use yet.
end;
Value[Position] := '1'; //so it don't find the zero twice.
end;
Delete(Result, Length(Result)-1, 1); //Removes the last ',' from the Result.
end;


Best Regard

GZZ

mpucoder
20th October 2002, 17:07
Sorry, I should have been more specific, the offset is in hex. 23h = 35.
And stopping at the first zero bit will cause you trouble, the reason it is called a bit mask is because more than one can be zeroed. As a mask it allows any combination of regions to be allowed, including all. Many disks have both region 1 and 7 permitted (7 is essentially boats at sea and the space station)

GZZ
20th October 2002, 17:35
And stopping at the first zero bit will cause you trouble

What do you mean by that. Does my code have an error. Because it works fine with all regions (except 7,8 which I don't think any dvd use or maybe I´m wrong. ??).

GZZ

mpucoder
20th October 2002, 17:47
I just read it quickly and mistook the comment "so it don't find the zero twice." as meaning don't look for others. My mistake. Also, just checked (my memory isn't what it used to be) - it's region 8, not 7, that is international.