Convert AVI video to mp4 and cut using ffmpeg on ubuntu

If you want to convert any AVI file to MP4 or compatible to be used in mobiles, you want to that on ubuntu using “HandBreak” and ffmpeg.

First, make sure you have handbreak installed on ubuntu, if not you can use below commands to do that,

sudo add-apt-repository ppa:stebbins/handbrake-releases

 [sudo] password for myuser:
These are the official HandBrake releases for Ubuntu. Official web site http://handbrake.fr/

HandBrake is an open-source, GPL-licensed, multiplatform, multithreaded video transcoder, available for MacOS X, Linux and Windows.

After adding this PPA to your list of repositories (see "Adding this PPA to your system" below), you can install the HandBrake gtk gui with the command:

apt-get install handbrake-gtk

And you can install the HandBrake CLI with the command:

apt-get install handbrake-cli
More info: https://launchpad.net/~stebbins/+archive/ubuntu/handbrake-releases
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmp0rnft20h/secring.gpg' created
gpg: keyring `/tmp/tmp0rnft20h/pubring.gpg' created
gpg: requesting key 816950D8 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmp0rnft20h/trustdb.gpg: trustdb created
gpg: key 816950D8: public key "Launchpad HandBrake Snapshots" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
OK

$ sudo apt-get update

$ sudo apt-get install handbrake-gtk handbrake-cli

Once HandBreak is installed, browse to the location of your AVI video, ( you can convert other formats as well ) and right click and select “Open with HandBreak” you will get screen like below,

avi to mp4

Please, note the “Ticks” from above image, which you can change as you want and click “Start Encoding”, after some time you will get the video file with “.m4v” extention stored as “Videos” or as path chosen by you in “Destination” as shown above.

Now, if you want to

:~/Desktop/movie/$ ffmpeg -ss 00:00:12 -i DSCN8885.m4v -t 00:00:22 -vcodec copy -acodec copy vr2.m4v

ffmpeg version N-78351-ga25c5db Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab
libavutil 55. 17.100 / 55. 17.100
libavcodec 57. 24.101 / 57. 24.101
libavformat 57. 24.101 / 57. 24.101
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 30.100 / 6. 30.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'DSCN9801.m4v':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2016-04-08 16:05:38
title : DSCN9801
encoder : HandBrake 7412svn 2015082501
Duration: 00:00:52.43, start: 0.000000, bitrate: 3364 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 640x480 [SAR 1:1 DAR 4:3], 3312 kb/s, 30 fps, 30 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2016-04-08 16:05:38
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 8000 Hz, mono, fltp, 48 kb/s (default)
Metadata:
creation_time : 2016-04-08 16:05:38
handler_name : Mono
Output #0, ipod, to 'vr2.m4v':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
title : DSCN9801
encoder : Lavf57.24.101
Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=2-31, 3312 kb/s, 30 fps, 30 tbr, 90k tbn, 90k tbc (default)
Metadata:
creation_time : 2016-04-08 16:05:38
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 8000 Hz, mono, 48 kb/s (default)
Metadata:
creation_time : 2016-04-08 16:05:38
handler_name : Mono
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 797 fps=0.0 q=-1.0 Lsize= 10576kB time=00:00:22.04 bitrate=3929.5kbits/s speed= 908x
video:10408kB audio:156kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.109884%

Using this command, you can cut the video starting from “-ss 00:00:12” i.e. 12 seconds to “-t 00:00:22” i.e. 22 seconds of time. You need to change -i “Name of your video file” and last argument which is output filename.

READ  c program for creating a text file from string in buffer

Leave a Reply

Your email address will not be published. Required fields are marked *