Showing posts with label ffmpeg. Show all posts
Showing posts with label ffmpeg. Show all posts

Saturday, March 10, 2012

FFMPEG Convert AVI to JPEG

$ ffmpeg -i input.avi -qscale 1 -qcomp 0 file-%03d.jpg


  • qscale[:stream_specifier] q (output,per-stream)’
    • Use fixed quality scale (VBR). The meaning of q is codec-dependent.
    • qscale constant quality buf variable bitrate. n = 1 for best quality, n = 31 for worst quality
  • qcomp compression
    • video quantizer scale compression (VBR) (default 0.5). Constant of ratecontrol equation. Recommended range for default rc_eq: 0.0-1.0
  • qblur blur
    • video quantizer scale blur (VBR) (range 0.0 - 1.0)
    • Previously tested with qblur option of 0 and 1, and outputs were exactly the same

Friday, March 9, 2012

Converting HD720 to 320x240

$ ffmpeg -i input.avi -vcodec huffyuv -vf "crop:960;720:0:0" -y intermediate.avi
$ ffmpeg -i intermediate.avi -vcodec libx264 -s qvga -y output.m4v

HuffYUV is a lossless codec. From Wikipedia:

Huffyuv (or HuffYUV) is a lossless video codec created by Ben Rudiak-Gould which is meant to replace uncompressed YCbCr as a video capture format.

Despite the "YUV" in the name, it does not compress the YUV color space, but YCbCr.[citation needed] The codec can also compress in the RGB color space.



-vf "..." replaces -croptop, -cropbottom, -padtop, -padbottom etc of older versions of FFMPEG

Monday, February 27, 2012

KISS (Keep It Simple Stupid) FFMPEG

How to remove jitter from the first couple of seconds of Nikon DSLR video, and keep only 60 seconds.

$ lav2yuv +n DSC_0000.AVI > dsc0000.yuv
$ ffmpeg -i dsc0000.yuv -ss 3 -t 60 -y -s vga dsc0000.mp4
$ mediainfo dsc0000.mp4

...asumming you want to convert the MJPEG original to MPEG-4, of course....

By the way, my Nikon outputs 1280x720 HD video (hd720 in FFMPEG-speak). No Full HD (aka hd1080) from this baby.

Wednesday, February 15, 2012

Converting AVI to Dirac

FFMPEG understands Dirac. So here's the command to convert MJPEG/AVI to Dirac. Use MKV extension for the output file to keep the sound.

$ ffmpeg -i t1.avi -vcodec libschroedinger t1.drc

It can be done the long way, by converting to YUV first:

$ lav2yuv +n DSC_0023.AVI > tmp.yuv
$ ffmpeg -i tmp.yuv -vcodec libschroedinger t1.drc

From a 55.2 MB AVI/MJPEG file with audio and 720x480 video, a 729.9 MB YUV420 file is produced.

Encoding to Dirac directly from AVI, results in a 562.4 KB file.
Encoding to MKV from AVI produces a 563.9 KB file.

Compare that to 6.8 MB H.264 file produced form YUV420.
$ ffmpeg -i tmp.yuv -vcodec libx264 t1.mp4
Note: FFMPEG crashes when converting directly from AVI to H.264.

Summary for File 1:

CodecMJPEGYUVDirac (.DRC)
Dirac (.MKV)
H.264
File size (MB)
55.2
729.9
0.562
0.563
6.8
Compression ratio (x)
13.22
1
1297.8
1294.4
107.3

But that's not the whole story. The quality of the Dirac video is so bad...because I used libschroedinger.

Here's the results for File 2, using libdirac switch:

CodecMJPEG
YUV
Dirac (.DRC)H.264(.MP4)
File size (MB)
47.0
1891.1
3.4
8.1
Compression ratio (x)
40.2
1
556.2
233.5

Suddenly, Dirac doesn't look so bad.

Tuesday, February 14, 2012

Converting AVI to YUV to H264

Using FFMPEG to transcode directly from AVI/MJPEG won't work:

$ ffmpeg -i input.avi -vcodec libx264 output.mp4

Still trying to get the commands from the following article to work:

http://www.linuxjournal.com/article/9005

$ mencoder -vf format=i420 -nosound -ovc raw -of rawvideo -ofps 24 -o tmp.yuv input.avi

$ x264 -o output.mp4 --fps 24 --bframes 2 --crf 26 --subme 6 --analyse p8x8,b8x8,i4x4,p4x4 --input-res 720x480 tmp.yuv

Using the lav2yuv command produces a raw YUV file of exactly the same size playable in VLC. The one from mencoder produces garbage.


Another example x264 invocation from http://mewiki.project357.com/wiki/X264_Settings:

$ x264 --output /dev/null --fps 30000/1001 --input-res 720x480 input.yuv

Thursday, December 1, 2011

ffmpeg sample use collection

Caveat: may not work in all cases

Very important, add "-threads 0" to every ffmpeg invocation to use all available cores.

Tuesday, November 29, 2011

ffmpeg install with libx264 (h264) on Fedora

The information for this is VERY very sparse, so here is a summary of what I have found.

Get all the fancy codecs

# yum -y install libmatroska-devel libmkv-devel mkvtoolnix-gui ogmrip themonospot-plugin-mkv themonospot amrnb-tools amrnb-devel amrnb amrwb-tools amrwb-devel amrwb bzip2-devel bzip2-libs bzip2 libdc1394-tools libdc1394-devel libdc1394 dirac-libs dirac-devel dirac faac-devel faac faad2-libs.x86_64 faad2-devel faad2 gsm-tools gsm-devel gsm lame-libs lame-devel lame twolame-libs twolame-devel twolame openjpeg-libs openjpeg-devel openjpeg ImageMagick schroedinger-devel schroedinger speex-tools speex-devel speex libtheora-devel theora-tools byzanz istanbul libtheora libvorbis-devel vorbisgain liboggz-devel libfishsound vorbis-tools x264-libs x264-devel x264 h264enc imlib2-devel libvdpau-devel opencore-amr-devel SDL-devel texi2html xvidcore-devel yasm

Install libx264

Get the libx264 package from http://www.videolan.org/developers/x264.html.
The link to the actual file is ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2

Download it, then..

# cd ~/Downloads/
# tar -xjvf last_x264.tar.bz2
# cd last_x264
# ./configure --enable-shared
# make
# make install
# ldconfig

Install ffmpeg

Just use your browser. From http://ffmpeg.org/download.html find the latest stable release, which is currently http://ffmpeg.org/releases/ffmpeg-0.8.7.tar.bz2. Download it, then...

# cd ~/Downloads
# tar xvfj ffmpeg-0.8.7.tar.bz2
# cd ffmpeg-0.8.7
# ./configure --enable-libx264 --enable-gpl --enable-shared
# make
# make install

ffmpeg is now installed with libx264 (h264).

Courtesy: http://www.saiweb.co.uk/linux/ffmpeg-install-with-libx264-h264

It works! I'm no longer getting Unknown encoder 'libx264' message.

Use ffmpeg

For example, convert a Flash video compressed using VP8 codec to H264. Am wondering which codec produces a smaller file.

# ffmpeg -i aflashfile.flv -vcodec libx264 convertedfile.mp4

Wait, and shazam! A smaller file should be produced. But you may get this message:

error while loading shared libraries: libavdevice.so.52: cannot open shared object file: No such file or directory

This error usually comes when ldconfig does not know where to search for the libraries, so, in order to help it out, on Fedora do the following:

# cd /etc/ld.so.conf.d

Add another file: custom-libs.conf
Inside, put :

/usr/local/lib

save, then do

# ldconfig

et voila again!!!

Thursday, September 8, 2011

Useful FFMPEG commands

Get info from media file

ffmpeg -i inputvideo.avi

Extract audio from any video

ffmpeg -i inputvideo.flv -vn audiofile.mp3
or
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3
Explanation:
  • Source video : source_video.avi
  • Audio bitrate : 192kb/s
  • output format : mp3
  • Generated sound : sound.mp3

Convert FLV to MP4

ffmpeg -i inputvideo.flv -vcodec copy -acodec copy outputvideo.mp4
or
ffmpeg -i inputvideo.flv -ar 22050 outputvideo.mp4
If you're lazy to type you can try the following but output video is big and ugly and takes ages to encode:
ffmpeg -i inputvideo.flv  outputvideo.mp4

Create a screencast

ffmpeg -f x11grab -s 800x600 -i :0.0 /tmp/screencast.mpg

Convert to 3gp format

ffmpeg -i input_video.mp4 -s 176x144 -vcodec h263 -r 25 -b 12200 -ab 12200 -ac 1 -ar 8000 output_video.3gp

Mix audio and video to create final video

ffmpeg -vcodec flv -qscale 9.5 -r 25 -ar 22050 -ab 32k -s 320x240 -i 1.mp3 -i Meta.ogv final.flv

Convert video to PSP MP4 format

ffmpeg -i "OriginalFile.avi" -f psp -r 29.97 -b 768k -ar 24000 -ab 64k -s 320x240 "OutputFile.mp4"

Convert video to iPod/iPhone format

ffmpeg -i inputvideo.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X outputvideo.mp4
Explanation:
  • Source : source_video.avi
  • Audio codec : aac
  • Audio bitrate : 128kb/s
  • Video codec : mpeg4
  • Video bitrate : 1200kb/s
  • Video size : 320px par 180px
  • Generated video : final_video.mp4


Attribution: