FORUMS: list search recent posts

MPEG2 to MPEG4 options

COW Forums : FFmpeg

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Nik Jell
MPEG2 to MPEG4 options
on Mar 27, 2012 at 2:49:06 pm

Hi there,

I have some MPEG2 video files that come directly from a video camera, I would like to convert them to MPEG4. I'm not sure what options to use and reading some of the documentation online I'm getting a little confused.

Currently I've using:

ffmpeg -i input.MPG -sameq -y output.mp4

The above process creates and mp4 file that's viewable in Quicktime and on most Media players but the file size is quite a lot larger than the original MPEG2 and takes quite some time to create.

I have also tried to use some libx264 presets but I seem to either get very small or very large file sizes.

Any guidance that you could offer would be greatly appreciated.

Many Thank,
Nik


Return to posts index

Reuben Martin
Re: MPEG2 to MPEG4 options
on Mar 28, 2012 at 5:15:57 am

Quicktime compatible, high quality, decent compression ratio, somewhat slow encoding time:


ffmpeg -i input.MPG -deinterlace -pix_fmt yuv420p -vcodec libx264 -preset slow -vprofile high -trellis 2 -crf 20 -acodec libfaac -ac 2 -ab 192k -f mp4 -y output.mp4


Requires that the version of ffmpeg being used is built with libfaac support. Also requires a fairly recent version of ffmpeg.


Return to posts index

stephen dixon
Re: MPEG2 to MPEG4 options
on Mar 28, 2012 at 11:06:54 am

If your footage isn't interlaced you could omit the -deinterlace option in the above command.

Also, if you want to tweak the settings until you get a movie that is acceptable size/quality, then change the -crf option (stands for constant rate factor which is basically the "quality" setting). 20 is a pretty good place to start, lower is better/bigger file, higher is worse quality/smaller file.

Stephen Dixon
Editor, Animator, Motionographer
Museum Victoria


Return to posts index


Nik Jell
Re: MPEG2 to MPEG4 options
on Mar 28, 2012 at 11:47:21 am

Hi Reuben/Stephen

Thanks for your responses.

My version of ffmpeg was installed using Macports and I don't think in has libfaac support. It also seems to be struggling with -vprofile. When I run the suggested options I get this error:

ffmpeg version 0.7.8, Copyright (c) 2000-2011 the FFmpeg developers
built on Nov 24 2011 14:31:00 with gcc 4.2.1 (Apple Inc. build 5666) (dot 3)
configuration: --prefix=/opt/local --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libdirac --enable-libschroedinger --enable-libopenjpeg --enable-libxvid --enable-libx264 --enable-libvpx --enable-libspeex --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/gcc-4.2 --arch=x86_64 --enable-yasm
libavutil 50. 43. 0 / 50. 43. 0
libavcodec 52.123. 0 / 52.123. 0
libavformat 52.111. 0 / 52.111. 0
libavdevice 52. 5. 0 / 52. 5. 0
libavfilter 1. 80. 0 / 1. 80. 0
libswscale 0. 14. 1 / 0. 14. 1
libpostproc 51. 2. 0 / 51. 2. 0
Input #0, mpeg, from '/Users/nikj/Desktop/untitled folder 2/converted/final.MPG':
Duration: 00:04:18.52, start: 0.240000, bitrate: 6147 kb/s
Stream #0.0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x576 [PAR 16:15 DAR 4:3], 9500 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0.1[0x80]: Audio: ac3, 48000 Hz, stereo, s16, 448 kb/s
[NULL @ 0x102009e00] [Eval @ 0x7fff5fbfe4b0] Undefined constant or missing '(' in 'high'
[NULL @ 0x102009e00] Unable to parse option value "high"
Invalid value 'high' for option 'vprofile'

I then removed the -vprofile high options and ran the command again and got this error:

ffmpeg version 0.7.8, Copyright (c) 2000-2011 the FFmpeg developers
built on Nov 24 2011 14:31:00 with gcc 4.2.1 (Apple Inc. build 5666) (dot 3)
configuration: --prefix=/opt/local --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libdirac --enable-libschroedinger --enable-libopenjpeg --enable-libxvid --enable-libx264 --enable-libvpx --enable-libspeex --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/gcc-4.2 --arch=x86_64 --enable-yasm
libavutil 50. 43. 0 / 50. 43. 0
libavcodec 52.123. 0 / 52.123. 0
libavformat 52.111. 0 / 52.111. 0
libavdevice 52. 5. 0 / 52. 5. 0
libavfilter 1. 80. 0 / 1. 80. 0
libswscale 0. 14. 1 / 0. 14. 1
libpostproc 51. 2. 0 / 51. 2. 0
Input #0, mpeg, from '/Users/nikj/Desktop/untitled folder 2/converted/final.MPG':
Duration: 00:04:18.52, start: 0.240000, bitrate: 6147 kb/s
Stream #0.0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x576 [PAR 16:15 DAR 4:3], 9500 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0.1[0x80]: Audio: ac3, 48000 Hz, stereo, s16, 448 kb/s
Unknown encoder 'libfaac'

I should explain that the files that come from the camera I first run this command on:

ffmpeg -i input.MPG -target pal-dvd -vcodec copy -y output.MPG

This is so that I have the option to burn them to a dvd.

I then concatenate the files using this mencoder commmand:

mencoder -audio-preload 0.0 -oac copy -ovc copy -of mpeg -mpegopts format=dvd:tsaf -idx -mc 0 input1.MPG input2.MPG input3.MPG input4.MPG -o final.MPG

Its this final.MPG that I want to convert into an MP4 preserving as much quality as possible whilst producing it as quickly as possible.

Thanks again,
Nik


Return to posts index

Reuben Martin
Re: MPEG2 to MPEG4 options
on Mar 29, 2012 at 1:34:08 am

The options change between versions. The options I gave need 0.9 or better.

You can download binary builds of the latest versions here: http://ffmpegmac.net/

However, I'm not sure if they are built with libfaac support. If not you may have to build your own, or use the visualon aac encoder if it supports it. (change "-acodec libfaac" to "-acodec libvo_aacenc" in that case) Also you can encode the audio with mp3 rather than aac, which is a perfectly valid format to mux into an mp4. (For mp3 change "-acodec libfaac" to "-acodec libmp3lame")

I mainly work from linux, so I have no idea what options are enabled in the mac builds. To get a listing of what codecs are supported with the build of ffmpeg you are using, run "ffmpeg -codecs"


Return to posts index

Nik Jell
Re: MPEG2 to MPEG4 options
on Mar 29, 2012 at 12:46:53 pm

Hi Reuben,

Thanks for your reply.

Here are some results:

input.MPG = 198.6 MB Duration 4min 18seconds

Output.mp4 produced using options: " -sameq -y " = 341.7 MB, conversion time = 59 seconds

Output.mp4 produced using options: "" -vcodec libx264 -preset ultrafast -trellis 2 -crf 21 -acodec libmp3lame -ac 2 -ab 192k -f mp4 -y " = 193.8 MB, conversion time = 1min 12 seconds

As you can see the -sameq command produced a large file size but produced the file quicker than the other options!

Without wishing to sound like I want 'The moon on a stick' I'm just trying to find the best combination of options to produce the best quality of file with the smallest file size as quickly as possible!

The file produced using the libmp3lame audio option does not appear to have any audio when played back in Quicktime.

If you can offer any further advice I would appreciate it.

Thanks,
Nik


Return to posts index


Reuben Martin
Re: MPEG2 to MPEG4 options
on Mar 29, 2012 at 3:18:10 pm

Well, that's a balance you have to find that satisfies you. Time to encode and file size are inversely proportional to quality.

If you want something faster, reducing trellis to 1 or 0 will speed things up quite a bit, but quality will not be as good.

It's all a matter of determining what is most important to you (time, quality or file size) and going from there.

Not sure why Quicktime is not playing back audio for you. Mp3 is supported by the spec, but Quicktime does not always support every option available in a spec. You could try VLC to verify that the audio stream is properly encoded, but if the resulting file must be compatible with Quicktime, you may have to look more deeply into what Quicktime supports. For instance I never use AAC+ when the content has to be Quicktime compatible, because Quicktime just doesn't know what to do with it. However, flash players in browsers handle it just fine.


Return to posts index

Nik Jell
Re: MPEG2 to MPEG4 options
on Mar 29, 2012 at 3:42:53 pm

Thanks yet again for your continued support Reuben.

VLC does indeed preserve the audio content, in fact I've never found much that VLC doesn't play, it's the Don of all movie playback apps.

I will continue to experiment with settings and post back here if I find a happy medium.

Thanks,
Nik


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]