LinuxQuestions.org
Review your favorite Linux distribution.
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-02-2008, 05:32 AM   #1
Steven Hyde
LQ Newbie
 
Registered: May 2008
Posts: 3

Rep: Reputation: 0
Batch convert video in entire folder using ffmpeg


I am trying to schedule batch conversion of all mpeg in a single base folder to swf in another output folder, backup original mpeg, and delete original mpeg from base folder.

I would like to run when mpeg exist (appear) in base folder or on a schedule.

I was planning on scheduling bat files containing ffmpeg commands to run and use xcopy/del for backup but other posts seem to handle similar tasks with bash shell scripts (which I am not too familiar) I am open to whichever method works best.

When I try to run the following...I get the error "cannot open file C:\OUTPUT\*.swf"
Code:
c:\ffmpeg\ffmpeg.exe -i "C:\BASE\*.mpg" -ar 44100 -ab 192 "C:\OUTPUT\*.swf"
If I don't use wildcards and specify individual file names instead it works.


??????
Code:
for x in *.mpg; do ffmpeg -i "$x" -ar 44100 -ab 192  "`basename "$x" .mpg`.swf"; done

I am not sure how to use bash scripts similar to below to schedule conversions of an entire folder.

bash example: mpg2swf
Code:
#!/bin/bash

mkdir output
for x in *.mpg ; do
echo processing $x
ffmpeg -i $x -ar 44100 -ab 192 
output/$x
done
chmod a+x mpg2swf


Thanks.
 
Old 05-02-2008, 06:01 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,454
Blog Entries: 54

Rep: Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896
There are a gazillion applications and scripts already that can do what you want, but since your commandline works, lets just expand. I hope commentary is kind of self-explanatory else you might want to read some Bash scripting guides like http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html and http://www.tldp.org/LDP/Bash-Beginne...tml/index.html.

Code:
#!/bin/sh --
# The directory name that holds your movies.
DIR="/tmp/movies"
# Creating the subdirectory names that hold the result and the backup.
for NEW in swf backup; do
 mkdir "${DIR}/${NEW}" || { echo "Could not create ${DIR}/${NEW}, exiting."; exit 1; }
done
# Start looping over files, tell what we do and log any output to screen and log.
for MPEG in ${DIR}/*.mpg; do echo "Starting ${MPEG}"
 ffmpeg -i "${MPEG}" -ar 44100 -ab 192  "${DIR}/swf/${MPEG%.mpg}.swf" 2>&1 | tee -a "${DIR}/conversion.log"
 # If ffmpeg exited OK, then say it and move the original to the backup directory.
 if [ $? -eq 0 ]; then
  echo "Completed ${MPEG%.mpg}.swf"; mv "${MPEG}" ${DIR}/backup || { echo "Could not move ${MPEG}, exiting."; exit 1; }
 else
  # If ffmpeg failed, then say so and exit loop.
  echo "FAILED converting ${MPEG}, exiting."; exit 1; 
 fi
done # End of file loop
# Exit.
exit 0
...or in a less functional, terse format:
Code:
#!/bin/sh --
DIR="/tmp/movies"; for NEW in swf backup; do mkdir "${DIR}/${NEW}"; done
for MPEG in ${DIR}/*.mpg; do ffmpeg -i "${MPEG}" -ar 44100 -ab 192  "${DIR}/swf/${MPEG%.mpg}.swf" \
>/dev/null 2>&1; [ $? -eq 0 ] && mv "${MPEG}" ${DIR}/backup; done; exit 0
 
Old 05-02-2008, 06:58 AM   #3
seraphim172
Member
 
Registered: May 2008
Posts: 101

Rep: Reputation: 15
pathname syntax

The "cannot open file C:\OUTPUT\*.swf" error actually indicates that you are using a Windows-style pathname. On the other hand you are using a bash script, that would require UNIX-style pathnames. I suppose this is even true if you run CygWin on Windows, though I'm not sure of this.

Linux Archive

Last edited by seraphim172; 06-05-2008 at 10:32 AM.
 
Old 05-02-2008, 06:42 PM   #4
Steven Hyde
LQ Newbie
 
Registered: May 2008
Posts: 3

Original Poster
Rep: Reputation: 0
I'm sorry, it's still not working for me.
I am using cygwin in a WinXP environment.
I tested a simple bash script and it works using cygwin through bash.exe.
Code:
echo 123
read
However, using bash.exe to run the below script has no effect and closes without error.
I can't understand what I may be doing wrong.

Thanks for sticking with me on this...


seraphim172 - yes. The code that generated that error was run from win cmd line. It didn't work most likely because of my attempt to use wildcards to perform conversion on multiple files in a folder. Most likely this is incorrect ffmpeg syntax.

I am also looking into trying to schedule bash scripts and unSpawn is trying to help me figure this out.

If I knew the proper syntax to run ffmpeg on a folder from cmd I would use that. If I could work out a bash/shell script to do the same I would try to use that.

Applications and utilities I have found require manual selection of individual files in a folder to do batch conversion which is not flexible enough.

Thanks again.
 
Old 05-03-2008, 05:28 PM   #5
Steven Hyde
LQ Newbie
 
Registered: May 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Now I am able to get the error:
Quote:
line 20: syntax error: unexpected end of file
Any suggestions?
 
  


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
Script to automatically convert video files using ffmpeg jroyce Linux - Software 3 01-04-2008 11:17 PM
FFMPEG vs MPLAYER vs MENCODER and batch conversions to MP4 ? AngusM Linux - Software 2 11-08-2006 08:20 AM
mencoder/ffmpeg convert video(wmv) for Windows Mobile? paulx Linux - Software 2 06-26-2006 11:24 AM
how do i convert wmv to flv using ffmpeg? farmerjoe Linux - Software 0 11-15-2005 02:20 PM
Batch convert video files KimVette Linux - General 1 08-02-2005 09:13 PM


All times are GMT -5. The time now is 10:59 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