ffmpeg script to convert files - Programming On Unix
Users browsing this thread: 1 Guest(s)
|
|||
Hey nixers, I'm trying to figure out how to write a short script to convert all the media files in a directory and delete the old files.
I found this on the web looking for answers PHP Code: #!/bin/bash So, my question is, how do I add other file types to the fist line so that if I have a folder which contains .mkv & .webm files then both file types will be converted to .mp4. Lastly, as this will create newly converted files, how can I have all old files deleted within this same script?
_____________________________________________________________________________________________
“Maybe you have some bird ideas... Maybe that's the best you can do.” - Terry A. Davis (R.I.P Terry & Percival) |
|||
|
|||
You just add the other types to the `for` loop. :) And for removing, well, use `rm`.
Code: #!/bin/bash Stuff after the `in` in a `for` really is just a list. You could also do this: Code: for i in hello world, how are you today? It’ll loop over the individual words. Globs like `*.webm` will be expanded before the iteration begins. |
|||
|
|||
Hi Ramiferous! I haven't actually played with ffmpeg before, but I'll assume that the command you provided is correct. This would be my solution to your problem:
Code: #!/bin/bash You could also take out the rm command and run Code: rm *.{mkv,webm} |
|||
|
|||
(15-03-2021, 03:00 AM)s0kx Wrote: I haven't actually played with ffmpeg before, but I'll assume that the command you provided is correct.Now that you mention it, I’m not sure if that’s really what he wants. It will only change the video’s container format but keep the codecs. So you can end up with an “unusual” combination like ”VP9 inside of MP4”. Depending on which program is used as a player, this might break playback. (Something like `mpv` will probably almost always work.) |
|||
|
|||
(15-03-2021, 03:15 AM)movq Wrote:(15-03-2021, 03:00 AM)s0kx Wrote: I haven't actually played with ffmpeg before, but I'll assume that the command you provided is correct.Now that you mention it, I’m not sure if that’s really what he wants. It will only change the video’s container format but keep the codecs. So you can end up with an “unusual” combination like ”VP9 inside of MP4”. Depending on which program is used as a player, this might break playback. (Something like `mpv` will probably almost always work.) Yeah, pretty much always using mpv (sometimes vlc if casting to chromecast). So are the curly brackets necessary? seems to work without them.
_____________________________________________________________________________________________
“Maybe you have some bird ideas... Maybe that's the best you can do.” - Terry A. Davis (R.I.P Terry & Percival) |
|||
|
|||
(15-03-2021, 07:57 PM)Ramiferous Wrote: So are the curly brackets necessary? seems to work without them. Not sure if this is what you're asking about, but: Code: for i in *.mkv *.webm and Code: for i in *.{mkv,webm} generate the same list of files, although the syntax used to describe the pattern to be matched is slightly different. The bracketed notation is just a compact way to say either file extension will do. It's a handy way to avoid retyping the common elements of two or more arguments. E.g., Code: cp original{,.bak} expands to Code: cp original original.bak Apologies if I've misunderstood your question and explained something you already knew! |
|||
|
|||
_____________________________________________________________________________________________
“Maybe you have some bird ideas... Maybe that's the best you can do.” - Terry A. Davis (R.I.P Terry & Percival) |
|||