|
cyber
|
 |
« on: 2009.06.09, 16:18:32 » |
|
This is posted by RobertM, in post "FLACs, OGGS and WAVs "Reply #16 on: 2009.05.21, 21:04:33 /* OGG to MP3 */ Parse Arg OggFileName
SAMPLERATE=22500 /* CHANGE AS NEEDED */ BITRATE=128 /* CHANGE AS NEEDED */
MP3FileName=SubStr(OggFileName,1,LastPos(translate(OggFileName),".OGG"))||"mp3"
'ffmpeg -i 'OGGFILENAME' -acodec libmp3lame -ac 2 -ar 'SAMPLERATE' -ab 'strip(BITRATE)'k -vol 256 'MP3FILENAME
I've just stripp comments, and code from example above doesn't work at all... MP3FileName is simply and only MP3 and not filename-"ogg"+"mp3".  What I want to ask is how to strip filename from path. For example; when start test.cmd s:\dir\filename.ext to got filename.ext as result in variable ?
|
|
|
|
« Last Edit: 2009.06.09, 16:39:34 by cyber »
|
Logged
|
|
|
|
warpcafe
Global Moderator
Hero Member
    
Posts: 746
Failure is not an option.
|
 |
« Reply #1 on: 2009.06.09, 16:50:56 » |
|
Hi, first I hope you did not strip ALL comments! You know that REXX needs the first line of the script to be a comment, right?  Second, this will only work with files of the extension ".ogg" (or ".OGG" - case is not important)... is that what you did? Other than that, I could not imagine a possible error. But getting back to your question: The way it's done is basically correct - the function searches for the LAST occurrence of ".OGG" in the fully-qualified filename (that is passed as a parameter). Then, it takes everything up to the "." of ".OGG" and puts "mp3" behind it. In your case, if only "MP3" come out, it means that the previous search for ".ogg" did not work and returned a nullstring... most likely, you did not pass a filename with ".ogg" in the end? You can retrieve the filename part by using the "filespec()" built-in function of rexx: say filespec("N", "s:\dir\filename.ext")
will give you "filename.ext" (without the quotes). Cheers, THT, Thomas
|
|
|
|
|
Logged
|
"It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that" - G.H. Hardy
|
|
|
|
herwigb
|
 |
« Reply #2 on: 2009.06.10, 09:55:33 » |
|
Hi, an alternative way is using the VX-REXX runtime DLL VROBJ.DLL, which is virtually available on any eCS (OS/2) system. Most functions of the VX-REXX runtime DLL also work in simple text mode scripts. As the DLL comes with many, many functions for all kind of purposes, it is definitely worth to look into it. Here's how you can do the same using VROBJ.DLL: /* Register VX-REXX Functions */
call RxFuncAdd 'VRLoadFuncs', 'VROBJ', 'VRLoadFuncs' call VRLoadFuncs
say VRParseFileName("D:\OS2\CMD.EXE", "D") say VRParseFileName("D:\OS2\CMD.EXE", "P") say VRParseFileName("D:\OS2\CMD.EXE", "N") say VRParseFileName("D:\OS2\CMD.EXE", "E")
You will get: D \OS2 CMD EXE The letters within the parenthesis may be combined, for example: say VRParseFilename("s:\dir\filename.ext","NE")
will give you "filename.ext" (like in Thomas example for filespec). Other example: say VRParseFilename("s:\dir\filename.ext","DP")
will give you "s:\dir". So you see, it is much more flexible than filespec(). Kind regards, Herwig
|
|
|
|
|
Logged
|
Kind regards, HerwigB.
|
|
|
|
jep
|
 |
« Reply #3 on: 2009.06.10, 12:01:49 » |
|
Hi, Ahh, VROBJ.DLL as a stand alone rexx dll, nice! But if you want to try FILESPEC anyway you may want to use: /* This is a comment on the first line to make it a rexx script */ PARSE VALUE FILESPEC( "N", "s:\dir\filename.ext" ) WITH fname".". say fname /* Will output "filename" without the quotes */
NOTICE!!! if the filename contains several "." (dots) it will return the first part of the filename, so you may loose some additional parts, so try: /* This is a comment on the first line to make it a rexx script */ PARSE VALUE REVERSE( FILESPEC( "N", "s:\dir\filename.ext" ) ) WITH ."."fname fname = REVERSE( fname ) say fname /* Will output "filename" without the quotes */
//Jan-Erik
|
|
|
|
« Last Edit: 2009.06.10, 12:23:22 by jep »
|
Logged
|
|
|
|
warpcafe
Global Moderator
Hero Member
    
Posts: 746
Failure is not an option.
|
 |
« Reply #4 on: 2009.06.10, 13:39:13 » |
|
Hey, So you see, it is much more flexible than filespec().
Show-off!  Cheers Thomas
|
|
|
|
|
Logged
|
"It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that" - G.H. Hardy
|
|
|
warpcafe
Global Moderator
Hero Member
    
Posts: 746
Failure is not an option.
|
 |
« Reply #5 on: 2009.06.10, 13:41:30 » |
|
Hi, /* This is a comment on the first line to make it a rexx script */ PARSE VALUE REVERSE( FILESPEC( "N", "s:\dir\filename.ext" ) ) WITH ."."fname fname = REVERSE( fname ) say fname /* Will output "filename" without the quotes */
I had tgo look twice to understand, but... yeah! Never thought of using REVERSE() in THAT way. Lovely!  Cheers, Thomas
|
|
|
|
|
Logged
|
"It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that" - G.H. Hardy
|
|
|
|
cyber
|
 |
« Reply #6 on: 2009.06.10, 14:23:32 » |
|
To Jep: Thanks, this kick ass ! To WarpCafe: "I had tgo look twice to understand, but... yeah!" I do not understand even after third look, but I can implement.  It has no time loop for input funtions, but hitting ENTER twice isn't such hard.  It isn't perfect yet, It may be interesting to add stream mapping too, but maybe latter. I've test this script with mp4, wma, mpeg and flv and all work ok. /* Convert everything to mp3 using FFmpeg */ /* You need to change path to FFmpeg !!!! */
/* Default values */ SAMPLERATE=44100 /* CHANGE AS NEEDED */ BITRATE=64 /* CHANGE AS NEEDED */ FFmpeg_pth="C:\TOOLS\M600\ffmpeg.exe" /* path where is FFmpeg, if FFmpeg IS in path, then just ffmpeg.exe */
/* end of configuration !!!! */ call LblueCol
Say "" Say " ███ ███ █ █ █ █ ████ ███ ███" Say " █ █ █ ██ █ █ █ █ █ █ █" Say " █ █ █ █ ██ █ █ ██ ███ █ everything to mp3" say " █ █ █ █ █ █ █ █ █ █ █" say " ███ ███ █ █ █ ████ █ █ █ Thanks to WarpCafe, Jep and RobertM"
call YellowCol say" "
Parse Arg v1ideost if v1ideost="" then call nofile
Call GreenCol FFmpeg_pth" -i "v1ideost Call WhiteCol say "Enter samplerate (enter for default to "SAMPLERATE")" Call GreenCol tsample=LINEIN() If tsample="" then tsample=SAMPLERATE Call WhiteCol say "Enter bitrate (enter for default to "BITRATE")" Call GreenCol tbit=LINEIN() If tbit="" then tbit=BITRATE
PARSE VALUE REVERSE( FILESPEC( "N", v1ideost ) ) WITH ."."fname fname = REVERSE( fname ) gname="'"fname".mp3'"
FFmpeg_pth' -i 'v1ideost' -acodec libmp3lame -ac 2 -ar 'tsample' -ab 'strip(tbit)'k -vol 256 'gname
call WhiteCol Say "convertion complete"
exit
RedCol: CALL CHAROUT ,"1B"x||'[1m'||"1B"x||'['||31||'m' return
GreenCol: CALL CHAROUT ,"1B"x||'[1m'||"1B"x||'['||32||'m' return
WhiteCol: CALL CHAROUT ,"1B"x||'[1m'||"1B"x||'['||37||'m' return
LblueCol: CALL CHAROUT ,"1B"x||'[1m'||"1B"x||'['||36||'m' return
YellowCol: CALL CHAROUT ,"1B"x||'[1m'||"1B"x||'['||33||'m' return
YellGreyCol: CALL CHAROUT ,"1B"x||'[1m'||"1B"x||'['||5||'m' return
YellRedCol: CALL CHAROUT ,"1B"x||'[1m'||"1B"x||'['||41||'m' return
cYellRedCol: CALL CHAROUT ,"1B"x||'[1m'||"1B"x||'['||40||'m' return
nofile: call YellRedCol say say" Must have source file as argument" call cYellRedCol
say "" say "exiting..." pause exit
|
|
|
|
« Last Edit: 2009.06.11, 00:24:11 by cyber »
|
Logged
|
|
|
|
|
jep
|
 |
« Reply #7 on: 2009.06.10, 14:25:05 » |
|
 You're welcome cyber. using vrobj.dll provide the short and elegant solution. and for those of you that didn't bother to look twice to see why you should reverse filespec... here's the explanation. - Let's say that the path is "S:\path\2\my\music\Artist.Name-Song.1.ext"
- filespec with the parameter "N" will return the filename part, "Artist.Name-Song.1.ext"
- We only know that "." (dot) is the delimiter for the extension
- If we just look for the dot and not the text, we can support more file extensions and formats with the same code.
- "parse value" will split the text up at the first dot found, while we want it to remove the last part
- The result will then just be "Artist" in this example
- If we instead reverse the text before we parse it, it will become "1.gonS-emaN.tsitrA" just as we want it (except for the reversed order)
- That's why we have to use an extra row to reverse it back to the original order
|
|
|
|
« Last Edit: 2009.06.10, 15:34:44 by jep »
|
Logged
|
|
|
|
|
cyber
|
 |
« Reply #8 on: 2009.06.10, 14:37:58 » |
|
A-ha, very easy when You explain like that. But I'l probably newer found this by my self.
|
|
|
|
|
Logged
|
|
|
|
|
jep
|
 |
« Reply #9 on: 2009.06.10, 17:07:19 » |
|
Ahh cyber, now you've extended your script to an almost complete tool, neat!
//Jan-Erik
|
|
|
|
|
Logged
|
|
|
|
warpcafe
Global Moderator
Hero Member
    
Posts: 746
Failure is not an option.
|
 |
« Reply #10 on: 2009.06.10, 19:06:42 » |
|
I like the credits it displays. 
|
|
|
|
|
Logged
|
"It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that" - G.H. Hardy
|
|
|
|
cyber
|
 |
« Reply #11 on: 2009.06.11, 00:19:43 » |
|
Ahh cyber, now you've extended your script to an almost complete tool, neat!
Sugestions, corrections ? It may be nice to support list of files too, but on other side, this can be done using FileComander/2 without change code except for enter action ? I like the credits it displays.  Some smart people I know.  I've forgot RobertM, important line of code is his writing.
|
|
|
|
« Last Edit: 2009.06.11, 00:26:58 by cyber »
|
Logged
|
|
|
|
|
jep
|
 |
« Reply #12 on: 2009.06.11, 09:54:35 » |
|
 cyber It's quite complete as it is... but ok, a) find and (re)use path to ffmpeg automagically See: " Use EA to store information and settings" how to read and store e.g. path to ffmpeg so the user doesn't have to change the settings in your script. You have to search for the executable with "SysFileTree" if the EA doesn't return anything useful. b) List of files? Then I'd suggest either to use the folder¹ approach or a loop² ¹) Drag a folder to the .cmd-file or type the path to the folder as a parameter when you start the .cmd-file and it scan the folder for files. SysFileTree( ARG(1)||"\*", "files", "FO" ) do i = 1 to files.0 retval = Convert2MP3( filename, counter ) end ²) Ask what file to process where you have to enter data by hand for each until file (text) can't be found. do forever retval = Convert2MP3( filename ) say 'Next file to convert:' filename = linein() if STREAM( filename, "C", "QUERY EXISTS" ) = "" then return 0 Call SysCls end //Jan-Erik
|
|
|
|
|
Logged
|
|
|
|
|
RobertM
|
 |
« Reply #13 on: 2009.06.20, 03:41:34 » |
|
The way it's done is basically correct - the function searches for the LAST occurrence of ".OGG" in the fully-qualified filename (that is passed as a parameter). Then, it takes everything up to the "." of ".OGG" and puts "mp3" behind it. In your case, if only "MP3" come out, it means that the previous search for ".ogg" did not work and returned a nullstring... most likely, you did not pass a filename with ".ogg" in the end?
Yes... there was absolutely no error checking in my script. One reason is I use it by object association and not (or rarely) by commandline. That means there will never be an error in the filename sent as only right-clicking on an OGG file will give the "Convert to..." option (unless I severely screwed up what I associated the script to). And second, I didnt have the time to flesh it out for more general use (which, had I that time when I posted it, it would have included a "pop-up" requesting bitrate and such if none was specified, and various other tweaks, including a progress bar and more). Best, Rob
|
|
|
|
|
Logged
|
|
|
|
|