LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 08-03-2008, 11:52 PM   #1
Romanus81
Member
 
Registered: Feb 2008
Posts: 201

Rep: Reputation: 31
ffmpeg, dramatic decrease in size from camera videos.


Am I using ffmpeg correctly? I noticed an insane decrease in file size when passing videos through ffmpeg.
I passed a video through with the command
Code:
ffmpeg -i mvi_0130.avi -r 30 mvi_0131.avi
'-r' changes the frame rate, and the movie was originally 30 fps anyway. The result, however, gave me a 4MB file from a 75.7MB file. Of course, the video quality is a lot worse, the music is the same, from what I can tell. The only differences from the properties window are as follows:

Video:
Codec: Motion jpeg > ffmpeg mpeg4
Audio:
Codec: Uncompressed 16-bit PCM audio > MPEG 1 Audio, Layer 2
Bitrate: undefined > 64 kbps

So is this natural behavior for ffmpeg? Is there a way I can control to what degree ffmpeg degrades the quality of the movie? Is there a way I can just slightly reduce the frame rate, but keep each individual frame the same quality as it was recorded? Is it just because I am using an .avi file? (it is going from .avi to .avi)

Here is the output:
Code:
owner@darkstar:~/Desktop$ ffmpeg -i mvi_0130.avi -r 30 mvi_0131.avi
FFmpeg version SVN-r10652, Copyright (c) 2000-2007 Fabrice Bellard, et al.
  configuration: --prefix=/usr --mandir=/usr/man --disable-debug 
--enable-shared --disable-static --enable-pthreads --enable-libogg
 --enable-libtheora --enable-libvorbis --enable-gpl --enable-pp 
--enable-swscaler --enable-x11grab --enable-libmp3lame --enable-libfaac
 --enable-libfaad --enable-libxvid --enable-liba52 --enable-libx264
  libavutil version: 49.5.0
  libavcodec version: 51.44.0
  libavformat version: 51.14.0
  built on May 30 2008 16:34:43, gcc: 4.2.3
Input #0, avi, from 'mvi_0130.avi':
  Duration: 00:00:51.5, start: 0.000000, bitrate: 12308 kb/s
  Stream #0.0: Video: mjpeg, yuvj422p, 640x480, 30.00 fps(r)
  Stream #0.1: Audio: pcm_s16le, 44100 Hz, mono, 705 kb/s
Output #0, avi, to 'mvi_0131.avi':
  Stream #0.0: Video: mpeg4, yuv420p, 640x480, q=2-31, 200 kb/s, 30.00 fps(c)
  Stream #0.1: Audio: mp2, 44100 Hz, mono, 64 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 1547 fps= 83 q=31.0 Lsize=    4094kB time=51.6 bitrate= 650.5kbits/s    
video:3597kB audio:403kB global headers:0kB muxing overhead 2.372027%
 
Old 08-04-2008, 01:00 AM   #2
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
Quote:
Originally Posted by Romanus81 View Post
So is this natural behavior for ffmpeg?
Checked it on my own mjpeg videos, looks like by default it encodes video to new format.

Quote:
Originally Posted by Romanus81 View Post
Is there a way I can control to what degree ffmpeg degrades the quality of the movie?
according to "man ffmpeg", you can set video bitrate, video format and filesize.

Quote:
Originally Posted by Romanus81 View Post
Is there a way I can just slightly reduce the frame rate, but keep each individual frame the same quality as it was recorded?
I don't know mjpeg details, but I don't think that's possible unless you want to stretch video - which means if original video was 30 fps and you make it 20 fps, then it'll be 1.5 times longer.

I'd recommend you to use mencoder. If you wanted to stretch video (just change fps without losing much data), say, reduce fps from 30 to 3 , then you could try to do it like this:
Code:
mencoder -oac copy -ovc copy -fps 3 input_video.avi -o output_video.avi
However if you want to keep video length same and reduce fps, then, I'm afraid, you'll have to recode video, so you might lose some quality.
 
Old 08-04-2008, 01:36 AM   #3
Romanus81
Member
 
Registered: Feb 2008
Posts: 201

Original Poster
Rep: Reputation: 31
when I say reduce the frame rate I'm not talking about stretching the video, a reduction from 30 to 15 would mean that it removes half the frames. And here I didn't even do anything, it just automatically reduced the quality without my input. Is there something I can do to stop this? So that if I did tell it to reduce the framerate to 15, that it would take half the frames out and that's all?
I think I just need an explaination of what exactly ffmpeg does. I don't think I quite understand.
 
Old 08-04-2008, 02:33 AM   #4
storkus
Member
 
Registered: Jun 2008
Posts: 314

Rep: Reputation: 47
Disclaimer: Bear in mind what I'm about to say is without looking at the docs, man pages, etc.

Looking at the transcoding output I'm seeing a rather extreme reduction in both rates, but especially the video: if I'm reading this right, you've taken a 12 megabit/second video stream and knocked it down to just 200 kilobits/second, which is pretty extreme--that explains your video quality loss. It says it's using MPEG4, which is a container--I'm assuming it's actually using x.264 as a codec, but I can't tell from the output. Also, any noise in the original video (analog to digital conversion in particular) will make compression worse.

Depending on the actual codec in use, there probably exist options to make it not compress as hard so your video looks better; the caveat being your resulting file will be larger. I also know there exists a codec, but I can't remember the name, that does for video what FLAC does for audio: lossless compression. (All other codecs will reduce video quality by removing information that can't be recovered, but that's the trade-off for much higher compression ratios.)

There exists a program made for just what you're doing called "transcode", which is also the name for what you're doing (transcoding from one digital format to another). I believe it can call ffmpeg along with a host of other codec packages. You should really consider it rather than trying to feed it through ffmpeg raw.

Mike

Disclaimer #2: Despite how this may sound, I'm not an expert. I just learned all this while I was in my "downloading anime torrents" phase, which the MPAA/RIAA/FBI/DMCA snoops reading this message can know I don't do anymore.
 
Old 08-04-2008, 03:28 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951
200kbs is the default bitrate ffmpeg falls back to if it doesn't know what value to use. In my experience its default behavior has been inconsistent. Sometimes it will use the settings from the input video and sometimes it won't. I haven't been able to figure out in which situations it does it, so I make sure to always manually set the bitrate now. Same goes with audio, as 64kbs is a rather low default there too.

I'm not sure how framerate conversion works exactly, but I believe it usually involves taking only the required frames from the input video. This is easy if the new framerate is an even multiple of the input (e.g. just take every other frame), but involves some interpolation if it's an odd number conversion, such as converting NTSC to PAL framerates. Of course, changing the bitrate, video size, and especially codec definitely means having to reencode the video.

I've always found ffmpeg to be rather tricky when it comes to framerate conversions. I generally use transcode or the gui program avidemux when I have to do something like that, since they both have specially-designed filters for conversion.

So when you use ffmpeg, it's usually best to set your -b and -ab manually. You can also use the 'copy' codec option to keep the original audio stream, say. But use another program if you want to change framerates.
 
Old 08-07-2008, 01:50 PM   #6
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
If you have five minutes, then this should shed a bit of light on the subject.
http://www.linuxjournal.com/video/li...g-magic-ffmpeg
At least it did for me.
 
Old 08-07-2008, 03:56 PM   #7
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
Quote:
Originally Posted by Romanus81 View Post
when I say reduce the frame rate I'm not talking about stretching the video, a reduction from 30 to 15 would mean that it removes half the frames.
Are you absolutely sure that MJPEG stores full frames and allows to remove some of them without recompression? It's not uncompressed video! I don't know details about mjpeg, but (as far as I know) other compressed formats don't store all frames, they store differences between frames(motion vectors, color changes, etc). In this case reducing framerate would require recompression of entire video. If MJPEG allows just to throw out every second frame, then you should look for some mjpeg-specific tool.

Last edited by ErV; 08-07-2008 at 03:59 PM.
 
Old 08-07-2008, 05:37 PM   #8
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
MPEG doesn't store frames, it stores changes between frames, which is it's main source of compression and why it's so bad to edit
 
Old 08-07-2008, 07:49 PM   #9
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951Reputation: 1951
mjpeg is not mpeg. Each individual frame is stored as a compressed jpeg image.
 
  


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
How to decrease size of a libc-2.5.1.so? Nad0x00 Linux From Scratch 3 11-14-2007 05:08 AM
How to decrease text editor size? marcoguillen Linux - Software 2 03-24-2007 02:44 AM
Updated xine-lib and ffmpeg, now I can't watch any videos dubya Fedora 11 01-11-2007 10:48 AM
How do I decrease K-Menu size? Slamtilt Linux - Software 4 01-12-2006 02:18 PM
photo's size decrease with 'convert' ? thelonius Linux - Software 1 10-04-2005 09:28 PM


All times are GMT -5. The time now is 03:41 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration