LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 12-30-2012, 11:49 AM   #1
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Rep: Reputation: 44
ffmpeg mass convert & merge video files from various formats


Hi all! I am pretty sure this wont be a tough one for the real ffmpeg Gurus but I have achieved minor success so far in converting videos with ffmpeg.

Basically, I have a folder with all kind of video files (.flv, .wmv, .mpeg .mp4...) you got the idea.. These files all have different resolutions (some are 640x480, others are 320x240, etc..) and I also assume they also have all kind of different codecs, etc..

I take that some were encoded in windows, some in Mac, some in Linux and with all kind of methods, applications etc..

In other words, its a mess. I'd like to mass (batch) convert all files to the exact same format (container, resolution, codecs, etc) for later on merge (concatenate) all of them into a single file.

A script would be nice. I'd dump all files in a folder, run the script and bingo, I get a big file and Im done.

So far I have used this command within the folder where all files are stored:
Quote:
$IFS=$'\n' ;for f in `ls *.wmv`; do FILE=$(basename $f .wmv) ;ffmpeg -i $FILE.wmv -target ntsc-dv $FILE.mpg; done
The problem is that it processes only wmv files, and I am not sure it will work flawlessly when I will play the output file (I am not knowledgeable enough in video processing to determine that). Also, the converted files are like 300%+ of the original file size.. I believe this is the -target ntsc-dv which is responsible of that..

I am pretty sure that there must be a script someone already worked on. I couldnt find anything like that.. Right now I am in some kind of a rush so I am looking for a quick fix instead of learning ffmpeg..

If someone can point me to something I'd be very grateful, otherwise I will keep searching and trying.

Thanks!

Last edited by lpallard; 12-30-2012 at 11:52 AM.
 
Old 12-30-2012, 11:57 AM   #2
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44
I *may* have found something. Trying as we "speak".... Ill post the results when done, but I am confident it will work. If so, KUDOS to the original writer!

To be continued !
 
Old 12-30-2012, 01:48 PM   #3
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,008

Rep: Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624
something like this mite work:
Code:
/usr/bin/mencoder *.* -o /dev/null -vc mpeg12 -vf pp=al:c,softskip,unsharp=l5x5:.25:c5x5:.25,harddup -channels 6 -oac lavc -lavcopts acodec=ac3:abitrate=192 -a52drc 1 -ovc xvid -xvidencopts pass=1:turbo:me_quality=6:vhq=4:threads=2:max_bframes=2:bvhq=1:nopacked:quant_type=h263:noqpel:nogmc:trellis:nointerlacing:chroma_me:chroma_opt:hq_ac:nolumi_mask:rc_reaction_delay_factor=0:rc_averaging_period=100:closed_gop:autoaspect -passlogfile out.log

/usr/bin/mencoder *.* -o moo-vee.avi -ffourcc XVID -vc mpeg12 -vf pp=al:c,softskip,unsharp=l5x5:.25:c5x5:.25,harddup -channels 6 -oac lavc -lavcopts acodec=ac3:abitrate=192 -a52drc 1 -ovc xvid -xvidencopts pass=2:bitrate=1500:me_quality=6:vhq=4:threads=2:max_bframes=2:bvhq=1:nopacked:quant_type=h263:noqpel:nogmc:trellis:nointerlacing:chroma_me:chroma_opt:hq_ac:nolumi_mask:rc_reaction_delay_factor=0:rc_averaging_period=100:closed_gop:autoaspect -passlogfile out.log

sleep 2

/usr/bin/mkvmerge   --title moo-vee --track-name 0:moo-vee --language 1:en --track-name 1:"AC3 5.1" moo-vee.avi  -o moo-vee.mkv
you didnt say what format/codec/resolution you wanted so i made many assumptions you will need to correct.

Last edited by schneidz; 12-30-2012 at 01:56 PM.
 
Old 12-30-2012, 06:03 PM   #4
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44
Wow these are LONNNNNG commands!! No chance I would have ever been able to formulate those..

The first command throws

Code:
-xvidencopts is not an MEncoder option
I indeed forgot to indicate which options I was searching for. MKV with 640x480 would be more than fine as most video clips are already crappy.. Other options as standard as possible (audio, framerate, etc). The end file will play on XBMC.

Can you modify these commands? Better, are you aware of some kind of wizard that could help me build such a command without spending countless hours trying different options until it works..?
 
Old 12-30-2012, 06:10 PM   #5
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,008

Rep: Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624
Quote:
Originally Posted by lpallard View Post
Wow these are LONNNNNG commands!! No chance I would have ever been able to formulate those..

The first command throws

Code:
-xvidencopts is not an MEncoder option
maybe you dont have xvid installed. if you run
Code:
xbmc@XBMCLive:~$ mencoder -ovc help
it will show you what options you have.
Quote:
Originally Posted by lpallard View Post
Can you modify these commands? Better, are you aware of some kind of wizard that could help me build such a command without spending countless hours trying different options until it works..?
the above was the output script i saved from xvidenc or h264enc.

Last edited by schneidz; 12-30-2012 at 06:14 PM.
 
Old 12-30-2012, 07:32 PM   #6
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44
You were right. My machine did not have xvid as a codec. However, I have tried on a different machine that has everything installed, the command (the first one you provided) starts well but after several minutes (10 or so..) it throws away:

Code:
==========================================================================
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
AUDIO: 22050 Hz, 1 ch, s16le, 16.0 kbit/4.54% (ratio: 2003->44100)
Selected audio codec: [ffwmav2] afm: ffmpeg (DivX audio v2 (FFmpeg))
==========================================================================
Opening video filter: [expand osd=1]
Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffwmv1] vfm: ffmpeg (FFmpeg WMV1/WMV7)
==========================================================================
Movie-Aspect is undefined - no prescaling applied.

New video file has different resolution or colorspace than the previous one.
FATAL: Cannot initialize video driver.
Movie-Aspect is undefined - no prescaling applied.

New video file has different resolution or colorspace than the previous one.
FATAL: Cannot initialize video driver.

Exiting...
Cannot initialize video driver? What does that mean in "layman's terms"??

Last edited by lpallard; 12-31-2012 at 02:24 PM.
 
Old 12-30-2012, 11:02 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Could you please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.

And please edit your previous posts so that it doesn't make the window side-scroll. Thanks!


Speaking of which, the command in the OP has a few weaknesses. I'm going to start by breaking it into a multi-line format, for readability:

Code:
$IFS=$'\n'
for f in `ls *.wmv`; do
	FILE=$(basename $f .wmv)
	ffmpeg -i $FILE.wmv -target ntsc-dv $FILE.mpg
done

1) The first problem is Don't Read Lines With For! While setting IFS to newline does work to avoid the main problem with it, it's more of a cludgy work-around than a true fix.


2) Useless Use of ls *. It does absolutely nothing here except waste an extra process.

Both 1 and 2 can be replaced more safely with a simple globbing pattern.


3) QUOTE ALL OF YOUR VARIABLE EXPANSIONS. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell (globbing patterns are also expanded). This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later.

http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes

Again, just like in #1, re-setting IFS works around it, but it's safer to just do it correctly.


4) While not actually a mistake, basename can be replaced with a simple parameter substitution.

There's also a kind of unusual and unnecessary code flow in the above, removing the extension globally, then re-adding it.

5) Since environment variables are generally all upper-case, it's good practice to keep your own user variables in lower-case or mixed-case to help differentiate them. You should also generally try to use variable names that clearly relate to their function in the script (but that don't conflict with existing command names, like "file").


Thus the corrected version should more properly look more like this:

Code:
for fname in *.wmv; do

	ffmpeg -i "$fname" -target ntsc-dv "${fname%.*}.mpg"

done

#or in a single line:
for fname in *.wmv; do ; ffmpeg -i "$fname" -target ntsc-dv "${fname%.*}.mpg" ; done
 
Old 12-31-2012, 12:03 AM   #8
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,008

Rep: Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624
Quote:
Originally Posted by lpallard View Post
You were right. My machine did not have xvid as a codec. However, I have tried on a different machine that has everything installed, the command (the first one you provided) starts well but after several minutes (10 or so..) it throws away:



Cannot initialize video driver? What does that mean in "layman's terms"??
seems like mencoder is expecting all the files to have the same resolution. changing all the files to the same resolution first mite work (not sure why mencoder cant do that in one throw).
maybe ffmpeg would be more efficient.

Last edited by schneidz; 12-31-2012 at 12:06 AM.
 
  


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to merge video files with ffmpeg GrepAwkSed Linux - Newbie 12 04-04-2012 02:33 AM
[SOLVED] how do i merge mp4 video files using ffmpeg ? dEnDrOn Linux - Software 2 02-04-2012 06:17 AM
using ffmpeg to convert video files acamus Linux - Newbie 2 01-04-2011 08:41 PM
LXer: Converting video & audio files using ffmpeg in GNU/Linux LXer Syndicated Linux News 0 05-30-2009 04:31 AM
Script to automatically convert video files using ffmpeg jroyce Linux - Software 3 01-04-2008 11:17 PM


All times are GMT -5. The time now is 01:34 AM.

Main Menu
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