Publié : lun. 02/juin/2008 16:13
par Rimpotché
Tu as raison, on ne gâche pas de papier ici et puis il n'est pas si long non plus.
;
; ------------------------------------------------------------
;
; PureBasic - Changement de pixel ratio d'un fichier MPEG
;
; (c) 2008 - Jac PETIT-JEAN-BORET
;
; Outil pour changer l'aspect ratio d'un MPEG
; Le programme cherche d'abord le premier "sequence header"
; Il ouvre alors une fenêtre, renseigne sur l'actuel aspect ratio,
; en profite pour donner des infos sommaires sur la vidéo.
; et propose un éventail de nouvelles proportions.
; Une fois le choix entériné, il change la valeur dans le premier sequence header
; puis refait une boucle pour trouver les autres et les changer également.
; Le requester "Save as" ne sauvegarde hélas pas sous le nouveau nom proposé
; mais sous le fichier d'origine qui est écrasé, même si on fait annuler. A voir !
; samedi 31 mai 2008 23h18
; ------------------------------------------------------------
;
Enumeration
#Window_0
EndEnumeration
;- Gadget Constants
;
Enumeration
#Text_0
#Text_1
#String_0
#String_1
#Text_2
#String_2
#String_3
#Text_3
#Text_5
#Text_6
#Text_8
#Text_9
#Text_10
#Text_11
#Text_12
#Text_13
#Text_14
#Text_15
#Text_16
#Text_17
#Text_18
#Text_19
#Radio_0
#Radio_1
#Radio_2
#Radio_3
#Radio_4
#Radio_5
#Radio_6
#Radio_7
#Radio_8
#Radio_9
#Radio_10
#Radio_11
#Radio_12
#Radio_13
#ProgressBar_0
#Text_20
#String_4
#Text_21
#Text_23
#String_5
#Button_0
#Button_1
#Text_24
#String_6
#String_7
#Image_0
EndEnumeration
;- Image Plugins
UseJPEGImageDecoder()
;- Image Globals
Global Image0
;- Catch Images
Image0 = CatchImage(0, ?Image0)
;- Images
DataSection
Image0:
IncludeBinary "C:\Program Files\PureBasic\Examples\Sources\Data\tintin.jpg"
EndDataSection
StandardFile$ = "D:\files\telecom\new\" ; set initial file+path to display
; With next string we will set the search patterns ("|" as separator) for file displaying:
; 1st: "Text (*.txt)" as name, ".txt" and ".bat" as allowed extension
; 2nd: "PureBasic (*.pb)" as name, ".pb" as allowed extension
; 3rd: "All files (*.*) as name, "*.*" as allowed extension, valid for all files
pointeur.l = 0
header.l =$B3010000
compteur.w = 0
choix.b=0
Quit.b =0
Pattern$ = "Video (*.mpg)|*.mpg;*.mpeg|All files (*.*)|*.*"
Pattern = 0 ; use the first of the three possible patterns as standard
Filtre$ = "MPEG (*.mpg)|*.mpg|All files (*.*)|*.*"
FiltrePosition = 0
File$ = OpenFileRequester("Sélection du MPEG", StandardFile$, Pattern$, Pattern)
If File$
If OpenFile(0, File$)
length.l = Lof(0)
nom$ = GetFilePart(File$)
path$ = GetPathPart(File$)
NewFile$ = path$ + "1" + nom$
Repeat
;Chercher le premier sequence header
FileSeek(0,pointeur)
head.l = ReadLong(0)
pointeur = pointeur + 1
Until (head.l = header.l) Or (pointeur >length)
pointeur = pointeur + 3
FileSeek(0,pointeur)
l1.b = ReadByte(0)
pointeur = pointeur + 1
FileSeek(0,pointeur)
l2.b = ReadByte(0)
largeur.w= (l1*16) + (l2/16)
pointeur = pointeur + 1
FileSeek(0,pointeur)
h1.b = ReadByte(0)
h2.w = h1
If h2<0
h2=h2 + 256
EndIf
hauteur.w= ((l2 % 16)*256) + h2
pointeur = pointeur + 1
FileSeek(0,pointeur)
r.b = ReadByte(0)
rate = r % 16
If rate<0
rate = rate + 16
EndIf
oldratio.w = r/16
If oldratio<0
oldratio = oldratio + 16
EndIf
If oldratio =1
specratio.s = "1.0000"
EndIf
If oldratio =2
specratio.s = "0.6735"
EndIf
If oldratio =3
specratio.s = "0.7031"
EndIf
If oldratio =4
specratio.s = "0.7615"
EndIf
If oldratio =5
specratio.s = "0.8055"
EndIf
If oldratio =6
specratio.s = "0.8437"
EndIf
If oldratio =7
specratio.s = "0.8935"
EndIf
If oldratio =8
specratio.s = "0.9157"
EndIf
If oldratio =9
specratio.s = "0.9815"
EndIf
If oldratio =10
specratio.s = "1.0255"
EndIf
If oldratio =11
specratio.s = "1.0695"
EndIf
If oldratio =12
specratio.s = "1.0950"
EndIf
If oldratio =13
specratio.s = "1.1575"
EndIf
If oldratio =14
specratio.s = "1.2051"
EndIf
If rate = 1
imaprosec.s = "23.976"
EndIf
If rate = 2
imaprosec.s = "24.000"
EndIf
If rate = 3
imaprosec.s = "25.000"
EndIf
If rate = 4
imaprosec.s = "29.970"
EndIf
If rate = 5
imaprosec.s = "30.000"
EndIf
If rate = 6
imaprosec.s = "50.000"
EndIf
If rate = 7
imaprosec.s = "59.940"
EndIf
If rate = 8
imaprosec.s = "60.000"
EndIf
If OpenWindow(#Window_0, 869, 346, 445, 395, "Pixel Ratio Changer", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
If CreateGadgetList(WindowID(0))
TextGadget(#Text_0, 10, 100, 40, 20, "Largeur")
TextGadget(#Text_1, 10, 140, 50, 20, "Hauteur")
StringGadget(#String_0, 80, 100, 50, 20, Str(largeur), #PB_String_ReadOnly | #PB_String_Numeric)
StringGadget(#String_1, 80, 140, 50, 20, Str(hauteur), #PB_String_ReadOnly | #PB_String_Numeric)
TextGadget(#Text_2, 10, 180, 50, 20, "Pixel Ratio")
StringGadget(#String_2, 170, 180, 40, 20, Str(oldratio), #PB_String_ReadOnly | #PB_String_Numeric)
StringGadget(#String_3, 80, 180, 70, 20, specratio, #PB_String_ReadOnly)
TextGadget(#Text_3, 340, 10, 90, 20, "Nouveau ratio", #PB_Text_Center)
TextGadget(#Text_5, 340, 30, 70, 20, " 1 1.0000")
TextGadget(#Text_6, 340, 50, 70, 20, " 2 0.6735")
TextGadget(#Text_8, 340, 70, 70, 20, " 3 0.7031")
TextGadget(#Text_9, 340, 90, 70, 20, " 4 0.7615")
TextGadget(#Text_10, 340, 110, 70, 20, " 5 0.8055")
TextGadget(#Text_11, 340, 130, 70, 20, " 6 0.8437")
TextGadget(#Text_12, 340, 150, 70, 20, " 7 0.8935")
TextGadget(#Text_13, 340, 170, 70, 20, " 8 0.9157")
TextGadget(#Text_14, 340, 190, 70, 20, " 9 0.9815")
TextGadget(#Text_15, 340, 210, 70, 20, "10 1.0255")
TextGadget(#Text_16, 340, 230, 70, 20, "11 1.0695")
TextGadget(#Text_17, 340, 250, 70, 20, "12 1.0950")
TextGadget(#Text_18, 340, 270, 70, 20, "13 1.1575")
TextGadget(#Text_19, 340, 290, 70, 20, "14 1.2051")
OptionGadget(#Radio_0, 420, 30, 20, 20, "")
OptionGadget(#Radio_1, 420, 50, 20, 20, "")
OptionGadget(#Radio_2, 420, 70, 20, 20, "")
OptionGadget(#Radio_3, 420, 90, 20, 20, "")
OptionGadget(#Radio_4, 420, 110, 20, 20, "")
OptionGadget(#Radio_5, 420, 130, 20, 20, "")
OptionGadget(#Radio_6, 420, 150, 20, 20, "")
OptionGadget(#Radio_7, 420, 170, 20, 20, "")
OptionGadget(#Radio_8, 420, 190, 20, 20, "")
OptionGadget(#Radio_9, 420, 210, 20, 20, "")
OptionGadget(#Radio_10, 420, 230, 20, 20, "")
OptionGadget(#Radio_11, 420, 250, 20, 20, "")
OptionGadget(#Radio_12, 420, 270, 20, 20, "")
OptionGadget(#Radio_13, 420, 290, 20, 20, "")
ProgressBarGadget(#ProgressBar_0, 10, 330, 420, 20, 0, 100)
TextGadget(#Text_20, 10, 260, 140, 20, "Nombre de headers patchés")
StringGadget(#String_4, 150, 260, 60, 20, Str(compteur), #PB_String_ReadOnly | #PB_String_Numeric)
TextGadget(#Text_21, 10, 220, 120, 20, "Images par seconde")
TextGadget(#Text_23, 10, 20, 50, 20, "Fichier")
StringGadget(#String_5, 60, 20, 250, 20, nom$ , #PB_String_ReadOnly)
ButtonGadget(#Button_0, 10, 360, 80, 20, "Annuler")
ButtonGadget(#Button_1, 330, 360, 100, 20, "Patcher")
TextGadget(#Text_24, 10, 60, 150, 20, "Longueur du fichier en ko")
StringGadget(#String_6, 190, 60, 120, 20, Str(length/1024), #PB_String_ReadOnly | #PB_String_Numeric)
StringGadget(#String_7, 150, 220, 60, 20, imaprosec, #PB_String_ReadOnly | #PB_String_Numeric)
ImageGadget(#Image_0, 230, 90, 100, 230, Image0)
EndIf
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_CloseWindow
End
EndIf
If EventID = #PB_Event_Gadget
If EventGadget()=#Radio_0
newratio.b=1
choix=1
EndIf
If EventGadget()=#Radio_1
newratio.b=2
choix=1
EndIf
If EventGadget()=#Radio_2
newratio.b=3
choix=1
EndIf
If EventGadget()=#Radio_3
newratio.b=4
choix=1
EndIf
If EventGadget()=#Radio_4
newratio.b=5
choix=1
EndIf
If EventGadget()=#Radio_5
newratio.b=6
choix=1
EndIf
If EventGadget()=#Radio_6
newratio.b=7
choix=1
EndIf
If EventGadget()=#Radio_7
newratio.b=8
choix=1
EndIf
If EventGadget()=#Radio_8
newratio.b=9
choix=1
EndIf
If EventGadget()=#Radio_9
newratio.b=10
choix=1
EndIf
If EventGadget()=#Radio_10
newratio.b=11
choix=1
EndIf
If EventGadget()=#Radio_11
newratio.b=12
choix=1
EndIf
If EventGadget()=#Radio_12
newratio.b=13
choix=1
EndIf
If EventGadget()=#Radio_13
newratio.b=14
choix=1
EndIf
If EventGadget()= #Button_0
End
EndIf
If EventGadget()= #Button_1
Quit=1
EndIf
If newratio <1 Or newratio >14
choix =0
EndIf
If Quit = 1 And choix = 0
MessageRequester("Erreur", "Choisir un nouvel aspect ou annuler", 0)
Quit=0
EndIf
EndIf
Until Quit=1 And choix = 1
aecrire.b = (newratio*16)+rate
If aecrire>127
aecrire = aecrire -128
EndIf
FileSeek(0,pointeur)
WriteByte(0,aecrire)
compteur = compteur +1
;---------------------------------------------------------------
;recherche des autres blocs
Repeat
Repeat
;Chercher le header
FileSeek(0,pointeur)
head.l = ReadLong(0)
pointeur = pointeur + 1
Until (head.l = header.l) Or (pointeur >length)
pointeur = pointeur + 6
If pointeur <length
FileSeek(0,pointeur)
WriteByte(0,aecrire)
compteur = compteur + 1
SetGadgetText(#String_4, Str(compteur))
SetGadgetState(#ProgressBar_0,(pointeur*100/length))
EndIf
Until (pointeur >length)
; ---------------------------------------------------------------
; Sauvegarde
If SaveFileRequester("Choisissez un fichier à sauvegarder", NewFile$, Filtre$, Filtre)
MessageRequester("Information", "Vous avez choisi ce fichier :"+Chr(10)+Fichier$, 0)
Else
MessageRequester("Information", "La sélection a été annulée.", 0)
EndIf
Else
MessageRequester("Erreur", "La fenêtre ne peut pas être ouverte.", 0)
EndIf
;CloseFile(0)
CloseWindow(0)
Else
MessageRequester("Erreur", "Le fichier ne peut pas être ouvert.", 0)
EndIf
Else
MessageRequester("Information", "Opération annulée.", 0)
EndIf
End