Link to home
Start Free TrialLog in
Avatar of www_puertoricoautoforo_com
www_puertoricoautoforo_comFlag for United States of America

asked on

Ubuntu > ffmpeg .sh script to mass convert directory of .ogv files to .mpg or .mp4

I have a directory full of OGV videos that youtube hates.. Unfortunately 'cheese' does not allow me to save in any other format besides OGV.  But youtube doesn't like it and my videos look like an 8-bit Atari acid tripping or something..

so I have a bunch of OGV files here:
/home/username/Video/webcam/

How can I convert every OGV in the webcam folder to the same resolution .mpg files..
Also for my friends with slow upload speeds, how could I convert them to .mp4 files..

I figure .mpg is less lossy than .mp4

Please attach the code of the .sh script for each.  I would like to just execute the script by placing it in the /webcam directory and clicking it after giving it executable permission.
Avatar of TobiasHolm
TobiasHolm
Flag of Sweden image

Hi!

Try this for the convert:
ffmpeg -i input.ogv output.mpg

Ref: http://ubuntuforums.org/showthread.php?t=665836

Or try this for FLV conversion (doesn't YouTube use FLV?):

sudo apt-get update
sudo apt-get install ffmpeg libavcodec-extra-52
ffmpeg -i input.ogv -acodec libmp3lame -aq 4 -vcodec libx264 -vpre hq -crf 26 -wpredp 0 -threads 0 output.flv

Ref: http://ubuntuforums.org/showthread.php?t=1500142

To execute a script by placing it in the /webcam directory you could use fsniper or cron:

Ref: http://www.linux.com/archive/feature/150200

Regards, Tobias
Avatar of www_puertoricoautoforo_com

ASKER

I need that in a .sh script that converts everything in the directoy.  I tried executing that command, and I get this error..

edward@edward-laptop:~/Videos$ ls
kdenlive  Webcam
edward@edward-laptop:~/Videos$ cd Webcam
edward@edward-laptop:~/Videos/Webcam$ ls
2010-06-30-211303.ogv  2010-06-30-212715.ogv  convert.sh
edward@edward-laptop:~/Videos/Webcam$ clear
edward@edward-laptop:~/Videos/Webcam$ ls
2010-06-30-211303.ogv  2010-06-30-212715.ogv  convert.sh
edward@edward-laptop:~/Videos/Webcam$ ls -l
total 707476
-rw-r--r-- 1 edward edward 717641230 2010-06-30 21:24 2010-06-30-211303.ogv
-rw-r--r-- 1 edward edward   6801803 2010-06-30 21:27 2010-06-30-212715.ogv
-rwxr-xr-x 1 edward edward       157 2010-06-30 21:36 convert.sh
edward@edward-laptop:~/Videos/Webcam$ ffmpeg -i 2010-06-30-211303.ogv output.mpg 
FFmpeg version SVN-r0.5.1-4:0.5.1-1ubuntu1, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --extra-version=4:0.5.1-1ubuntu1 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 1 / 52.20. 1
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  libavfilter    0. 4. 0 /  0. 4. 0
  libswscale     0. 7. 1 /  0. 7. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Mar  4 2010 12:41:55, gcc: 4.4.3
Input #0, ogg, from '2010-06-30-211303.ogv':
  Duration: 00:11:05.46, start: 0.000000, bitrate: 8627 kb/s
    Stream #0.0: Video: theora, 640x480, 24 tbr, 24 tbn, 24 tbc
    Stream #0.1: Audio: vorbis, 44100 Hz, mono, s16, 80 kb/s
swScaler: Unknown format is not supported as input pixel format
Cannot get resampling context
edward@edward-laptop:~/Videos/Webcam$ 

Open in new window

Tried the other one, and I get this error
edward@edward-laptop:~/Videos/Webcam$ mv *303.ogv input.ogv
edward@edward-laptop:~/Videos/Webcam$ ffmpeg -i input.ogv -acodec libmp3lame -aq 4 -vcodec libx264 -vpre hq -crf 26 -wpredp 0 -threads 0 output.flv
FFmpeg version SVN-r0.5.1-4:0.5.1-1ubuntu1, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --extra-version=4:0.5.1-1ubuntu1 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 1 / 52.20. 1
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  libavfilter    0. 4. 0 /  0. 4. 0
  libswscale     0. 7. 1 /  0. 7. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Mar  4 2010 12:41:55, gcc: 4.4.3
Input #0, ogg, from 'input.ogv':
  Duration: 00:11:05.46, start: 0.000000, bitrate: 8627 kb/s
    Stream #0.0: Video: theora, 640x480, 24 tbr, 24 tbn, 24 tbc
    Stream #0.1: Audio: vorbis, 44100 Hz, mono, s16, 80 kb/s
swScaler: Unknown format is not supported as input pixel format
Cannot get resampling context
edward@edward-laptop:~/Videos/Webcam$ ^C

Open in new window

Hi!

Maybe the ffmpeg cannot process vorbis video...

You can try Mencoder.

sudo apt-get install mencoder
mencoder input.ogv -ofps 23.976 -ovc lavc -oac mp3lame -lameopts abr:br=56 -o output.avi

Ref: https://help.ubuntu.com/community/MEncoder
Ref: http://en.gentoo-wiki.com/wiki/HOWTO_Mencoder_Introduction_Guide
Ref: http://ubuntuforums.org/archive/index.php/t-1174968.html

Regards, Tobias
But how would I make a .sh script to process all the ogv files in a directory

Yes mencoder does work for 1 file.
ASKER CERTIFIED SOLUTION
Avatar of TobiasHolm
TobiasHolm
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I changed "Video" to "Videos" and changed some of the sound settings, now it works like a charm! Thanks.


#!/bin/bash

directory=~/Videos/

while read file; do
        echo "Processing: $file"
        mencoder "$file" -ovc x264 -oac pcm -o "$file.avi"
done < <(find "$directory" -iname '*.ogv' -print)

Open in new window