LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-11-2014, 10:24 AM   #1
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,687

Rep: Reputation: 55
convert mpg to mp4


Hi all,

Please advise how to convert .mpg video file to .mp4.

TIA

Regards
satimis
 
Old 08-11-2014, 10:31 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867
Use conversion tools like ffmpeg (CLI), HandBrake (CLI and GUI) or even VLC:
Code:
ffmpeg -i video.mpg video.mp4
Of course there are countless encoding parameters for audio and video to play with, but your favorite web search engine should have thousands of tutorials for that.
 
1 members found this post helpful.
Old 08-11-2014, 10:31 AM   #3
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655
Use ffmpeg:

Code:
ffmpeg -i input.mpg output.mp4
Or HandBrake:

Code:
HandBrakeCLI -Z Universal -i input.mpg -o output.mp4

Last edited by szboardstretcher; 08-11-2014 at 10:34 AM.
 
Old 08-11-2014, 10:50 AM   #4
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,687

Original Poster
Rep: Reputation: 55
Hi all,

Thanks for your advice.

$ ffmpeg -i MOV_Ayala_Mall_01.MPG MOV_Ayala_Mall_01.mp4
Code:
ffmpeg version 0.8.13-4:0.8.13-0ubuntu0.12.04.1, Copyright (c) 2000-2014 the Libav developers
  built on Jul 15 2014 12:56:47 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Input #0, mpeg, from 'MOV_Ayala_Mall_01.MPG':
  Duration: 00:01:23.66, start: 0.070000, bitrate: 10486 kb/s
    Stream #0.0[0x1c0]: Audio: mp2, 32000 Hz, mono, s16, 64 kb/s
    Stream #0.1[0x1e0]: Video: mpeg1video, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 104857 kb/s, 30 fps, 30 tbr, 90k tbn, 30 tbc
[buffer @ 0x1afa0a0] w:640 h:480 pixfmt:yuv420p
[aac @ 0x1af9860] Too many bits per frame requested
Output #0, mp4, to 'MOV_Ayala_Mall_01.mp4':
    Stream #0.0: Video: mpeg4, yuv420p, 640x480 [PAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 30 tbc
    Stream #0.1: Audio: aac, 32000 Hz, mono, s16, 200 kb/s
Stream mapping:
  Stream #0.1 -> #0.0
  Stream #0.0 -> #0.1
Error while opening encoder for output stream #0.1 - maybe incorrect parameters such as bit_rate, rate, width or height
Failed.

$ which HandBrakeCLI
No output. It may not be available


Regards
satimis
 
Old 08-11-2014, 11:48 AM   #5
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
I recommend 2 pass encoding:
Code:
ffmpeg -i input.mpg -vcodec libxvid -q:v 5 -s 640x480 -aspect 640:480 -r 30 -g 300 -bf 2 -acodec libmp3lame -ab 160k -ar 32000 -async 32000 -ac 2
-pass 1 -an -f rawvideo -y /dev/null
ffmpeg -i input.mpg -vcodec libxvid -q:v 5 -s 640x480 -aspect 640:480 -r 30 -g 300 -bf 2 -acodec libmp3lame -ab 160k -ar 32000 -async 32000 -ac 2
-pass 2 output.mp4
You can replace 'ffmpeg' with 'avconv' because Ubuntu tends to use that.
 
Old 08-11-2014, 12:34 PM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 23,120

Rep: Reputation: 6451Reputation: 6451Reputation: 6451Reputation: 6451Reputation: 6451Reputation: 6451Reputation: 6451Reputation: 6451Reputation: 6451Reputation: 6451Reputation: 6451
Quote:
Originally Posted by satimis View Post
Hi all,
Thanks for your advice.

*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
....did you read/understand this part of the output? Did you try avconv, as suggested?
Quote:
Error while opening encoder for output stream #0.1 - maybe incorrect parameters such as bit_rate, rate, width or height
...and did you try to read the man pages on ffmpeg, or (as was suggested to you in the first reply), try to look up how to use that program?? There are THOUSANDS of sites with examples and parameters.
Quote:
$ which HandBrakeCLI
No output. It may not be available
Ok...so INSTALL HANDBRAKE if you don't have it and want to use it.
 
Old 08-11-2014, 05:04 PM   #7
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,289

Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
i like to use xvidenc (or its brother h264enc). heres my output:
Code:
schneidz@xbmc:~$ cat bin/xvidenc-ac3-mkv.ksh 
#!/bin/bash
################### START OF COMMANDS ###################
dvd=`lsdvd $1 | grep "Disc Title:" | awk '{print tolower($3)}' | sed s/_/-/g`
#mkdir /home/xbmc/win/stuff/clips/$dvd
titles=`lsdvd $1 | grep ^Title: | cut -b 8-9 | tail -n 1`
i=1
if [ -n "$2" ]
then
 i=$2
 titles=$2
fi

while [ $i -le $titles ]
do

/usr/bin/mencoder "dvd://$i" -nosub -dvd-device $1 -o /dev/null -vf pp=al:c,softskip,unsharp=l5x5:.25:c5x5:.25,harddup -aid 128 -channels 6 -oac lavc -lavcopts acodec=ac3:abitrate=192 -a52drc 1 -ovc xvid -xvidencopts pass=1:turbo:me_quality=6:vhq=4:threads=2:max_bframes=2:bvhq=1:nopacked:quant_type=h263:noqpel:nogmc:trellis:nointerlacing:chroma_me:chroma_opt:hq_ac:nolumi_mask:rc_reaction_delay_factor=0:rc_averaging_period=100:closed_gop:autoaspect -passlogfile "$dvd-`zero-pad-2.x $i`.log"

/usr/bin/mencoder "dvd://$i" -nosub -dvd-device $1 -o "$dvd-`zero-pad-2.x $i`".avi -ffourcc XVID -vf pp=al:c,softskip,unsharp=l5x5:.25:c5x5:.25,harddup -aid 128 -channels 6 -oac lavc -lavcopts acodec=ac3:abitrate=192 -a52drc 1 -ovc xvid -xvidencopts pass=2:bitrate=1000:me_quality=6:vhq=4:threads=2:max_bframes=2:bvhq=1:nopacked:quant_type=h263:noqpel:nogmc:trellis:nointerlacing:chroma_me:chroma_opt:hq_ac:nolumi_mask:rc_reaction_delay_factor=0:rc_averaging_period=100:closed_gop:autoaspect -passlogfile "$dvd-`zero-pad-2.x $i`.log"

sleep 2

/usr/bin/mkvmerge   --title "$dvd-$title-ac3" --track-name 0:"$dvd-$title-ac3" --language 1:en --track-name 1:"AC3 5.1" "$dvd-`zero-pad-2.x $i`.avi"      -o "$dvd-`zero-pad-2.x $i`.mkv"
sleep 2
rm "$dvd-`zero-pad-2.x $i`.avi" "$dvd-`zero-pad-2.x $i`.log"
i=`expr $i + 1`
done
#################### END OF COMMANDS ####################
 
Old 08-12-2014, 11:23 AM   #8
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,687

Original Poster
Rep: Reputation: 55
Hi all,

Thanks for your advice. Problem solved as follow;

$ apt-get install libavcodec-extra-53
$ avconv -i file.mpg -c:v mpeg2video -q:v 2 -c:a libmp3lame output.mp4

Regards
satimis
 
1 members found this post helpful.
Old 08-12-2014, 12:23 PM   #9
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
The mpeg2 video codec is very old and have very bad compression. Would recommend at least mpeg4.
 
Old 08-12-2014, 01:18 PM   #10
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867Reputation: 4867
.mpg videos are usually MPEG2, so encoding your MP4 video in it does not make much sense, why changing format at all in that case?
Encoding to MPEG4 will not work, MPEG4 (or in short MP4) is a container format.
I would recommend to encode to H.264 instead.

Keep in mind that even if H.264 is the better codec the quality will decrease anyways when converting to that format.
 
Old 08-12-2014, 01:23 PM   #11
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
mpeg4/xvid/divx is also actually a video codec. It is also a contained format, the .mp4. It is a bit confusing, and device compatibility also varies.
 
Old 08-12-2014, 08:47 PM   #12
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,687

Original Poster
Rep: Reputation: 55
Hi all,

Thanks for your advice.

Also I'm confused here. mpg is the format of the Sony video camera in my possession. I have no idea whether I can change the format on recording.

Which format would you recommend on conversion? My problem here is the huge size of the video. Putting the video in a container on my webpage it takes long time to load. I'm running WordPress.

I'm considering uploading the video to YouTube or Vimeo and then embed using that link to the video. But the size of video is dead knot.

Regards
satimis
 
Old 08-12-2014, 09:05 PM   #13
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
The huge size is probably due to the nearly uncompressed mpeg2video. Here's the command I would use:
Code:
ffmpeg -i input.mpg -vcodec libx264 -crf 15 -s 640x480 -aspect 640:480 -r 30 -threads 4 -acodec libvo_aacenc -ab 128k -ar 32000 -async 32000 -ac 2 -scodec copy output.mkv
Try with 'avconv' instead of 'ffmpeg' or you can try some static builds (64-bit only), which I usually use for convenience:
http://johnvansickle.com/ffmpeg/
 
Old 08-12-2014, 10:42 PM   #14
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,687

Original Poster
Rep: Reputation: 55
Quote:
Originally Posted by metaschima View Post
The huge size is probably due to the nearly uncompressed mpeg2video. Here's the command I would use:
Code:
ffmpeg -i input.mpg -vcodec libx264 -crf 15 -s 640x480 -aspect 640:480 -r 30 -threads 4 -acodec libvo_aacenc -ab 128k -ar 32000 -async 32000 -ac 2 -scodec copy output.mkv
Hi,

Your command works for me. Thanks.

Code:
avconv -i input.MPG -c:v mpeg2video -q:v 2 -c:a libmp3lame output.mkv
Also works

Quote:
Try with 'avconv' instead of 'ffmpeg' or you can try some static builds (64-bit only), which I usually use for convenience:
http://johnvansickle.com/ffmpeg/
What is "static builds (64-bit only)"? What is its advantage?

What I expect to achieve is reducing the video size without sacrificing its quality, if possible. Otherwise it takes long time loading the page.

Regards
satimis
 
Old 08-13-2014, 11:02 AM   #15
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
I linked the static builds because I know some distros ship with a broken ffmpeg. There is no real advantage to using them, except for convenience.
 
  


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
Apache handling mpg and mp4 SernOne Linux - Server 9 05-27-2013 12:32 AM
How to convert a video from mp4/flv to mpeg/mpg sadikemre Linux - Newbie 5 03-11-2013 02:16 PM
What you use to convert .avi/.mpg to .mp4 in linux? ishuaia Linux - Software 1 10-24-2007 06:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:40 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
Open Source Consulting | Domain Registration