LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   convert mpg to mp4 (https://www.linuxquestions.org/questions/linux-general-1/convert-mpg-to-mp4-4175514239/)

satimis 08-11-2014 10:24 AM

convert mpg to mp4
 
Hi all,

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

TIA

Regards
satimis

TobiSGD 08-11-2014 10:31 AM

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.

szboardstretcher 08-11-2014 10:31 AM

Use ffmpeg:

Code:

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

Code:

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

satimis 08-11-2014 10:50 AM

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

metaschima 08-11-2014 11:48 AM

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.

TB0ne 08-11-2014 12:34 PM

Quote:

Originally Posted by satimis (Post 5218862)
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.

schneidz 08-11-2014 05:04 PM

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 ####################


satimis 08-12-2014 11:23 AM

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

metaschima 08-12-2014 12:23 PM

The mpeg2 video codec is very old and have very bad compression. Would recommend at least mpeg4.

TobiSGD 08-12-2014 01:18 PM

.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.

metaschima 08-12-2014 01:23 PM

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.

satimis 08-12-2014 08:47 PM

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

metaschima 08-12-2014 09:05 PM

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/

satimis 08-12-2014 10:42 PM

Quote:

Originally Posted by metaschima (Post 5219998)
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

metaschima 08-13-2014 11:02 AM

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 05:11 PM.