Showing posts with label Linux Multimedia Hacks. Show all posts
Showing posts with label Linux Multimedia Hacks. Show all posts

How to Embed Subtitles to a Video in Linux

How to Embed Subtitles to a Video in Linux


1.) ffmpeg:

$ ffmpeg -i /path-to/videoFoo.avi -vf subtitles=/path-to/subtitleFoo.srt /path-to/output_videoFoo.avi


/or


2.) mencoder:

$ mencoder video.avi -oac copy -ovc lavc -sub /path-to/subtitleFoo.srt -subfont-text-scale 3 -o output_videoFoo.avi





Extract and Convert wmv Files to mp3 Files in Linux

Extract and Convert wmv Files to mp3 Files in Linux


Input at command line:

$ ffmpeg -i file.wmv -vn new.mp3


Notes:
- It actually works for many types of video files as well
- You can remove the -vn option and use it on different kinds of audio files to convert to mp3 files

Merge mp4 Files in Linux

Merge mp4 Files in Linux

One of the best ways to prevent losing quality from concatenating files is to transcode them to mpeg transport streams, using  H.264 video and AAC audio -

$ ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts new1.ts

$ ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts new2.ts

then

$ ffmpeg -i "concat:new1.ts|new2.ts" -c copy -bsf:a aac_adtstoasc output.mp4


Notes:
- In this example I use only 2 mp4 files converted to streams and then concatenating them, but you can
put as much as you like that your system can handle

Merge several mp3 files to one file with mp3wrap and mp3val

Merge several mp3 files to one file with mp3wrap and mp3val

Issue command:

$ mp3wrap tmp.mp3 fooFile01.mp3 fooFile02.mp3 fooFile03.mp3 fooFile04.mp3 && mv tmp*.mp3 new.mp3 && mp3val new.mp3 -f -nb

(Use VLC to easily input metadata into the files)

Notes:
- Mp3wrap and mp3val required for this
- vlc is optional

Download flash videos from Google Chrome and Opera in Linux without other plugins

Download flash videos from Google Chrome without other plugins:

Go to the website where the movie  you desire to download is, the video you want to download must be played/loading when you try this

Open the builtin webtools, or right click mouse on empty space in google chrome, and select inspect element, then point and click to NETWORK, look for the video file in the listing, if no file shows, refresh and reload the video/page itself you want to download the video from, then look again, if it doesnt show just reload the page/video and let it play or load and pause it, til the browser sees it.

Try to use the sort order for easier searching, click the file, if it doesnt download, click open in new tab
or window then right click on the video file and choose save video/save as.

Download flash videos from Opera without other plugins:

Opera Webbrowser

Opera has webtools builtin just like google chrome, do the same and go to the website and specific video you want to download, at the url bar, clear the field and type in - opera:cache , then click the possible data types you want to download, for information regarding files open the webtools like in google chrome, and select network, to have a view of the files, if it doesnt show just reload the page/video and let it play or load and pause it, til the browser sees it.

Convert .MKV to .MP4 in Linux with FFMPEG


Convert .MKV to .MP4 in Linux with FFMPEG:

$ ffmpeg -i input.mkv -vcodec copy -ab 128k -acodec libfaac output.mp4



*NOTES:
- Where input is the source file and output the outcome file.
- The $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.
- Many file formats are supported, for more see $ man ffmpeg

Convert .FLAC audio files to .MP3 in Linux with FFMPEG

Convert .FLAC audio files to .MP3 in Linux with FFMPEG:

$ ffmpeg -i  input.flac -ab 320k output.mp3


*NOTES:
- Where input is the source file and output the outcome file.
- The $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.
- Many file formats are supported, for more see $ man ffmpeg
Join multiple MP4/M4V video files into one continuous video with GPAC:

First install gpac:

In debian based distros, issue command in terminal:

# apt-get install gpac


To join files issue command:

$ MP4Box -cat input1.mp4 -cat input2.mp4 -cat input3.mp4 -new output.mp4


 *NOTES:
- Where input(n).mp4 is the input mp4 files you want to join together, you must start from left to right, left starts the order going to the right what follows in order, it is not limited to 3 files, I limit it to 3 only for example purposes.
- The command is written exactly as it starts with command MP4Box and not mp4box or MP4BOX and etc, if you have an error check your case and spelling.
- The $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.
- The # sign at the start of the command is to signify the root terminal's prompt, no need to type this in.

Quick Way to Create a .GIF Animated Picture in Linux from a Video File

Quick Way to Create a .GIF Animated Picture in Linux from a Video File:

Prerequisite/s:

Be able to use Terminal
Install FFMPEG
Install ImageMagick


Using FFMPEG, we shall extract pictures from a desired video clip, to use for creating the .GIF animated
picture file

$ ffmpeg -i inputfile.avi -r 1 -s sqcif -f image2 image-%3d.jpg

You can also define the image size of the extracted images using the -s flag. The default option is to use the image size same as the video resolution. you can use different video formats just change the file name/extension of the video input in this example we use a .avi video file.

sqcif option stands for the frame size. You can use other options to change sizes:


sqcif 128x96

qcif 176x144

cif 352x288

4cif 704x576

qqvga 160x120

qvga 320x240

vga 640x480

svga 800x600

xga 1024x768

uxga 1600x1200

qxga 2048x1536

sxga 1280x1024

qsxga 2560x2048

hsxga 5120x4096

wvga 852x480

wxga 1366x768

wsxga 1600x1024

wuxga 1920x1200

woxga 2560x1600

wqsxga 3200x2048

wquxga 3840x2400

whsxga 6400x4096

whuxga 7680x4800

cga 320x200

hd480 852x480

hd720 1280x720

hd1080 1920x1080




To create the .GIF issue command below:

$ convert -delay 20 -loop 0 image*.jpg animation.gif

Merge Several mp3 files into just One mp3 File


Merge Several mp3 files into just One mp3 File (with fix the time stamps and search index)

Required programs:
mp3wrap
mp3val


Issue command:

$ mp3wrap tmp.mp3 fooFile01.mp3 fooFile02.mp3 fooFile03.mp3 fooFile04.mp3 && mv tmp*.mp3 new.mp3 && mp3val new.mp3 -f -nb




*NOTES:

- The $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.
- (Use VLC to easily input metadata into the files)

Animated wallpaper on Linux Desktop with XWINWRAP

Animated Wallpaper on Linux Desktop with XWINWRAP:


Download and Install xwinwrap to have animated wallpaper from shantz-xwinwrap @ http://tech.shantanugoel.com/projects/linux/shantz-xwinwrap

Alot of people seem to be having problems with this app with icons, well for me I don't use icons anyways,
and even in this article I assume if you do try it, that you don't use icons, for me its just more clean anyways.

You can actually use a media player like mplayer to play a video as the background if you like with xwinwrap app, however for this example I keep it simple by using the matrix screen saver found in most linux distros, especially debian and debian based ones.


At the website it instructs to using:

- To run glmatrix in fullscreen wallpaper mode

$ ./xwinwrap -ov -fs -- /usr/lib/xscreensaver/glmatrix -root -window-id WID


- To run glmatrix in a small window wallpaper mode

$ ./xwinwrap -ov -g 400x400+400+200 -- /usr/lib/xscreensaver/glmatrix -root -window-id WID


- To run glmatrix in small circle wallpaper mode

$ ./xwinwrap -ov -g 400x400+400+200 -sh circle -- /usr/lib/xscreensaver/glmatrix -root -window-id WID


- To run glmatrix in small triangular wallpaper mode

$ ./xwinwrap -ov -g 400x400+400+200 -sh triangle -- /usr/lib/xscreensaver/glmatrix -root -window-id WID


However, I ran into some problems and I tried several combinations of the options, I would get the whole screen with the animation eating up all my windows/apps/panels even, I found a solution that works, but as I said earlier, I do not use nor have tested it with icons, try the following command if it works out for you:

To run:

$ xwinwrap -ni -o 1 -fs -s -st -sp -b -nf -- /usr/lib/xscreensaver/glmatrix -root -window-id WID

To stop use pkill as below:

$ pkill xwinwrap


(Tested working in LMDE LinuxMint XFCE 4.8, Debian Sid (Unstable) KDE 4.8)


*NOTES:
- I suggest using ALT+F2 and inputting the command/s there, instead of on console prompt, however if you do use a console append an "&" w/o the quotes a the end with a space separating it from the rest, this will indicate to run it on the background so that you wont kill the program by terminating console when you do.
ex:
$ xwinwrap -ni -o 1 -fs -s -st -sp -b -nf -- /usr/lib/xscreensaver/glmatrix -root -window-id WID
to
$ xwinwrap -ni -o 1 -fs -s -st -sp -b -nf -- /usr/lib/xscreensaver/glmatrix -root -window-id WID &
- The $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.



Add Audio to a Video file in Linux with FFMPEG

Add Audio to a Video file in Linux with FFMPEG:

$ ffmpeg -i input.mp4 -i input.mp3 -vcodec copy -acodec libmp3lame output.flv


*NOTES:
- Where input is the source file and output the outcome file.
- The $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.
- Many file formats are supported, for more see $ man ffmpeg

Convert .MPG Video to a Compressed .AVI in Linux with Mencoder


Convert .MPEG/MPG Video to a Compressed .AVI in Linux with Mencoder:

1.) xvid

$ mencoder -ofps 25 -ovc xvid -oac mp3lame -lameopts abr:br=128 -srate 48000 -xvidencopts fixed_quant=4 input.mpg -o output.avi

/or

2.) x264

$ mencoder -ofps 25 -ovc x264 -oac mp3lame -lameopts abr:br=128 -srate 48000 -xvidencopts fixed_quant=4 input.mpg -o output.avi



*NOTES:
- Where input is the source file and output the outcome file.
- The $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.
- Using x264 option than xvid will make it the better compressed file, approx 10-30% smaller, this is my preferred conversion of the two.

Screencasting in Linux with FFMPEG

Screencasting in Linux with FFMPEG:

Open a terminal and issue the command below to start recording a video screencast of your desktop -


$ ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/output.mpg

press CTRL-C to exit.

*NOTES:
- Where output is the outcome file.
- The $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.
- You can name your file and folder to where the video will be saved whatever you like, in this tutorial I just use /tmp and output.mpg as the destination directory and outcome file name.

3 Ways to Join/Merge .AVI video files in Linux:


3 Ways to Join/Merge .AVI video files in Linux:



1.) avimerge

Issue the avimerge command as such:

$ avimerge -i b1.avi b2.avi b3.avi b4.avi b5.avi b6.avi b7.avi -o output.avi



2.) mencoder

Issue the mencoder command as such:

$ mencoder -oac copy -ovc copy file1.avi file2.avi file3.avi -o output.avi




3.) cat & mencoder

Issue the cat command to string together or concatenate the binary .avi files:

$ cat foo1.avi foo2.avi foo3.avi > output.avi

(this will string all binary .avi files first but the sync of audio and video might likely be broken, so follow the next instructions below to fix it.)

after issuing the cat command and getting the final file output from it, issue the following meconder command from the mplayer package:

$ mencoder -forceidx -oac copy -ovc copy input.avi -o output.avi




*NOTES:
- Where input is the source file and output the outcome file.
- the $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.
- The order you set the files to be joined or merged from left to right will be the sequence it will playback as one video file.
- Though for me avimerge is my preferred tool for this task.
- If the header file is broken in the final .avi use the avifix command part of the transcode package, as such:

$ avifix -i input.avi

/or

$ avifix -i input.avi -f 30,1

(this changes the header of the file input.avi and sets the frame rate to 30 fps.)

Convert Image files within current Directory to .MPG video in Linux with FFMPEG


Convert Image/Picture files within current Directory to .MPG video in Linux with FFMPEG:

$ ffmpeg -r 10 -b 1800 -i %03d.jpg output.mp4



*NOTES:
- Where output is the outcome file.
- The $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.
- For this to work the files must start with 001.jpg and count from there in order, be careful not to miss a sequence number for example 001.jpg 002.jpg 003.jpg 005.jpg missing 004.jpg wont count the rest after, 005.jpg and if there are more after wont be added.


Convert an .MPG video to Picture files in Linux with FFMPEG


Convert an .MPG video to Picture files in Linux with FFMPEG:

$ ffmpeg -i input.mpg image%d.jpg

This command will generate the files named image1.jpg, image2.jpg, …

Picture files supported: PGM, PPM, PAM, PGMYUV, JPEG, GIF, PNG, TIFF, SGI.



*NOTES:
- Where input is the source file.
- the $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.

Convert .AVI video to PSP friendly .MP4 video file in Linux with FFMPEG


Convert .AVI video to a PSP friendly .MP4 video file in Linux with FFMPEG:

$ ffmpeg -i input.avi -b 300 -s 320x240 -vcodec xvid -ab 32 -ar 24000 -acodec aac output.mp4

*NOTES:
- Where input is the source file and output the outcome file.
- the $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.

Extract Audio from .AVI video to an .MP3 file in Linux with FFMPEG:


Extract Audio/Music from .AVI video to an .MP3 file in Linux with FFMPEG:

$ ffmpeg -i input.avi -vn -ar 44100 -ac 2 -ab 320k -f mp3 output.mp3

*NOTES:
- Where input is the source file and output the outcome file.
- the $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.

Create VCD/SVCD/DVD from an .AVI in Linux with FFMPEG


Create VCD/SVCD/DVD from an .AVI in Linux with FFMPEG:



$ ffmpeg -i input.avi -target ntsc-dvd /tmp/output.mpg

*NOTES:
- Where input is the source file and output the outcome file.
- the $ sign at the start of the command is to signify the terminal's prompt, no need to type this in.
- ffmpeg can make DVD video files using -target option,
the target can be any of the following "vcd", "svcd", "dvd", "dv", "pal-vcd", "ntsc-vcd", "ntsc-dvd", "ntsc-svcd in the example above ntsc-dvd is used