LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-28-2012, 03:56 PM   #1
Dafydd
Member
 
Registered: Oct 2008
Posts: 311

Rep: Reputation: 23
Converting video formats


Using the script below, I have converted the format of 20 videos. Took 119 hours 14 minutes.

Code:
#! /bin/bash
## convert video for use on website.

for filename in *.ogg;
	do
	  if [ -f "$filename" ]
    then
		 outfile=${filename%.*} ## strip off the extension
			ffmpeg -i "$filename" "$outfile".webm
	  fi
	done
I still have the 'mp4' format and the 'swf' format to go.

Is there a faster way to do this? Something simular to this?
Code:
 
ffmpeg -i "$filename" -o "$outfile".mp4 -o "$outfile".swf
OR!!!

Even a 10% reduction in run time over the 2 formats would mount to a whole day.

Dave
 
Old 09-28-2012, 04:31 PM   #2
Dman58
Member
 
Registered: Nov 2010
Location: The Danger Zone
Distribution: Slackware, Mint, & random selection for VM
Posts: 214

Rep: Reputation: 26
Overclock your machine, upgrade your cpu & ram. Lol

Maybe since they have been converted already you can use those new files to convert to the next desired formats. Instead of converting them all over to a new format.

Does this make sense?
 
Old 09-28-2012, 05:01 PM   #3
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 4,766

Rep: Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467
Are you just changing the container format? You can add the -acodec copy and -vcodec copy flags to ffmpeg, and it won't recompress the audio and video.
 
Old 09-28-2012, 05:08 PM   #4
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch
Posts: 421

Rep: Reputation: 18
Quote:
Originally Posted by Dafydd View Post
Using the script below, I have converted the format of 20 videos. Took 119 hours 14 minutes.

Code:
#! /bin/bash
## convert video for use on website.

for filename in *.ogg;
	do
	  if [ -f "$filename" ]
    then
		 outfile=${filename%.*} ## strip off the extension
			ffmpeg -i "$filename" "$outfile".webm
	  fi
	done
I still have the 'mp4' format and the 'swf' format to go.

Is there a faster way to do this? Something simular to this?
Code:
 
ffmpeg -i "$filename" -o "$outfile".mp4 -o "$outfile".swf
OR!!!

Even a 10% reduction in run time over the 2 formats would mount to a whole day.

Dave
Assuming there are no directory names ending in '.ogg', you could rewrite it as
Code:
for fl in *.ogg; do ffmpeg -i "$fl" -o "${fl%.*}".webm; done
but it would make no appreciable difference in the time

I've never done web videos myself, nor used ffmpeg, but I do a lot of dvd encoding with both mencoder and HandBrake. They both average about 2 hours per dvd for a 2 pass process. Is ffmpeg perhaps being thrown off by your using a music encoding suffix (ogg) for files that actually are videos? As in trying every format that it will handle to determine what your ogg files actually are. What does its log file have to say?
 
Old 09-28-2012, 05:13 PM   #5
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,592
Blog Entries: 2

Rep: Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047Reputation: 4047
Quote:
Originally Posted by porphyry5 View Post
Is ffmpeg perhaps being thrown off by your using a music encoding suffix (ogg) for files that actually are videos? As in trying every format that it will handle to determine what your ogg files actually are. What does its log file have to say?
Ogg is not a music encoding format, it is a container format, like avi is. The actual audio codec is named Vorbis, the video codec is name Theora: http://www.theora.org/faq/#13
 
2 members found this post helpful.
Old 09-29-2012, 10:32 AM   #6
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch
Posts: 421

Rep: Reputation: 18
Quote:
Originally Posted by TobiSGD View Post
Ogg is not a music encoding format, it is a container format, like avi is. The actual audio codec is named Vorbis, the video codec is name Theora: http://www.theora.org/faq/#13
Thank you for that clarification, I've only ever encountered ogg music files before.
 
Old 09-30-2012, 06:14 PM   #7
Dafydd
Member
 
Registered: Oct 2008
Posts: 311

Original Poster
Rep: Reputation: 23
Quote:
Originally Posted by dugan View Post
Are you just changing the container format? You can add the -acodec copy and -vcodec copy flags to ffmpeg, and it won't recompress the audio and video.
You have ask a question for which I don't have an answer.

I used only the 'ogg' in a tread recently posted. Deeper research has produced this information

HTML Supported.
Code:
Browser			MP4	WebM	Ogg
___________________________________________________
Internet Explorer 9	YES	NO		NO
Firefox 4.0		NO	YES		YES
Google Chrome 6		YES	YES		YES
Apple Safari 5		YES	NO		NO
Opera 10.6		NO	YES		YES
I was trying to get a modified version of this code snippet from W3School to work.
Code:
<!DOCTYPE html>
<html>
<body>

<video width="640" height="480" controls="controls" autoplay="autoplay">
  <source src="movie.ogg" type="video/ogg">
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.webm" type="video/webm">
<!-- Object tag deleted -->
</video>

</body>
</html>
Will 'iPad' accept one of these containers?
This VIDEO stuff is a new learning curve for me. Thanks for you help and feed back.
Dave

Last edited by Dafydd; 09-30-2012 at 06:16 PM.
 
Old 09-30-2012, 07:26 PM   #8
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 4,766

Rep: Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467
You're encoding for the web? Don't even bother with ogg containers or Theora video. There is no browser whose currently supported version supports theora video in an ogg container, but not vp8 video in a webm container.

Just do one patent-encumbered h264/mp3/mp4 encode and one patent-unencumbered vp8/vorbis/webm encode. Something like this should cover you:

Code:
ffmpeg -i input.avi -vcodec libx264 -acodec mp3 movie.mp4
ffmpeg -i input.avi -vcodec libvpx_vp8 -acodec vorbis movie.webm
This combination will work in every current browser.

Code:
<video>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.webm" type="video/webm">
</video>

Last edited by dugan; 09-30-2012 at 07:38 PM.
 
1 members found this post helpful.
Old 09-30-2012, 09:56 PM   #9
BenCollver
Rogue Class
 
Registered: Sep 2006
Location: OR, USA
Distribution: Slackware 14.1
Posts: 160

Rep: Reputation: 50
Quote:
Originally Posted by porphyry5 View Post
Assuming there are no directory names ending in '.ogg', you could rewrite it as
Code:
for fl in *.ogg; do ffmpeg -i "$fl" -o "${fl%.*}".webm; done
but it would make no appreciable difference in the time
Assuming you have a processor with 2 cores, you could speed it up by transcoding 2 videos in parallel. Off the cuff, it could look like the following:

Code:
cores=2
i=0
for fl in *.ogg
do
    ffmpeg -i "$fl" -o "${fl%.*}.webm" >/dev/null 2>&1 &
    i=$(($i + 1))
    if [ $i -ge $cores ]
    then
        wait
        i=0
    fi
done
-Ben
 
1 members found this post helpful.
Old 10-01-2012, 06:40 AM   #10
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch
Posts: 421

Rep: Reputation: 18
Quote:
Originally Posted by BenCollver2 View Post
Assuming you have a processor with 2 cores, you could speed it up by transcoding 2 videos in parallel. Off the cuff, it could look like the following:

Code:
cores=2
i=0
for fl in *.ogg
do
    ffmpeg -i "$fl" -o "${fl%.*}.webm" >/dev/null 2>&1 &
    i=$(($i + 1))
    if [ $i -ge $cores ]
    then
        wait
        i=0
    fi
done
-Ben
Thank you, I'd just naively assumed multi-core processors used their capabilities automatically. And presumably this technique can be adapted to any number of cores, for any lengthy process that has a series of inputs.
 
Old 10-01-2012, 07:33 AM   #11
BenCollver
Rogue Class
 
Registered: Sep 2006
Location: OR, USA
Distribution: Slackware 14.1
Posts: 160

Rep: Reputation: 50
Quote:
Originally Posted by porphyry5 View Post
Thank you, I'd just naively assumed multi-core processors used their capabilities automatically. And presumably this technique can be adapted to any number of cores, for any lengthy process that has a series of inputs.
You are welcome. If you are careful, you can use "xargs -P 2" and get a little better performance than my first example.

Code:
$ cat >transcode.sh <<__EOF__
#!/bin/sh
fl="$1"
ffmpeg -i "$fl" -o "${fl%.*}.webm"
exit 0
__EOF__
$ chmod +x transcode.sh
$ find . -type f -name '*.ogg' -print0 | xargs -0 -n 1 -P 2 ./transcode.sh
 
1 members found this post helpful.
Old 10-02-2012, 07:14 PM   #12
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch
Posts: 421

Rep: Reputation: 18
Quote:
Originally Posted by BenCollver2 View Post
You are welcome. If you are careful, you can use "xargs -P 2" and get a little better performance than my first example.

Code:
$ cat >transcode.sh <<__EOF__
#!/bin/sh
fl="$1"
ffmpeg -i "$fl" -o "${fl%.*}.webm"
exit 0
__EOF__
$ chmod +x transcode.sh
$ find . -type f -name '*.ogg' -print0 | xargs -0 -n 1 -P 2 ./transcode.sh
And thank you for these techniques too. So one can indicate to an app that it should read from standard input until a designated line. But is there a particular reason why you feed the output of find through a pipe to xargs, rather than use find's -exec option?
 
Old 10-02-2012, 11:37 PM   #13
BenCollver
Rogue Class
 
Registered: Sep 2006
Location: OR, USA
Distribution: Slackware 14.1
Posts: 160

Rep: Reputation: 50
The "xargs -P 2" option runs 2 commands in parallel. The "find -exec" option doesn't.

-Ben
 
1 members found this post helpful.
Old 10-03-2012, 12:13 AM   #14
Dafydd
Member
 
Registered: Oct 2008
Posts: 311

Original Poster
Rep: Reputation: 23
Thanks to all for the informaton, instructions and patients. I have put the script to running. I will be back after Sunday, Renaissance Festival is starting this weekend and I have things to do to get ready.
 
Old 10-04-2012, 03:39 PM   #15
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch
Posts: 421

Rep: Reputation: 18
Quote:
Originally Posted by BenCollver2 View Post
The "xargs -P 2" option runs 2 commands in parallel. The "find -exec" option doesn't.

-Ben
I might be misreading the 'find' manpage, but I thought that the
Code:
 -exec command {} +
variant would allow that simultaneous processing, because it will pass multiple files to a single evocation of 'command', while
Code:
 -exec command {} \;
does them sequentially, just one file per evocation of 'command'.
 
  


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] Converting video formats to enable dvd burn BobRose152 Linux - Newbie 5 02-07-2010 08:17 AM
Looking for opinions on programs to change video formats/ resize video damgar Linux - Software 1 01-12-2010 04:52 PM
openssl key formats (converting to others) cygnus-x1 Linux - Security 0 03-15-2007 03:56 PM
Converting proprietary audio/video formats to ogg vorbis/theora? brynjarh Linux - Software 2 08-25-2006 11:52 PM
converting between proprietary sound formats q. Calum Linux - Software 2 05-08-2003 08:41 AM


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