[SOLVED] (Insidious Case correction)

Just starting out? Need help? Post your questions and find answers here.
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

[SOLVED] (Insidious Case correction)

Post by Piero »

This one can make you very mad, thinking you modified the string while splitting it

Code: Select all

Procedure.s QP(str$)
   ProcedureReturn "'" + ReplaceString(str$, "'", "'\''") + "'"
EndProcedure

Procedure Shell(ShellCommand$)
   Protected shell = RunProgram("/bin/zsh","","",
      #PB_Program_Open|#PB_Program_Write|#PB_Program_Read|#PB_Program_Error )
   If shell
      WriteProgramStringN(shell,"zsh -lc " + QP(ShellCommand$))
      WriteProgramData(shell,#PB_Program_Eof,0)
      While ProgramRunning(shell)
         If AvailableProgramOutput(shell)
            Output$= ReadProgramString(shell)+ Chr(13)
            Debug Output$
         EndIf
         tmper$ = ReadProgramError(shell)
         If tmper$
            Debug  tmper$ + Chr(13)             
         EndIf
      Wend
      CloseProgram(shell)
   EndIf
EndProcedure

s.s= "ffmpeg -v 8 -hide_banner -progress pipe:1 -i '/Users/piero/Desktop/in.mp4' -af 'dynaudnorm=g=3:c=1:m=10:f=10:b=1' -map 0 -c:v copy -y '/Users/piero/Desktop/out.mp4'"
Shell(s) ; works as expected
Debug ~"\n"+s+~"\n"

; THE FOLLOWING WILL GIVE ERROR EVEN IF I DELETE " + " !!!!!!

s.s= "ffmpeg" + " -v 8 -hide_banner -progress pipe:1 -i '/Users/piero/Desktop/in.mp4' -af 'dynaudnorm=g=3:c=1:m=10:f=10:b=1' -Map 0 -c:v copy -y '/Users/piero/Desktop/out.mp4'"
Shell(s) ; Error splitting the argument list: Option not found
Debug ~"\n"+s

; 6.12 LTS Mac M1
Last edited by Piero on Wed Jan 29, 2025 9:32 pm, edited 2 times in total.
PeDe
Enthusiast
Enthusiast
Posts: 305
Joined: Sun Nov 26, 2017 3:13 pm

Re: Insidious bug!

Post by PeDe »

Are FFmpeg parameters case-sensitive?
-map <> -Map

Peter
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Insidious Case correction!

Post by Piero »

PeDe wrote: Wed Jan 29, 2025 8:03 pm Are FFmpeg parameters case-sensitive?
-map <> -Map

Peter
Many thanks Peter!
I didn't notice it! :oops: :oops: :oops:

If you paste e.g. "something -map something" (without quotes) with "Enable Case correction" on, you will get -Map, so be careful when pasting shell parameters!
Also:

Code: Select all

; Pasting inside double quotes:
"    <pasted> "something -Map </pasted>   "
"    <pasted> something -map </pasted>   "
Even more insidious:

Code: Select all

s.s = "         dummy -map"
; Try type " (a double quote) before dummy -map
; with "Enable Case correction" in preferences…
User avatar
ChrisR
Addict
Addict
Posts: 1484
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: [SOLVED] (Insidious Case correction)

Post by ChrisR »

I've often had the same case, when I write translations in my app, I end up with Or, And, For... key words, if I forget to put the text in quotes right away. Not what I want, but no impact on execution here.
It would be useful to be able to enable or disable “Case correction” from the toolbar.
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: [SOLVED] (Insidious Case correction)

Post by Piero »

ChrisR wrote: Thu Jan 30, 2025 12:46 pmIt would be useful to be able to enable or disable “Case correction” from the toolbar
YES! Hope Fred's team will consider it! And with a BIG red icon when it's active! :lol:

I use shell often…
Here's one of my Mac "Scripting Terminal" Magics (I'm still learning PB :cry:):
Auto-closes the Terminal… you won't easily find stuff like this elsewhere… :)

This time, always dynamic audio normalization, but one file at the time:

Code: Select all

on open | my Video (or Audio) files |
	-- tell application "Finder" to set | my Video (or Audio) files | to selection as alias list -- avoid weird drag and drop bug
	tell application "Terminal" -- process files one by one
		launch -- no new empty window
		activate
		set allf to ""
		set c to count | my Video (or Audio) files |
		set ind to 0
		repeat with i in | my Video (or Audio) files |
			set ind to ind + 1
			set dotp to offset of "." in (reverse of (characters of (POSIX path of i)) as text)
			set allf to allf & "(echo Processing " & ind & " of " & c & ": " & quoted form of POSIX path of i & "; " & ¬
				"ffmpeg -v 32 -hide_banner -nostdin -i " & ¬
				quoted form of POSIX path of i & ¬
				" -af 'dynaudnorm=g=3:c=1:m=10:f=10:b=1' -map 0 -c:v copy -y " & ¬
				quoted form of ((characters 1 thru -(dotp + 1) of (POSIX path of i)) as text) & ¬
				"_AN" & ¬
				(characters -1 thru -dotp of (POSIX path of i) as text) & ¬
				")|| exit  && echo &&"
		end repeat
		do script "clear"
		delay 2
		set wi to (the id of window 1)
		do script ¬
			" clear; " & allf & " osascript  -e 'ignoring application responses'  -e 'tell app \"finder\"' -e 'delay .5'  -e 'tell app \"terminal\" to close window id " & wi & "'" & " -e 'end' -e 'end'  2>/dev/null &" in window id wi
		try
			repeat while (id of window id wi) > 0
				if processes of window id wi is {} then return
				delay 0.4
			end repeat
		end try
		delay 0.2
		if (count of windows) is 0 then quit
	end tell
end open

on run
	open (choose file with multiple selections allowed) -- launched without any dropped files
end run
I use ffpb or ffmpeg-bar for better ffmpeg progress display:

in.mp4: 100%|█████████████████| 4150/4150 [00:01<00:00, 2850.31 frames/s]

Edit: updated a bit to make it stop on errors
Post Reply