Use ffmpeg in ubuntu to generate videos for images

Source: Internet
Author: User
Tags flv file

Ffmpeg can convert images into videos, which is much better than php's ming extension.

The following is how to use

1. Install ffmpeg first

Ubuntu is very simple apt-get install ffmpeg can be installed successfully, other systems to view their own official Internet cafe ffmpeg open source library URL: http://ffmpeg.org/

2. Call php System commands

The code is as follows: Copy code
System ('ffmpeg-threads 2-y-r 1-I '. $ file. 'Mongod.png'. $ file. 'Out. Flv ');

The parameters are described as follows:

$ File is your own path

-Threads 2 runs in two threads to speed up processing.

-Y overwrites the output file

-R 10 fps is set to 10 frames per second

-I-input image (% d indicates 1 2 3 and other numbers)


Format conversion (convert file. avi to output. flv)

# Ffmpeg-I file. avi output. flv-I indicates the input file
: Now there is a video. avi, and an audio audioaudio, which is merged into output. avi.
Two commands (file. avi is an intermediate file and can be deleted after use)

The code is as follows: Copy code
# Ffmpeg-I video. avi-vcodec copy-an video2.avi
# Ffmpeg-I video2.avi-I audioaudio-vcodec copy-acodec copy output. avi-I indicates the input file

-Vcodec copy indicates force video codec ('copy' to copy stream). It is estimated that this is a direct copy.
-Acodec copy: the audio is the same as the above.
-An: indicates that disable audio is abbreviated as audio no, indicating that the original audio of video. avi is removed.

Method 2 it seems that you can directly specify two input files,

# The Order of ffmpeg-I/tmp/a.wav-I/tmp/a. avi/tmp/a. avi files is very important.
Extract sound from a video (separation of sound and video)

# Ffmpeg-I if you only start with ". flv -vnr1_", extract the sound from the flv file and save it as mp3.
-Vn: indicates ignoring the abbreviation of a video, such as video no.

# Ffmpeg-I if you only see the first video in your life. flv-an r. flv keeps no sound.
-An: indicates that the abbreviation of ignoring sound is audio no.

Extract images from videos ()

The code is as follows: Copy code
# Ffmpeg-I test. avi-y-f image2-ss 8-t 0.001-s 350x240 test.jpg

-Ss screenshot in 8th seconds
Compress mp3 files
If you think the mp3 file is a little large and you want to make it smaller, you can use the-AB option to change the audio bit rate (bitrate)

The code is as follows: Copy code

# Ffmpeg-I input0000- AB 128 output0000// set the bit rate to 128 here

You can run the file command to view the source file information.

The code is as follows: Copy code
Zdio: Audio file with ID3 version 2.3.0, contains: mpeg adts, layer III, v1, 192 kbps, 44.1 kHz, Stereo

192 kbps is the same.

The bit rate in mp3 indicates that when the audio file is compressed to mp3, the digital file determined by the compression software is sent to the player every second during playback. The unit is kilobytes/second; kbps-= kilobits per second. The maximum bit rate of mp3 files is 320 kbps. The size of such a file is very large, and the music per minute exceeds two MB. If you use variable bit rate (VBR) encoding to generate mp3 files and obtain sound quality equivalent to 320 kbps, the file size will be reduced by 25 ~ 50%. Note: the playing time is the same, while the songs are different, and the obtained compressed mp3 files are generally different, because the size of the mp3 file generated by VBR encoding is not only determined by the length of playback time, it also depends on other factors in the source audio file.

Recording (there must be an available microphone, and if alsa is used, it seems like installing alsa-oss and restarting)

The code is as follows: Copy code
# Ffmpeg-f oss-I/dev/dsp out. avi
# Ffmpeg-f alsa-ac 2-I hw: 0, 0 ut. avi
# Ffmpeg-f alsa-ac 2-I pulseoss

It is a sound-related thing in linux. It is the same as alsa, but oss is commercial, while/dev/dsp is the mic device used by oss.

Screen Recording

The code is as follows: Copy code
# Ffmpeg-f x11grab-s xga-r 10-I: 0.0 + 0 + 0 wheer. avi
# Ffmpeg-f x11grab-s 320x240-r 10-I: 0.0 + 100 + 200 wheer. avi: 0: 0

Indicates the screen (for personal understanding, because the system variable $ DISPLAY value is: 0.0) and 100, which indicates that the screen is 100 pixels away from the left end, and 200 indicates that the screen is 200 from the top end.
-S: Set the window size
-R 10 seems to be the set frequency.

The code is as follows: Copy code
# Ffmpeg-f x11grab-s xga-qscale 5-r 10-I: 0.0 + 0 + 0 wheer. avi-qscale 8

Set the image quality. The smaller the value, the better.

Screen Recording and simultaneous recording

The code is as follows: Copy code
# Ffmpeg-f oss-I/dev/dsp-f x11grab-r 30-s 1024x768-I: 0.0 output.mkv
# Ffmpeg-ac 2-f oss-I/dev/dsp-f x11grab-r 30-s 1024x768-I: 0.0-acodec pcm_s16le-vcodec libx264-vpre lossless_ultrafast-threads 0 output.mkv

Seeing this, you will find how powerful this command is,


Ffmpeg has many other functions. If you are interested, you can study it on your own.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.