LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 02-10-2010, 06:59 PM   #1
felipe1982
LQ Newbie
 
Registered: Dec 2007
Posts: 23

Rep: Reputation: 0
how should one compress a MPG file made with small P&S Digital Camera?


I've made a 15-minute film, but its 99MB in size. What's a good CLI method to compress it down? I hear ffmpeg is good at this, but I don't know exactly what flags/options to include/exclude, which codecs to employ, etc. I don't want to shrink the video dimensions down, they are already as 3xx-by-4xx
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 02-10-2010, 07:19 PM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
Do you have a target size in mind?

Making the dimensions of the video smaller is the easiest way to make the file size smaller, but since you don't want to do that you are going to need to increase the compression on the video. Depending on your target file size, the final video quality may become an issue.
 
Old 02-10-2010, 11:12 PM   #3
felipe1982
LQ Newbie
 
Registered: Dec 2007
Posts: 23

Original Poster
Rep: Reputation: 0
Thank you for your reply. The video quality is not really that much of an issue. It was MEDIUM quality setting on a $150 sony digital cam. It won't win an Oscar

The size is pretty small already, largest dimension 4xx pixels (I don't have the file with me now, it's on my Desktop machine half way around the world).

What I'd like to do, is post it on the web, for others to view (download). I don't really know what file sizes are possible. I would like something less-than 20MB. If it helps a great deal, I guess I could live with shrinking the dimensions down a bit, maybe 10% (15%??).

Any suggestions are welcome.


Thanks
 
Old 02-11-2010, 12:28 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
There are a few basic ways to reduce file size. Most of them rely on reducing quality in some way. A) Reduce the frame size. B) Reduce the framerate. C) Reduce the bitrate. and/or D) Use a more efficient codec. (There may also be some intra-codec tweaks you can use, like setting the gop size or number of b-frames, but I'm not completely clear about how to use those advanced settings myself.)

We'll probably need to know what the original is set to before we can come up with proper settings to use. Also, can you give use some more details about how you will post it? Will it be used in a youtube-like player, or just as a raw file or something?

I don't think we need to see the video itself, just get the metadata for it. Can you run "ffmpeg -i filename", and post the output here?
 
Old 02-11-2010, 11:57 AM   #5
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Yeah, first post the output of 'ffmpeg -i movie.mpg', then I can suggest some possible commands using ffmpeg.
 
Old 02-11-2010, 03:14 PM   #6
felipe1982
LQ Newbie
 
Registered: Dec 2007
Posts: 23

Original Poster
Rep: Reputation: 0
Code:
felipe@suse-amd:~/Pictures/2010-01-13/TEST> ls -l *mpg
-rw-r--r-- 1 felipe users 103933131 2010-01-13 02:09 mov01516.mpg
Code:
felipe@suse-amd:~/Pictures/2010-01-13/TEST> ffmpeg -i mov01516.mpg
FFmpeg version UNKNOWN, Copyright (c) 2000-2010 Fabrice Bellard, et al.
  built on Feb  6 2010 19:14:04 with gcc 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036]
  configuration: --shlibdir=/usr/lib --prefix=/usr --mandir=/usr/share/man --libdir=/usr/lib --enable-shared --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libfaad --enable-libfaac --enable-nonfree --enable-libxvid --enable-postproc --enable-gpl --enable-x11grab --enable-libschroedinger --enable-libdirac --enable-libgsm --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libdc1394 --enable-pthreads
  libavutil     50. 8. 0 / 50. 8. 0
  libavcodec    52.52. 0 / 52.52. 0
  libavformat   52.50. 0 / 52.50. 0
  libavdevice   52. 2. 0 / 52. 2. 0
  libswscale     0.10. 0 /  0.10. 0
  libpostproc   51. 2. 0 / 51. 2. 0
[mpeg @ 0x808bb40]invalid dts/pts combination
    Last message repeated 82 times
[mpeg @ 0x808bb40]max_analyze_duration reached
Input #0, mpeg, from 'mov01516.mpg':
  Duration: 00:04:45.40, start: 0.110000, bitrate: 2913 kb/s
    Stream #0.0[0x1c0]: Audio: mp2, 32000 Hz, 1 channels, s16, 64 kb/s
    Stream #0.1[0x1e0]: Video: mpeg1video, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc
At least one output file must be specified
Code:
felipe@suse-amd:~/Pictures/2010-01-13/TEST> ffmpeg -version
FFmpeg version UNKNOWN, Copyright (c) 2000-2010 Fabrice Bellard, et al.
  built on Feb  6 2010 19:14:04 with gcc 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036]
  configuration: --shlibdir=/usr/lib --prefix=/usr --mandir=/usr/share/man --libdir=/usr/lib --enable-shared --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libfaad --enable-libfaac --enable-nonfree --enable-libxvid --enable-postproc --enable-gpl --enable-x11grab --enable-libschroedinger --enable-libdirac --enable-libgsm --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libdc1394 --enable-pthreads
  libavutil     50. 8. 0 / 50. 8. 0
  libavcodec    52.52. 0 / 52.52. 0
  libavformat   52.50. 0 / 52.50. 0
  libavdevice   52. 2. 0 / 52. 2. 0
  libswscale     0.10. 0 /  0.10. 0
  libpostproc   51. 2. 0 / 51. 2. 0
FFmpeg UNKNOWN
libavutil     50. 8. 0 / 50. 8. 0
libavcodec    52.52. 0 / 52.52. 0
libavformat   52.50. 0 / 52.50. 0
libavdevice   52. 2. 0 / 52. 2. 0
libswscale     0.10. 0 /  0.10. 0
libpostproc   51. 2. 0 / 51. 2. 0
felipe@suse-amd:~/Pictures/2010-01-13/TEST>

I think I may have been wrong about the video's original dimensions, it appears that it is 640 x 480. Shrinking it could be possible. Yes --- I was thinking of having the video be made ideal for sharing on a youtube-like site.

thank you
 
Old 02-12-2010, 03:33 AM   #7
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Well, I think youtube can use mp4 as well as flv, and since mp4 is usually higher quality, I'd try that. So try:

Code:
ffmpeg -i input.mpg -vcodec libx264 -vpre hq -crf 23 -s 640x480 -r 25 -aspect 4:3 -acodec libfaac -ab 96k -ar 32000 -async 32000 -ac 1 output.mp4
If you wanted flv you should try:
http://luar.com.hk/blog/?p=670
to make a proper flv.
 
2 members found this post helpful.
Old 02-14-2010, 07:40 AM   #8
felipe1982
LQ Newbie
 
Registered: Dec 2007
Posts: 23

Original Poster
Rep: Reputation: 0
Besides `man ffmpeg' and doom9's forums, and linuxquestions.org, are there any recommended places to learn about video (and audio) encoding processes, optimisations, types of codecs and containers, etc, etc?

There are things that I know so very little about, and wish to learn more - in as short a span of time as possible. I find the discussion of video/audio codecs, bitrates, frame-rates, I-frames, B-frames, sample rates, et al., to be so alien/foreign to me, and I'd really like to learn more.

Thanks for the above ffmpeg line. I shrunk the video down from 100M to 46M, but I haven't downloaded it yet (only getting 2.0KBytes/s download ATM) so I can't speak for the quality

Last edited by felipe1982; 02-14-2010 at 07:42 AM.
 
Old 02-14-2010, 08:11 AM   #9
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
You can search wikipedia for more on what those things mean. Some are not so complicated, but other options are more obscure and you may never understand exactly what they are talking about.
 
1 members found this post helpful.
Old 02-14-2010, 08:30 AM   #10
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Wikipedia is a good resource to learn about container formats and protocols. An article will have references in the bottom. For the esoteric options, usually someone active in this area has a blog where they post articles, with sample configurations. There also is an ffmpeg users mailing list where you can ask particular questions.

Download a sample from youtube or use their recommendations.
Use the mediainfo program to analyze that video and adopt them for your output video.

Often a variation of the input video will point out an addition option or setting you need. For example the line above doesn't provide a -pix_fmt option for the colorization model. It may be carried over from the input (yuv420p) or be implied by the output codec. When you try to transcode a different input you my learn you need to add another option. The options after the -i <input video> pertain to the output video. Once these options are complete enough, you usually don't need to change them for the same target. Ffmpeg handles changes in the input video.

Last edited by jschiwal; 02-14-2010 at 08:34 AM.
 
1 members found this post helpful.
Old 02-14-2010, 04:50 PM   #11
felipe1982
LQ Newbie
 
Registered: Dec 2007
Posts: 23

Original Poster
Rep: Reputation: 0
By using MPEG-4 video type, as I have done above, what is the 'container' format? Would AVI or MVK or any other be a suitable container type? How does one know that this is in fact mp4 (aside from the extension, of course)? Why is it better to select mpeg-4 versus mpeg-2? Does one produced smaller file sizes? I'm trying to get a better grasp of these things. Thanks for all the inputs. The wiki articles are helpful, but leave me with a thousand more questions than I began.
 
Old 02-15-2010, 03:40 AM   #12
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
AIUI, mpeg4 generally uses it's own container format, specifically designed for it. It's possible to put mpeg4 in an avi container, but with some limitations. I've heard that avi doesn't support mpeg4's b-frames correctly, for example.

mpeg2 is the format used in the dvd standard. It has two container formats of it's own, mpeg-ps and mpeg-ts. ps is designed to support the same parameters (bitrate, framerate, framesize) as dvd video (which uses yet another container, vob) and is often used as a stepping stone in dvd authoring, while ts is more flexible and designed for general usage.

mpeg4, being a newer codec (or set of codecs) is, in general, more efficient, providing higher quality at lower bitrates than mpeg2, but at the cost of requiring more processing power to encode and decode. There are several different codec levels defined, for various purposes from internet streaming to blu-ray discs.

Note also that mpeg4 is not yet universally supported, and is also heavily patent-encumbered, meaning that all Free versions of the codecs fall inside a legal grey area.

I'm not too familiar with the matroska container, but I believe it's often used for dv digital video streams. Then there's the ogg container, which goes well with the theora codec.

The only way to tell for sure what's inside a container is to run it through a program that can read the streams inside, like ffmpeg or mplayer or something. Don't forget that they can also often hold multiple audio and subtitle streams as well.

Again, Wikipedia and Google will tell you much more about each different format.
 
1 members found this post helpful.
Old 02-15-2010, 04:44 AM   #13
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
mkv is a very good container format and supports many codecs. On the site there is a set of tools that can easily extract and combine streams, which makes things really easy to work with. It also supports many advanced features.

http://en.wikipedia.org/wiki/Compari...tainer_formats
http://en.wikipedia.org/wiki/Comparison_of_video_codecs
http://en.wikipedia.org/wiki/Comparison_of_audio_codecs
 
Old 02-15-2010, 07:03 AM   #14
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Oh, and one more thing, I don't think you will do well to choose patent unencumbered codecs just because it's a great thing to be free of patents. In general, I've found them to be rather crappy. One exception is vorbis, but in terms of size, it's still a bit large.

Here are my recommendations:

video codecs:
Xvid/Divx using libxvid
x264/H264 using libx264

audio codecs:
AAC using libfaac/libfaad
mp3 using lame
 
1 members found this post helpful.
  


Reply

Tags
compression, ffmpeg, shrink, video



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] no thumbnail for flv file though present for mpg,avi & mp4 files sumeet inani Ubuntu 7 05-07-2010 04:53 AM
Digital Camera Compatibility & Such TSHF-Megsy Linux - Software 4 11-03-2005 10:17 PM
Mplayer won't play Digital Camera's mpg-files Trygleren Linux - Software 0 12-15-2004 08:16 AM
need to compress an .mpg to .avi drawhla Linux - Software 1 11-03-2004 07:39 AM
Digital camera NSKL Linux - Hardware 2 09-13-2002 01:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 09:29 PM.

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
Open Source Consulting | Domain Registration