LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Converting video formats (http://www.linuxquestions.org/questions/programming-9/converting-video-formats-4175429488/)

Dafydd 09-28-2012 03:56 PM

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

Dman58 09-28-2012 04:31 PM

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?

dugan 09-28-2012 05:01 PM

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.

porphyry5 09-28-2012 05:08 PM

Quote:

Originally Posted by Dafydd (Post 4791907)
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?

TobiSGD 09-28-2012 05:13 PM

Quote:

Originally Posted by porphyry5 (Post 4791961)
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

porphyry5 09-29-2012 10:32 AM

Quote:

Originally Posted by TobiSGD (Post 4791967)
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.

Dafydd 09-30-2012 06:14 PM

Quote:

Originally Posted by dugan (Post 4791957)
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

dugan 09-30-2012 07:26 PM

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>


BenCollver 09-30-2012 09:56 PM

Quote:

Originally Posted by porphyry5 (Post 4791961)
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

porphyry5 10-01-2012 06:40 AM

Quote:

Originally Posted by BenCollver2 (Post 4793602)
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.

BenCollver 10-01-2012 07:33 AM

Quote:

Originally Posted by porphyry5 (Post 4793887)
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


porphyry5 10-02-2012 07:14 PM

Quote:

Originally Posted by BenCollver2 (Post 4793929)
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?

BenCollver 10-02-2012 11:37 PM

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

-Ben

Dafydd 10-03-2012 12:13 AM

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.

porphyry5 10-04-2012 03:39 PM

Quote:

Originally Posted by BenCollver2 (Post 4795621)
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'.


All times are GMT -5. The time now is 05:55 AM.