LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-28-2014, 09:36 AM   #1
ejames82
Member
 
Registered: Jun 2009
Posts: 110

Rep: Reputation: 15
ffmpeg - want it to convert/rename/batch, don't overwrite or ask to


Hello,


here are my files:

a.flv
a.mp4
b.flv
c.flv

I would like to have ffmpeg convert flv files to mp4 if there is not one, rename them, then move on to the next flv. if it finds that an mp4 already exists with the same name, I don't want it to ask, and I don't want it to overwrite.

I have a command script, but it stops to ask to overwrite. in the example above, it will ask about a.flv
I want ffmpeg to skip a.flv (because there is already a.mp4) and move on to b.flv, then c.flv

here is my script (it works great, except for the overwrite issue):


for file in *.flv
do
ffmpeg -i $file -sameq ${file%%.*}.mp4
done


I realize that ffmpeg is supposed to work with the -n option, I tried the -n option (perhaps a mistake on my part, I hope someone points out where I went wrong) and got an error:

Unrecognized option 'n'
Failed to set value 'thefile.flv' for option 'n'



here is what that failed script looks like. I assumed just change the i to n

for file in *.flv
do
ffmpeg -n $file -sameq ${file%%.*}.mp4
done


it's possible that I have an older version of ffmpeg, and the n option is not included. I would rather not uninstall/reinstall if possible. instead I have a little chunk of code that may help. I don't know how it would be implimented, or if there is any way to make it work correctly. I read something about curved brackets and a colon could be used.

echo "n" | <some command to ask you y/n>


can this little piece of code be merged into my script successfully?

thanks.
 
Old 01-28-2014, 10:09 AM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
4 Years here and no code tags?
Tsk tsk.
 
Old 01-28-2014, 10:27 AM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
check if file exists:
Code:
if [ -e /path/to/file ]
then
 echo file exists
fi
 
Old 01-28-2014, 10:51 AM   #4
ejames82
Member
 
Registered: Jun 2009
Posts: 110

Original Poster
Rep: Reputation: 15
Hello schneidz,

so would the command look like this?


Code:
for file in *.flv
do
ffmpeg -i $file -sameq ${file%%.*}.mp4
if [ -e /path/to/file ]
then
 echo file exists
fi
done
also, if I am already in the same folder in the terminal, what would I substitute 'path/to/file' with? I usually cd to the folder with the files.

much thanks as always.


thanks to Habitual as well. I tried it, I hope it worked.
 
Old 01-28-2014, 10:58 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
i would check to see if the file exists before i overwrite the file.
/path/to/file would be the whole filename that you are working on.
 
Old 01-28-2014, 11:26 AM   #6
ejames82
Member
 
Registered: Jun 2009
Posts: 110

Original Poster
Rep: Reputation: 15
schneidz,


I think you may misunderstand what I need (my fault).

I'm converting/renaming hundreds of flv files to mp4, and many already have an eqivalent/converted mp4, so instead of the terminal wasting time converting them (overwriting them is converting them again, isn't it?) I want the command to also state that if there already is a mp4 file of that name, don't ask to overwrite, and don't overwrite. ultimately what I want the command to do is make sure that each flv has a mp4 and does it without intervention or overwriting. I can leave it go overnight and it would get as much done if possible, if not all.

off-topic:
you probably didn't notice, but you provided me with that command years ago. it works great for batch converting and renaming flv files to mp4.

thanks
 
Old 01-28-2014, 11:40 AM   #7
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Code:
for file in *.flv
do
  mp4=${file%%.*}.mp4
  if [ ! -e $mp4 ] ; then
    ffmpeg -i $file -sameq $mp4
  fi
done
 
Old 01-28-2014, 12:11 PM   #8
ejames82
Member
 
Registered: Jun 2009
Posts: 110

Original Poster
Rep: Reputation: 15
Hello Guttorm,


I tried the command you provided in a test folder. it worked great. it skipped over flv's with mp4's already present and converted those without. didn't say a word until done.
I have every reason to believe that it will always work without a problem, but I would like to leave the thread open for a couple of days in case I (or others) have other thoughts.

thanks to Guttorm, schneidz, and Habitual.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash - rename directory to overwrite existing LarsWestergren Linux - Newbie 18 04-04-2013 02:07 PM
Batch convert video in entire folder using ffmpeg Steven Hyde Linux - General 4 05-03-2008 05:28 PM
Batch Rename shelfitz Linux - Newbie 19 10-12-2006 10:23 PM
Cannot edit, delete, rename, or overwrite lilo.cof R_Shackleford Slackware 2 05-13-2006 05:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration