LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 05-16-2012, 01:42 PM   #1
ejames82
Member
 
Registered: Jun 2009
Posts: 93

Rep: Reputation: 15
need help with command bulk convert/rename .flv to .mpg


hello,

could I please get some command-line help, my knowledge is limited, and my luck has been good at receiving help in this area at this site.

I have been able to convert .flv files to .mpg with ffmpeg with quality results with this command:

Code:
ffmpeg -i input.flv -sameq output.mpg
though the command works great, it definitely needs to RENAME IN BULK, and if possible, also remove the .flv from the name (after the convert and rename) as it is no longer needed.


I have a command here (below) that does/comes 'close' to what I need, but it converts from .MTS to .avi (to allow my camcorder footage to be viewed on pc with ffmpeg). maybe posting it as info can help in some way. it converts and renames in bulk. I know there are parameters that wouldn't belong in a '.flv to .mpg'. I know because I tried. I also tried substitutions where I thought they should be, but failed.

Code:
for file in *.MTS; do ffmpeg -i "$file" -f avi -vcodec dvvideo -s pal -aspect 4:3 -qscale 4 -acodec pcm_s16le -ac 2 $file.avi; done

please allow me to clarify
I need a command that bulk converts and renames, from .flv to .mpg, and preferably also removes .flv from the name after renaming.

thank you.
 
Old 05-16-2012, 01:53 PM   #2
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,214

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
not sure what you mean by bulk rename... ffmpeg command allows you to indicate what you want to name the output file:
Code:
ffmpeg -i $file -sameq `echo $file | sed s/flv/mpg/`

Last edited by schneidz; 05-16-2012 at 01:54 PM.
 
Old 05-16-2012, 01:57 PM   #3
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,159

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
Code:
ffmpeg -i $file -sameq ${file%%.*}.mpg
do not use pipe and sed instead of parameter substitution
see http://www.linuxquestions.org/questi...script-945195/
 
1 members found this post helpful.
Old 05-16-2012, 04:37 PM   #4
ejames82
Member
 
Registered: Jun 2009
Posts: 93

Original Poster
Rep: Reputation: 15
@schneidz

thanks for the quick reply.
bulk rename means multiple, many, or numerous. if I left the computer on overnight, it would convert and rename each file, one at a time until complete, then go on to the next one until all are done, no matter how long it takes. the example I speak of in the first post works in that fashion, though it converts and renames files from .MTS to .avi, it names 0.MTS to 0.avi, then 1.MTS to 1.avi, and so on. although it converts and names them one at a time, the command allows it to continue until all files are converted and renamed.
yes, ffmpeg also allows you to choose a name, or the terminal does (or both do), but you would know that better than me.

I will give your command a shot and let you know.


@pan64

thanks for the quick reply.
I think what you are suggesting is that the command offered by schneidz needs a little adjustment.

I will give your command a shot and let you know.
 
Old 05-16-2012, 05:05 PM   #5
ejames82
Member
 
Registered: Jun 2009
Posts: 93

Original Poster
Rep: Reputation: 15
it looks like both commands suffered the same fate. check it out.


schneidz's command

ed@ed-5310S:~/dwh/dwhelper2$ ffmpeg -i $file -sameq `echo $file | sed s/flv/mpg/`
ffmpeg version 0.8.1-4:0.8.1-0ubuntu1, Copyright (c) 2000-2011 the Libav developers
built on Mar 22 2012 05:29:10 with gcc 4.6.3
This program is not developed anymore and is only provided for compatibility. Use avconv instead (see Changelog for the list of incompatible changes).
-sameq: No such file or directory
ed@ed-5310S:~/dwh/dwhelper2$


pan64's command

ed@ed-5310S:~/dwh/dwhelper2$ ffmpeg -i $file -sameq ${file%%.*}.mpg
ffmpeg version 0.8.1-4:0.8.1-0ubuntu1, Copyright (c) 2000-2011 the Libav developers
built on Mar 22 2012 05:29:10 with gcc 4.6.3
This program is not developed anymore and is only provided for compatibility. Use avconv instead (see Changelog for the list of incompatible changes).
-sameq: No such file or directory


it looks like the -sameq is not in the right place, or something else should be in there instead.
 
Old 05-17-2012, 08:36 AM   #6
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,214

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Quote:
Originally Posted by pan64 View Post
Code:
ffmpeg -i $file -sameq ${file%%.*}.mpg
do not use pipe and sed instead of parameter substitution
see http://www.linuxquestions.org/questi...script-945195/
ouch! last time i got my hand slapped like that i was in the 3rd grade (rep added.)
 
Old 05-17-2012, 08:41 AM   #7
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,214

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Quote:
Originally Posted by ejames82 View Post
@schneidz

thanks for the quick reply.
bulk rename means multiple, many, or numerous. if I left the computer on overnight, it would convert and rename each file, one at a time until complete...
a little bit confusing. just so you are aware you arent renaming files (that would be the mv command), you are converting video files and specifying what you want as the output files. just put my command (or better, pan's correction) in a loop.

Last edited by schneidz; 05-17-2012 at 08:50 AM.
 
Old 05-17-2012, 08:48 AM   #8
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,214

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Quote:
Originally Posted by ejames82 View Post
it looks like both commands suffered the same fate. check it out.


schneidz's command

ed@ed-5310S:~/dwh/dwhelper2$ ffmpeg -i $file -sameq `echo $file | sed s/flv/mpg/`
ffmpeg version 0.8.1-4:0.8.1-0ubuntu1, Copyright (c) 2000-2011 the Libav developers
built on Mar 22 2012 05:29:10 with gcc 4.6.3
This program is not developed anymore and is only provided for compatibility. Use avconv instead (see Changelog for the list of incompatible changes).
-sameq: No such file or directory
ed@ed-5310S:~/dwh/dwhelper2$


pan64's command

ed@ed-5310S:~/dwh/dwhelper2$ ffmpeg -i $file -sameq ${file%%.*}.mpg
ffmpeg version 0.8.1-4:0.8.1-0ubuntu1, Copyright (c) 2000-2011 the Libav developers
built on Mar 22 2012 05:29:10 with gcc 4.6.3
This program is not developed anymore and is only provided for compatibility. Use avconv instead (see Changelog for the list of incompatible changes).
-sameq: No such file or directory


it looks like the -sameq is not in the right place, or something else should be in there instead.
whats the value of the $file variable ?:
Code:
echo file = $file
this is taken from your initial post:
Code:
for file in *.MTS; do ffmpeg -i "$file" -f avi -vcodec dvvideo -s pal -aspect 4:3 -qscale 4 -acodec pcm_s16le -ac 2 $file.avi; done
we assumed from this post that you were already running this in a loop, try this:
Code:
for file in *.flv
do
 ffmpeg -i $file -sameq ${file%%.*}.mpg
done

Last edited by schneidz; 05-17-2012 at 08:49 AM.
 
Old 05-17-2012, 11:30 AM   #9
ejames82
Member
 
Registered: Jun 2009
Posts: 93

Original Poster
Rep: Reputation: 15
"ouch! last time i got my hand slapped like that i was in the 3rd grade (rep added.)"
yes, but that slap was close to non-existent on the slap-o-meter. was it a bare hand or a ruler for you?

just a question about the command (for both of you) should the $file be in quotes? "$file"

"a little bit confusing. just so you are aware you arent renaming files (that would be the mv command), you are converting video files and specifying what you want as the output files. just put my command (or better, pan's correction) in a loop."
my fault for being incorrect in my explanation. It's hard to say what I mean. ffmpeg keeps the old .MTS file with the old name. the actual first files name is 00000.MTS which is kept and then ffmpeg makes the conversion and adds into the folder an avi file of 00000.avi. ffmpeg keeps 00001.MTS, but adds 00001.avi, keeps 00002.MTS, and adds 00002.avi and so on. it keeps adding an avi file until all .MTS files have an avi copy.


"whats the value of the $file variable ?:"
I wasn't sure how to provide an answer to this, so I covered as many bases as I could think of.

ed@ed-5310S:~$ echo file = $file
file =
ed@ed-5310S:~$

ed@ed-5310S:~/dwh/dwhelper2$ echo file = $file
file =


I have tried your command below (I just tried it):

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

IT WORKED!
it was only two files, I should try it on more than two (and I will)
I will let you know how it goes, we can probably forget about alot that was discussed earlier
and thanks
 
Old 05-17-2012, 01:54 PM   #10
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,214

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Quote:
Originally Posted by ejames82 View Post
"ouch! last time i got my hand slapped like that i was in the 3rd grade (rep added.)"
yes, but that slap was close to non-existent on the slap-o-meter. was it a bare hand or a ruler for you?
bare hand. miss morsen wouldve been fired if anything more.
Quote:
Originally Posted by ejames82 View Post
just a question about the command (for both of you) should the $file be in quotes? "$file"
its a good habit to put variables in quotes especially if there are spaces in them.
Quote:
Originally Posted by ejames82 View Post
"a little bit confusing. just so you are aware you arent renaming files (that would be the mv command), you are converting video files and specifying what you want as the output files. just put my command (or better, pan's correction) in a loop."
my fault for being incorrect in my explanation. It's hard to say what I mean. ffmpeg keeps the old .MTS file with the old name. the actual first files name is 00000.MTS which is kept and then ffmpeg makes the conversion and adds into the folder an avi file of 00000.avi. ffmpeg keeps 00001.MTS, but adds 00001.avi, keeps 00002.MTS, and adds 00002.avi and so on. it keeps adding an avi file until all .MTS files have an avi copy.
an rm *.MTS at the end of the script would get rid of the files you dont want.
Quote:
Originally Posted by ejames82 View Post


"whats the value of the $file variable ?:"
I wasn't sure how to provide an answer to this, so I covered as many bases as I could think of.

ed@ed-5310S:~$ echo file = $file
file =
ed@ed-5310S:~$

ed@ed-5310S:~/dwh/dwhelper2$ echo file = $file
file =
i had you test this for yourself so you would realize the file variable isntt being set and therefore ffmpeg has no input to work on.
Quote:
Originally Posted by ejames82 View Post

I have tried your command below (I just tried it):

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

IT WORKED!
it was only two files, I should try it on more than two (and I will)
I will let you know how it goes, we can probably forget about alot that was discussed earlier
and thanks
hopefully you dont forget and use your mistakes as a way to learn/ adapt for problems in the future.
 
Old 05-17-2012, 04:00 PM   #11
ejames82
Member
 
Registered: Jun 2009
Posts: 93

Original Poster
Rep: Reputation: 15
"bare hand. miss morsen wouldve been fired if anything more."
Mrs Dudley was allowed to use a ruler and took advantage. I admit I was deserving.

"just a question about the command (for both of you) should the $file be in quotes? "$file"
its a good habit to put variables in quotes especially if there are spaces in them.
"
do you mean spaces in the names? I have seen where that causes trouble.

"an rm *.MTS at the end of the script would get rid of the files you dont want."
the first command was convert .MTS to avi. if you want to show me how to add that in I would be most grateful (I want to be sure).
the second command was convert .flv to mpg. I actually found a seperate command for eliminating the no-longer-wanted flv files. this probably works for any type of file in a given directory.

Code:
find . -type f -name "*.flv" -exec rm -f {} \;
by the way, your command worked to a tee. I checked it out on a sizeable directory full of flv's without fail. If you can think up a way to remove the leftover flv's from the directory, that would be super. I never really thought that far ahead.

"i had you test this for yourself so you would realize the file variable isntt being set and therefore ffmpeg has no input to work on."
I would rather be honest here and admit that I don't know what you mean. was this command some kind of test?

schneidz, I have to say, you went from being "very bad" (just kidding) to pulling the command out of thin air. I don't know how you did it. you know your command line "stuff".
thank you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] flv to mpg timl Linux - Software 2 10-27-2010 10:14 PM
shell command for bulk 'rename' ashrafulkarim Linux - Newbie 5 12-17-2008 04:46 AM
Converting flv to Mpg with Audio and ffmpeg btbx Linux - Software 7 06-12-2008 03:41 PM
LXer: Convert .flv (Google Videos) to .mpg using ffmpeg LXer Syndicated Linux News 0 07-25-2007 07:31 AM


All times are GMT -5. The time now is 06:47 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration