![]() |
|
|||
![]()
Convert mp4 to mp3
I have a load of mp4 files with spaces in their names, the first line replaces the spaces with _ so that the second line can convert them to mp3. Code:
#!/bin/sh for f in *; do mv "$f" `echo $f | tr ' ' '_'`; done for X in *.mp4;do ffmpeg -i $X $X.mp3;done
__________________
Linux since 1999, & also a BSD user. ![]() |
|
|||
![]()
Instead of using back ticks ```` (the key under the ~) you can use the POSIX command substitution"$( command )" construct. It is easier on the eyes, and does not have some quirks that plagues the older ` command ` format.
Code:
for f in *; do mv "$f" $( echo $f | tr ' ' '_'); done
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump Last edited by J65nko; 19th September 2022 at 10:27 PM. |
|
|||
![]()
Thanks, it's the first time I've used tr, so copied what I'd found, (after trying it out in safety), & it worked OK. But I will alter my personal script to use $() in future.
__________________
Linux since 1999, & also a BSD user. ![]() |
|
|||
![]()
I think you need to use -vn flag to extract just the audio stream out of .mp4
Code:
ffmpeg -i video.mp4 -vn audio.mp3 |
|
|||
![]()
Yes, I had to use sed to swap '.mp4.' to just a single '.' - messy, but worked.
![]() Code:
##To remove .mp4 from *.mp4.mp3 files for file in *; do mv "$file" $(echo "$file" | sed -e 's/.mp4././g'); done I also had to remove excess punctuation from filenames, this is what I used, (I expect there are better solutions, but again, it worked reasonably well). Code:
##To keep A-Za-z0-9.- & remove all other #!/bin/bash for file in *; do mv "$file" $(echo "$file" | sed -e 's/[^A-Za-z0-9.-]//g'); done As you can probably see, I'm no expert at scripting, but I noticed others were trying to do what I wanted to do, so posted what worked in my case. ![]()
__________________
Linux since 1999, & also a BSD user. ![]() |
|
|||
![]() Code:
for X in *.mp4; do ffmpeg -i $X ${X%.mp4}.mp3; done |
|
|||
![]()
You're welcome! There are others:
Code:
$ foo=some.thing.mp4 $ echo ${foo%.*} some.thing $ echo ${foo%%.*} some $ echo ${foo#*m} e.thing.mp4 $ echo ${foo##*m} p4 |
|
|||
![]()
These are documented in ksh(1):
Code:
The following forms of parameter substitution can also be used: [snip] ${name#pattern} ${name##pattern} If pattern matches the beginning of the value of parameter name, the matched text is deleted from the result of substitution. A single `#' results in the shortest match, and two of them result in the longest match. ${name%pattern} ${name%%pattern} Like ${..#..} substitution, but it deletes from the end of the value. Code:
${parameter%[word]} Substitute parameter, deleting the smallest possible suffix matching word. ${parameter%%[word]} Substitute parameter, deleting the largest possible suffix matching word. ${parameter#[word]} Substitute parameter, deleting the smallest possible prefix matching word. ${parameter##[word]} Substitute parameter, deleting the largest possible prefix matching word.
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
||||
![]()
Keith's using a /bin/sh shebang so the POSIX reference is probably better:
https://pubs.opengroup.org/onlinepub...V3_chap02.html (Section 2.6.2 — Parameter Expansion) |
![]() |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
convmv - convert file names | victorvas | OpenBSD Packages and Ports | 2 | 30th July 2022 03:05 AM |
New Convert NFSv3 NFSv4 | bigearsbilly | OpenBSD General | 1 | 6th March 2020 12:37 PM |
sh script to convert inches to mm and cm | J65nko | Programming | 6 | 8th August 2019 11:33 PM |
Problem with convert | aleunix | OpenBSD Packages and Ports | 2 | 10th May 2012 01:52 PM |
Want to convert my server to raid | revzalot | OpenBSD Installation and Upgrading | 2 | 16th September 2009 07:56 PM |