Java video processing ffmped + mencoder

Source: Internet
Author: User
Tags benchmark flv file automake
Navigation of this series of articles

FFmpeg Quick Start in Windows

Ffmpeg parameter description

Detailed description of mencoder and ffmpeg parameters (Java video processing)

Java generates video thumbnails (ffmpeg)

Use ffmpeg to convert video files to FLV

Java video processing mencoder

Java video processing ffmped + mencoder

 

Ffmpeg + mencoder can basically complete any audio/video processing operations on the current web-based podcast platform. if you still need to add something, it is the online video recording function, which can also be completed using ffmpeg + fms, therefore, some visible functions similar to YouTube can be implemented in the background in ffmpeg + mencoder + fms. this section does not describe because there is no practice in the fms.
This article has three parts:
1) Build ffmpeg + mencoder Environment
2) Common Operations
3) personal experiences

1. Build ffmpeg + mencoder Environment

1) Overview
Many codec protocols and specialized formats defined by various companies in the audio and video industry make the current video and audio files complicated. The formats supported by ffmpeg alone do not fully include all types, at least swf, the current version of rmvb (rv4) is not supported. at the same time, wma9 seems to be supported. but not tested. at the same time, mencoder supports rm, rmvb, and other formats, but obtaining a frame from a video can only be completed by ffmpeg. therefore, ffmpeg and mencoder can be used to compress and convert all popular formats of videos, set video information, and intercept images in videos. At the same time, other open-source tools such as MediaInfo can be used to obtain video metadata.

2) ffmpeg
Obtain the software package ffmpeg, lame (mp3 supported), ogg vorbis, x264 (h264 codec), xvid, 3gp, libdts, mpeg4 aac. these packages can be found in 71.21/home/zhengyu/tools. if you need to download it online, you can provide it.
Ffmpeg official website download: http://ffmpeg.mplayerhq.hu/ffmpeg-checkout-snapshot.tar.bz2 (svn ).
If there is a problem with the official website download, xplore also provides the January 30 snapshot: Download ffmpeg.

Lame download: current version is 3.97, http://sourceforge.net/project/showfiles.php? Group_id = 290 & package_id = 309 or download lame from xplore.
Ogg vorbis: This general redhat comes with it and does not need to be downloaded. You can check whether/usr/lib/libvorbis. a is absent. If not, you can run yum install or apt-get install.
Xvid download: http://downloads.xvid.org/downloads/xvidcore-1.1.0.tar.gz, xplore download XviD.
Download x264: this can be done in workshop/VideoLAN/x264/snapshots/
Xplore downloads the January 29 snapshot on x264.
Libdts: http://download.chinaunix.net/down.php? Id = 11568 & resourceid = 5785 & Site = 1, xplore download libdts:
In addition to FFMPEG, the above software package is decompressed after download. The compiled parameters are./configure -- prefix =/usr -- enable-shared; Make; sudo make install.

MPEG4 AAc/aad2: http://www.audiocoding.com/modules/mydownloads/visit.php? Cid = 1 & lid = 25 & PHPSESSID = 8267ff75b7c18826fe75eb1c15690862, http://www.audiocoding.com/modules/mydownloads/visit.php? Cid = 1 & lid = 23 & PHPSESSID = 8267ff75b7c18826fe75eb1c15690862.
Faac and faad2 must generate the compilation file by using automake after downloading and uninstalling the package. in faac 1.25, the built-in configure is required. in file, remove the last several lines in AM_OUTPUT and cancel the branch. then follow the operations in bootstrap, which is nothing more than aclocal-I .; autoheader; libtoolize -- automake; automake-a -- copy; autoconfig (or replaced by autoreconf-vif );. /configure -- prefix =/usr -- enable-shared; make; sudo make install;
In version 2.5 of faad2, You need to modify the built-in configure. in file. Otherwise, the compilation will fail if there is no libbmp. Find the following section in configure. in:

Reference if test x $ WITHBMP = xyes; then
AC_DEFINE ([HAVE_BMP], 1, [User wants beep media player plugin built])
AM_CONDITIONAL ([HAVE_XMMS], true)
AM_CONDITIONAL ([HAVE_BMP], true)
Fi

If test x $ WITHDRM = xyes; then
Change
If test x $ WITHBMP = xyes; then
AC_DEFINE ([HAVE_BMP], 1, [User wants beep media player plugin built])
AM_CONDITIONAL ([HAVE_XMMS], true)
AM_CONDITIONAL ([HAVE_BMP], true)
Else
AC_MSG_NOTICE (no bmp build configured)
AM_CONDITIONAL ([HAVE_BMP], false)
Fi

If test x $ WITHDRM = xyes; then

Then autoreconf-vif;./configure -- prefix =/usr -- enable-shared; make; sudo make install;
Here we provide two modified tar packages: make clean; make; sudo make install;. faac1.25 and faad2.5.

3gp support: when compiling ffmpeg to add -- enable-amr_nb -- enable-amr_wb, there will be a prompt, download: http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-510.zip, decompress the source code file and copy the files inside to the ffmpeg source code directory libavcodec/amrwb_float; then download: http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-510.zip, decompress the source code file and copy all the files to libavcodec/amr_float under the ffmpeg unpackage directory, and then compile the package with ffmpeg.
You can also download these two packages here: amrwb_float and amr_float.

After the codec is installed, You can compile ffmpeg. The compilation parameters are as follows:
. /Configure -- prefix =/usr/local -- enable-gpl -- enable-shared -- enable-mp3lame -- enable-amr_nb -- enable-amr_wb -- enable-libogg -- enable-vorbis -- enable-xvid -- enable-amr_if2 -- enable-a52bin -- enable-faadbin -- enable-dts -- enable-pp -- enable-faad -- enable-faac -- enable-x264 -- enable-pthreads -- disable-ffserver -- disable-ffplay
Make
(Sudo make install)
Then you can try to use ffmpeg for video conversion.

3) mencoder
First, obtain the codecs package that comes with the mplayer official website. if you like mplayer, You can also download the gui and font. about mplayer-1.0rc1 found in/home/zhengyu/tools 71.21. if you need to download it online, go to the official website: http: // www. mplayerhq. hu/design7/dload.html. download rc1 address: http://www1.mplayerhq.hu/MPlayer/releases/MPlayer-1.0rc1.tar.bz2. the latest svn version: http: // www1.mplayerhq. hu/MPlayer/releases/mplayer-checkout-snapshot.tar.bz2. the official website also gives some codec, which has rm format codec: http://www1.mplayerhq.hu/MPlayer/releases/codecs/essential-20061022.tar.bz2 (x86 ).
Xplore also provides download, mplayer1.0rc1 download, and codec Download.

After the download is complete, run tar vxjf essential-20061022.tar.bz2; sudo mkdir-p/usr/lib/codecs; sudo cp-rf essential-20061022/*/usr/lib/codecs; then unpack mplayer, compile as follows:

. /Configure -- prefix =/usr/local -- enable-gui -- enable-largefiles -- enable-gif -- enable-png -- enable-jpeg -- language = zh_CN -- with-codecsdir =/usr /lib/codecs/
Make
(Sudo make install)

Then you can use mencoder. Of course, there is also a mplayer without a gui that can play a variety of videos. However, we need mencoder. So far, ffmpeg + mencoder has been set up.

2. Common Operations
For ffmpeg, you can convert the video/audio formats except swf, rmvb, and wmav9 to flv/mp3, and intercept the frame image at a certain time in these video files. these are actually part of a video podcast. for mencoder, you can convert videos/audios in various common formats to flv/mp3. or convert them to avi.
1) ffmpeg:
The command line parameters of ffmpeg are too many and are not listed here. You can use ffpmeg-h to view the. list non-advanced parameters as follows:

Reference Main options:
-L show license
-H show help
-Version show version
-Formats show available formats, codecs, protocols ,...
-F fmt force format
-I filename input file name
-Y overwrite output files
-T duration set the recording time
-Fs limit_size set the limit File Size
-SS time_off set the Start Time Offset
-Itsoffset time_off set the input ts offset
-Title string set the title
-Timestamp time set the timestamp
-Author string set the author
-Copyright string set the Copyright
-Comment string set the comment
-Album string set the album
-V verbose control amount of Logging
-Target type Specify target file type ("VCD", "SVCD", "DVD", "DV", "dv50", "Pal-VCD ", "NTSC-SVCD ",...)
-Dframes number set the number of data frames to record
-Scodec codec force subtitle codec ('copy' to copy stream)
-Newsubtitle add a new subtitle stream to the current output stream
-Slang code set the ISO 639 language code (3 letters) of the current subtitle stream

Video options:
-Vframes number set the number of video frames to record
-R rate set frame rate (Hz value, fraction or abbreviation)
-S size set frame size (WxH or abbreviation)
-Aspect set aspect ratio (, or 1.3333, 1.7777)
-Croptop size set top crop band size (in pixels)
-Cropbottom size set bottom crop band size (in pixels)
-Cropleft size set left crop band size (in pixels)
-Cropright size set right crop band size (in pixels)
-Padtop size set top pad band size (in pixels)
-Padbottom size set bottom pad band size (in pixels)
-Padleft size set left pad band size (in pixels)
-Padright size set right pad band size (in pixels)
-Padcolor color set color of pad bands (Hex 000000 thru FFFFFF)
-Vn disable video
-Vcodec codec force video codec ('copy' to copy stream)
-Sameq use same video quality as source (implies VBR)
-Pass n select the pass number (1 or 2)
-Passlogfile file select two pass log file name
-Newvideo add a new video stream to the current output stream

Subtitle options:
-Scodec codec force subtitle codec ('copy' to copy stream)
-Newsubtitle add a new subtitle stream to the current output stream
-Slang code set the ISO 639 language code (3 letters) of the current subtitle stream

Audio/Video grab options:
-Vd device set video grab device
-Vc channel set video grab channel (DV1394 only)
-Tvstd standard set television standard (NTSC, PAL (SECAM ))
-Ad device set audio device
-Grab format request grabbing using
-Gd device set grab device

Advanced options:
-Map file: stream [: syncfile: syncstream] set input stream mapping
-Map_meta_data outfile: infile set meta data information of outfile from infile
-Benchmark add timings for benchmarking
-Dump each input packet
-Hex when dumping packets, also dump the payload
-Re read input at native frame rate
-Loop_input loop (current only works with images)
-Loop_output number of times to loop output in formats that support looping (0 loops forever)
-Threads count thread count
-Vsync video sync method
-Async audio sync method
-Vglobal video global header storage type
-Copyts copy timestamps
-Shortest finish encoding within shortest input
-Dts_delta_threshold timestamp discontinuity delta threshold
-Ps size set packet size in bits
-Muxdelay seconds set the maximum demux-decode delay
-Muxpreload seconds set the initial demux-decode delay

If you understand this and have a programming foundation, you can participate in ffmpeg development. in fact, these stacked commands 95% are generally not used. here are some simple and Common commands:
-Fromats display available formats
-F fmt forced the fmt Format
-I filename input file
-Y overwrites the output file
-T duration: set the record time in hh: mm: ss [. xxx] format (required)
-Ss position: the specified time [-] hh: mm: ss [. xxx] format is also supported.
-Title string: Set the title
-Author string: Set the author.
-Copyright string sets copyright
-Comment string: Set comments.
-Target type: sets the target file type (vcd, svcd, and dvd). All format options (bit rate, codec, and buffer size) are automatically set. You only need to enter the following: ffmpeg-I myfile. avi-target vcd/tmp/vcd. mpg
-Hq activates high-quality settings

-B bitrate: bit rate. The default value is kb/s.
-R fps: Specifies the frame rate. The default value is 25.
-S size: Specifies the frame size. The format is WXH. The default value is 160X128. You can also use the following shorthand: Sqcif 128X96 qcif 176X144 cif 252X288 4cif 704X576.
-Set aspect to or 1.3333 1.7777
-Croptop/botton/left/right size: Specifies the size of the top slice, in pixels.
-Padtop/botton/left/right size: Set the padding size on the top, in pixels.
-Padcolor color: Fill in the color (hex, six hexadecimal numbers, Red: Green: blue, for example, 000000 represents black)
-Vn does not record videos
-Bt tolerance: sets the video bit rate tolerance kbit/s.
-Maxrate bitrate: sets the maximum video bit rate tolerance.
-Minrate bitreate: sets the minimum video bit rate tolerance.
-Bufsize size: sets the bit rate to control the buffer size.
-Vcodec codec enforces codec encoding/decoding. If copy is used, the original codec data must be copied. (important)

-AB bitrate: Set the audio bit rate.
-Ar freq: Set the audio Sampling Rate
-Ac channels: Specifies the channel. The default value is 1.
-An does not enable audio recording
-Acodec codec uses codec encoding/Decoding

-Vd device: sets a video capture device, such as/dev/video0.
-Vc channel: Specifies the dedicated video capture channel DV1394.
-Tvstd standard: sets the TV standard NTSC PAL (SECAM)
-Set dv1394 to capture DV1394
-Av device: Set audio devices such as/dev/dsp

-Map file: stream sets the input stream ing.
-Debug: Print specific debugging information
-Benchmark indicates the benchmark test time.
-Hex dumping each input package
-Bitexact only uses a bit Precise Algorithm for Codec testing.
-Ps size: Set the package size, in bits.
-Re reads data at a local frame rate, which is mainly used to simulate capturing devices.
-Loop input stream. Only works on image streams for ffserver Testing

Common Methods for ffmpeg operations:

1. Convert to flv file: ffmpeg-I infile. *-y (-ss second_offset-ar-AB-r vr-B vb-s vsize) outfile. flv
Here, second_offset is how many seconds from the beginning. the **: ** format is supported. As for ar, AB is the audio parameter. You can specify ar = 44100, 24000, 48000 (PAL), (NTSC ), the last two common types: AB = 56 (depending on the codec of the video/audio protocol. If you want to listen to high quality, 80 or more ). vr, vb, and vsize are video parameters. You can specify vr = 15, 25 (PAL), 29 (NTSC), and vb = 200,500,800,150 0 (depending on the codec of the video protocol, you can refer to the professional codec instruction document. If you have a detailed codec instruction document, please provide it to me. Thank you very much .)
There are also some parameters-acodec ac-vcodec vc (ac can specify the audio codec, ar and AB, vc can specify the video codec, vr and vb can save, and the corresponding codec parameters are automatically used)
There are also many advanced parameters, such as-qmin and-qcale. Please refer to the detailed documentation.
The-an and-vn parameters are also used to extract pure video and audio from multimedia files.
In addition, if you are using shell batch processing, use the-y parameter to overwrite the flv.

2. screenshot: ffmpeg-I infile. *-y (-ss second_offset)-t 0.001-s msize (-f image_fmt) outfile.jpg
Here, second_offset is the same as above, and msize is the same as vsize. The image size. image_fmt = image2 is forced to use jpg, image_fmt = gif, and forced to use gif.
You can also use-vframes fn to specify a frame to intercept an image. fn =, 3 ,...

 
2) mencoder:
Mencoder is mainly used in video transcoding. After mplayer is installed, mencoder also generates a compilation. man mencoder can get mencoder instructions.
Mencoder parameters are more complex, but they are nothing more than audio processing video. For more information, see the network example http://www.masoncn.com/post/144.html.here.

Mencoder: mencoder infile. *-o outfile. * [-ovc target video format] [-oac target audio format] [-of target file format]

1. convert to flv file: mencoder infile. *-o outfile. flv-of lavf-oac mp3lame-lameopts abr: br = 56-ovc lavc-lavcopts vcodec = flv: vbitrate = 150: mbd = 2: mv0: trell: v4mv: cbp: last_pred = 3-srate 22050
Mencoder infile. rmvb-o outfile. flv-vf scale =--ofps 12-oac mp3lame-ovc xvid-xvidencopts bitrate = 112

2. convert to an avi file: mencoder infile. *-o outfile. avi-of avi-oac mp3lame-lameopts preset = 64-ovc xvid-xvidencopts bitrate = 600

3. convert to a wmv file (complex writing method, where advanced parameters can be omitted): mencoder infile. *-o outfile. wmusic-of lavf-ofps 25-oac mp3lame-lameopts cbr: preset = 128-ovc lavc-lavcopts vcodec = mpeg4: vbitrate = 768: mbd = 2: mv0: trell: v4mv: cbp: last_pred = 3-vf scale = 320: 240-srate 22050-sws 9-subcp cp936-subpos 0-subalign 0-subfont-text-scale 3-lavfopts I _certify_that_my_video_strea

4.: mplayer infile-ss START_TIME-noframedrop-nosound-vo jpeg-frames N

Among them,-ovc,-oac and-of are required.-ovc specifies the video codec. After ovc is specified, it usually carries an opt parameter of the codec.-oac specifies the audio codec, it will also include the opt parameter of codec. you can specify details to determine the video audio quality and conversion rate. for details, refer to the professional technical documents.

3. Some personal experiences
On the video podcast website, there are several problems with the audio and video itself:
1) Some formats of audio and video files are not supported. They cannot be fully implemented.
2) the same content uploaded, but the audio and video deduplication in different formats. There are different levels of Solutions to describe the problem from the storage and application aspects.
3) for audio and video files in some formats, they may be either pure audio or pure video files, such as rm format. How to differentiate such files for ease of application.
4) for Audio/Video Retrieval, whether the video description can be implemented in the content mode rather than the keyword mode defined by the user.
5) use and Process audio and video similarity.
6) download and obtain audio and video files.

Ffmpeg + mencoder can be used to obtain an acceptable solution to the first problem. the third problem is that you can install a front-end filter program after uploading to distinguish between audio files and video files. You already have open-source tools and code to do this. for the second problem, the first is to unify the format, and then calculate the hash of audio and video files. The storage part adopts the distributed CAS Technology for storage, and the application architecture is above the CAS. the fourth question is to be further studied. for the sixth question, we can consider the p2p approach, but this is not very important.
For how to use shell to process video queues and intercept video files in ffmpeg + mencoder + MediaInfo, refer to this article.

Blog Source: http://huqilong.blog.51cto.com/53638/136985

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.