In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use ffmpeg under linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.
Format conversion (convert file.avi to output.flv)
# ffmpeg-I file.avi output.flv
-I represents the input file
Now there is a video video.avi and an audio audio.mp3, which are merged into output.avi
Two commands (file.avi is an intermediate file, which can be deleted after use)
# ffmpeg-I video.avi-vcodec copy-an video2.avi # ffmpeg-I video2.avi-I audio.mp3-vcodec copy-acodec copy output.avi
-I represents the input file
-vcodec copy means force video codec ('copy' to copy stream). I don't know how to translate this, but it's probably direct copy.
-acodec copy should be talking about audio, just like above.
-an: indicates that disable audio is estimated to be an abbreviation such as audio no, and that the original audio of video.avi is removed.
Method 2 seems to specify two input files directly.
# ffmpeg-I / tmp/a.wav-I / tmp/a.avi / tmp/a.avi
The order of the two files is important.
Extract sound from video (separation of sound from video)
# ffmpeg-I if life is just like the first time. FLV-vnr.mp3
Extract sound from flv file and save it to mp3 format
-vn: ignores abbreviations such as video no for video estimation.
# ffmpeg-I if life is just like the first time. FLV-an r.flv
Only video but no sound
-an: means to ignore acronyms such as audio no for sound estimation
Extract pictures from video ()
# ffmpeg-I test.avi-y-f image2-ss 8-t 0.001-s 350x240 test.jpg-ss
Take a picture at the 8th second.
Compress mp3 file
If you think the mp3 file is a little big and you want to make it smaller, you can change the bit rate (bitrate) of the audio with the-ab option.
# ffmpeg-I input.mp3-ab 128 output.mp3
/ / set the bit rate to 128 here
You can use the file command to check the information of the source file
Z.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 192 kbps, 44.1 kHz, Stereo
One hundred and twenty-two kbps is this thing.
The meaning of bit rate in mp3 is: when the audio file is compressed to mp3, the digital file determined by the compression software will be transmitted to the player every second, in kilobits per second; the English meaning is: kbps-= kilobits per second. Now the highest digit rate for mp3 files is 320 kbps. Such files are large, with more than two megabytes of music per minute. If you use variable bit rate (VBR) coding to generate a mp3 file with sound quality equivalent to 320 kbps, the size of the file will be reduced by 2550%. Please note that the compressed mp3 files obtained are generally different when the playback time is the same, while the songs are different, because the size of the mp3 file generated by VBR encoding depends not only on the length of playback time, but also on other factors of the source audio file.
Recording (need to have an available microphone, and if you use alsa, it seems to have to install alsa-oss, restart)
# 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 pulse
Oss is related to sound under linux, just like alsa, but oss is commercial, and / dev/dsp is Mike's device used by oss.
Screen video recording
# ffmpeg-f x11grab-s xga-r 10-I: 0. 020 wheer.avi # ffmpeg-f x11grab-s 320x240-r 10-I: 0. 0100 million 200 wheer.avi
0:0 represents the screen (personal understanding, because the system variable $display value is: 0.0) and 100s from the left end, 200 pixels from the upper end
-s sets the window size
-r 10 seems to set the frequency. I don't understand.
# ffmpeg-f x11grab-s xga-qscale 5murr 10-I: 0. 020 wheer.avi
-qscale 8 sets the picture quality. The smaller the value, the better.
Screen recording and recording at the same time
# 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
When you see this, you will see how powerful this command is.
If I have a window open on the screen, I only want to record the contents of the window. How can I determine the coordinate location of the window?
You can use another command.
After xwininfo enters this command, click on the target window with the mouse
A series of information such as the coordinates, width and height of the target window will appear.
Absolute upper-left X: 276
Absolute upper-left Y: 57
Relative upper-left X: 2
Relative upper-left Y: 23
Width: 742
Height: 499
Depth: 24
Visual: 0 × 21
Visual Class: TrueColor
Border width: 0
Class: InputOutput
Colormap: 0 × 20 (installed)
Bit Gravity State: NorthWestGravity
Window Gravity State: NorthWestGravity
Backing Store State: NotUseful
Save Under State: no
Map State: IsViewable
Override Redirect State: no
Corners: + 276-262-244
-geometry 80 × 24027434 have you seen this line ()
For example, according to the information above,
# ffmpeg-f oss-I / dev/dsp-f x11grab-r 30-s 1280x752-I: 0.020 output.avi
Another thing you can change is the video frame rate (FPS). In the example above we used-r 30 which means capture at 30 FPS. You can change this value to whatever frame rate you want.
This-r 30 should be sampled several times per second, with an estimated screen capture of 30 times a second.
Cut the head to the tail
# ffmpeg-ss 00:00:10-t 00:01:22-I May Day-suddenly miss you .mp3 output.mp3
As long as the interception starts from the 10th second, a total of 1: 22:00 long content is intercepted, and the connection of video files, such as two flv files, is connected into one piece.
It seems that the file must be converted to mpg, dv and other formats before it can be connected.
An example of connecting plural AVI video files (in this example, it is necessary to temporarily convert AVI files to MPEG-1 files (MPEG-1, MPEG-2 PS, DV format can also be connected)
# ffmpeg-I input1.avi-sameq inputfile_01.mpg-r 20 # ffmpeg-I input2.avi-sameq inputfile_02.mpg-r 20 # cat inputfile_01.mpg inputfile_02.mpg > inputfile_all.mpg # ffmpeg-I inputfile_all.mpg-sameq outputfile.avi
The above merges input1.avi input2.avi into outputfile.avi
-sameq means the same quality (may refer to the picture, not very clear)
-r refers to frequency
=
Here are a few examples given on wiki
Parameters.
FFmpeg can use many parameters, and the contents of the parameters will vary according to the version of ffmpeg. It is recommended to refer to the parameters and codecs before using them. In addition, the details of parameters can be displayed by ffmpeg-h, and the details such as the name of codec can be displayed by ffmpeg-formats.
The following are the more commonly used parameters.
Main parameters
-I set the input file name.
-f sets the output format.
-y overwrite the file if the output file already exists.
-the conversion ends when the fs exceeds the specified file size.
-ss starts conversion from the specified time.
-title sets the title.
-timestamp sets the timestamp.
-vsync adds or subtracts Frame to synchronize audio and video.
Image parameters
-b set image traffic. Default is 200Kbit/ seconds. (for units, please refer to the notes below)
-r sets the FrameRate value, which defaults to 25.
-s sets the width and height of the screen.
-aspect sets the scale of the screen.
-vn does not process images and is used when processing only sound.
-vcodec sets the image codec. If it is not set, it uses the same codec as the input file.
Sound parameters
-ab sets the traffic per Channel (the most recent SVN version is the sum of all Channel). (for units, please refer to the notes below)
-ar sets the sampling rate.
-ac sets the number of Channel of the sound.
-acodec sets the sound codec, which is the same as the image when not set, and uses the same codec as the input file.
-an does not process sound and is used when processing only images.
-vol sets the volume, which is the standard volume. (to set it to twice the volume, enter 512, and so on.)
Matters needing attention
When setting the flow with-b and ab parameters, it should be noted that the unit will be different from bits/sec according to the version of ffmpeg used. (you can use the ffmpeg-h display description to confirm the unit. )
For example, in the case of bits/sec, you need to enter'- ab 64k 'when you want to specify the traffic 64kbps, and enter'-ab 64'in the case of kbits/sec.
The codec names specified with-acodec and-vcodec vary depending on the version of ffmpeg used. For example, when using AAC codecs, there will be cases of entering aac and libfaac. In addition, codecs are divided into codecs for decoding and encoding only, so it is important to use ffmpeg-formats to confirm whether the input codec can work.
Example
An example of converting MPEG-1 movies to MPEG-4 format
# ffmpeg-I inputfile.mpg-f mp4-acodec libfaac-vcodec mpeg4-b 256k-ab 64k outputfile.mp4
An example of converting MP3 sound to MPEG-4 format
# ffmpeg-I inputfile.mp3-f mp4-acodec libaac-vn-ab 64k outputfile.mp4
An example of converting a VOB file from DVD to a MPEG-1 file in VideoCD format
# ffmpeg-I inputfile.vob-fmpeg-acodec mp2-vcodec mpeg1video-s 352x240-b 1152k-ab 128k outputfile.mpg
An example of converting AVI movies to M4V files in H.264 format
# ffmpeg-I inputfile.avi-f mp4-acodec libfaac-vcodec libx264-b 512k-ab 320k outputfile.m4v
An example of converting any movie into a Toshiba REGZA-recognizable MPEG2 format
# ffmpeg-I inputfile-target ntsc-svcd-ab 128k-aspect 4:3-s 720x480 outputfile.mpg
An example of connecting plural AVI video files (in this example, it is necessary to temporarily convert AVI files to MPEG-1 files (MPEG-1, MPEG-2 PSDV format can also be connected),
# ffmpeg-I input1.avi-sameq inputfile_01.mpg # ffmpeg-I input2.avi-sameq inputfile_02.mpg # cat inputfile_01.mpg inputfile_02.mpg > inputfile_all.mpg # ffmpeg-I inputfile_all.mpg-sameq outputfile.avi
=
Http://ffmpeg.org/ffmpeg-doc.html
Http://ubuntuforums.org/showthread.php?t=1392026
Some problems that we can figure out at the same time
In the alsa system, the sound card (or microphone,) is called hw:0,0, while in the oss system, it is called / dev/dsp (words may not be very professional) Linux. After installing the sound card, some device files will be generated.
The / dev/dsp file of the digital sample is collected. For the mixer's / dev/mixer file, the / dev/sequencer,/dev/audio file for the sequencer is a sound device file based on compatibility considerations. Just input the wav file into / dev/audio to make a sound. The audio text in WAV file format can be obtained by reading the / dev/dsp file.
Press rmvb into mp4 with ffmpeg
1. View rmvb properties
Check the file attributes before conversion, take a look at the resolution and other information, if the resolution is more than 960,640, you need to adjust. By the way, take a look at the bit rate and refer to it when it is pressed into x264.
Ffmpeg-I file name
2. Pressed into mp4
1) .pass1 coding
Ffmpeg-I 01.rmvb-an-vcodec libx264-b 560k-pass 1-f mp4-y NUL
-an: does not encode audio
-vcodec: set the video encoding. I use x264 here.
-b: this is the bit rate
-f: force the format
-y: automatically enter y for confirmation
NUL: because it's pass1, you don't need an output file, just use NUL.
2) .pass2 coding
Ffmpeg-I 01.rmvb-acodec copy-vcodec libx264-b 560k-pass 2-f mp4 01.mp4
Because many audio parts of rmvb are encoded by aac, you can copy the audio part directly with-acodec copy.
3. Parameter adjustment for some files
Some rmvb or mkv and other high resolution, so the transfer to itouch needs to be adjusted. In ffmpeg, you can use the-s parameter: ffmpeg-I 01.rmvb-acodec copy-vcodec libx264-b 560k-s 960x640-f mp4 01.mp4
Ffmpeg-I 01.rmvb-acodec copy-vcodec libx264-b 560k-s 960x640-f mp4 01.mp4
960x640 needs to calculate by itself and adjust it proportionally.
Intercept by time
Ffmpeg-I 01.rmvb-acodec copy-vcodec libx264-b 560k-ss 00:00:00-t 00:01:00-f mp4 01.mp4
Setting B-frame has some advantages for cartoons, but it is not obvious when 2pass, but it is more obvious for 1pass:
Ffmpeg-I 01.rmvb-acodec copy-vcodec libx264-b 560k-bf 6-f mp4 01.mp4 thank you for reading this article carefully. I hope the article "how to use ffmpeg under linux" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 240
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Cat / etc/redhat-releaseuname-runame-muname-an all display
© 2024 shulou.com SLNews company. All rights reserved.