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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
08-11-2014, 11:24 AM
|
#1
|
Senior Member
Registered: Apr 2003
Posts: 3,695
Rep:
|
convert mpg to mp4
Hi all,
Please advise how to convert .mpg video file to .mp4.
TIA
Regards
satimis
|
|
|
08-11-2014, 11:31 AM
|
#2
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
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.
|
08-11-2014, 11:31 AM
|
#3
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
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 11:34 AM.
|
|
|
08-11-2014, 11:50 AM
|
#4
|
Senior Member
Registered: Apr 2003
Posts: 3,695
Original Poster
Rep:
|
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
|
|
|
08-11-2014, 12:48 PM
|
#5
|
Senior Member
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982
|
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.
|
|
|
08-11-2014, 01:34 PM
|
#6
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,416
|
Quote:
Originally Posted by satimis
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.
|
|
|
08-11-2014, 06:04 PM
|
#7
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
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 ####################
|
|
|
08-12-2014, 12:23 PM
|
#8
|
Senior Member
Registered: Apr 2003
Posts: 3,695
Original Poster
Rep:
|
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.
|
08-12-2014, 01:23 PM
|
#9
|
Senior Member
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982
|
The mpeg2 video codec is very old and have very bad compression. Would recommend at least mpeg4.
|
|
|
08-12-2014, 02:18 PM
|
#10
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
.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.
|
|
|
08-12-2014, 02:23 PM
|
#11
|
Senior Member
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982
|
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.
|
|
|
08-12-2014, 09:47 PM
|
#12
|
Senior Member
Registered: Apr 2003
Posts: 3,695
Original Poster
Rep:
|
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
|
|
|
08-12-2014, 10:05 PM
|
#13
|
Senior Member
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982
|
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/
|
|
|
08-12-2014, 11:42 PM
|
#14
|
Senior Member
Registered: Apr 2003
Posts: 3,695
Original Poster
Rep:
|
Quote:
Originally Posted by metaschima
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
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
|
|
|
08-13-2014, 12:02 PM
|
#15
|
Senior Member
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982
|
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.
|
|
|
All times are GMT -5. The time now is 01:23 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|