天天看點

ffmpeg 轉換flv壓縮大小_ffmpeg轉換參數和壓縮輸出大小的比率

該樓層疑似違規已被系統折疊 隐藏此樓檢視此樓

ffmpeg 轉換壓縮比例

FFMPEG如果是壓縮為FLV檔案 3個編碼可選

1. -c:v flv 标準FLV編碼 這個好處是速度快 清晰度高的話 視訊檔案會比較大

2. -c:v vp6 VP6編碼 這個大家都很少使用 其實這個也算不錯

3. -c:v libx264 H.264編碼 估計使用這個的比較多 優點是同等清晰度 視訊檔案更小 缺點就是轉換慢的吐血

以1.11G大小的電影 轉換為例子

libx264 500k 出片為 572.36M

flv編碼 清晰度5 出片為 872.94M

2個看起來flv的清晰度 還不如libx264的

竟然大了足足300M……

音頻都是一樣 都是Pass 1

下面是以前的備注文檔 貼出來共享下

壓縮配置選項

===============================

512Kbps

視頻bitrate 設置為 360k 最大416k 音頻設置為64k

1Mbps

視頻bitrate 設置為720k 最大832k 音頻設置為 128k

2Mbps HD

視頻bitrate 設置為1550k 最大1792k 音頻設置為128k

視頻壓縮大小

===============================

出片 Bitrate 10分鐘的視訊

320p 180 kbit/s ~13 MB

360p 300 kbit/s ~22 MB

480p 500 kbit/s ~37 MB

576p 850 kbit/s ~63 MB (SD/PAL)

720p 1000 kbit/s ~75 MB

FFMPEG參數

===============================================

-i 輸入檔案 test.avi 或其他

-c:v libx264 使用h.264 編碼

-vcodec libx264 強制指定視頻編碼模式

-profile:v high 使用H.264的High模式 比較消耗資源

-pre slow 使用慢速模式 耗時間 清晰度高

//該參數還可選擇 ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo

-b:v 360k / 720k / 1550k 視頻比特率 (該參數比較重要 如果是轉換Web用途 是否正確直接影響視頻播放流暢程度)

-maxrate 500k 最大比特率

-bufsize 1000k 比特率緩衝大小

-s 000×000

視頻大小 建議值

240P 320×240 //Mobile iPhone MP4

360P 640×360 //SD FLV

480P 864×480 //HD MP4

720P 960×720 //HD MP4

-threads 0 處理器核心利用數量

-aspect 16:9 / 4:3 視頻比例

-pass N 1-3可選

音頻

-acodec libfaac 強制指定音頻處理模式

-ac 2 聲道選擇

-ar 44100 音頻赫茲

-ab 128k 比特率 64k/128k

-acodec libfaac -ac 2 -ar 44100 -ab 64k

In this article we show how to resize any video file.This method is one of the bests ways to resize a video file in Linux systems (almost any distribution), and an excellent alternative to Windows and Mac users.

Changing the resolution of a video file will be one of the most common operations that we will perform when working with video files, and as such ffmpeg is able to do it perfectly. There are several reasons why we should want to change the resolution of a video file, for example:

To reduce the size of the video. This is possible by reducing the resolution of the video. If we take for example a video in HD (1920x1080 pixels) but we know that we will never see on a screen that supports a higher resolution than say 1024x768, we can reduce the video resolution to adapt to this new resolution, saving plenty of storage space and if used on Internet, saving bandwidth also.

Many times the resolution is changed on video files to standardize its format. That is, if we have several videos and we want them all in the same resolution, will have to go through this process of changing resolution.

In the development of modern websites it is quite useful to have the videos in various resolutions depending on where they appear. We can develop sites with responsive designs in which the most suitable video for the user plays. For example, if we have a video in various formats-we say 1920x1080, 1280x720, and 640x360- we can design a responsive site that makes visitors reproduce the proper video resolution depending on visitor browser saving bandwith (keep in mind that mobile users usually pay for transferred data so it is better to transfer as less traffic as possible)

In this example we will reduce the resolution of a video in HD format (1920x1080 pixels) to 640x360 (this is a fairly used configuration for aspect ratio 16:9):

ffmpeg -i video_1920.mp4 -vf scale=640:360 video_640.mp4 -hide_banner

It is only necessary to indicate the scale video filter with the new desired resolution (640:360) with -vf scale=640:360. To consider:

We can indicate any resolution we want, but the resulting video will always have the same aspect ratio. That is, it will not distort the images, if video is in 16:9 aspect ratio, it will keep the video in 16:9 aspect ratio. The program will adjust the resulting video so it can fit in the resolution that we have given.

When changing resolution, the video must go throught the encoding process another time, so the process can be slow depending on the output format and the codec you're using for the output.

We have not mentioned it, but most of the time it does not make sense to transform a video to a higher resolution because, there can't be any improvement in video quality.

Changing the video aspect ratio

If we want to change the look of the video, knowing that the image will appear distorted, we can use an additional filter "setdar". Imagine that in the previous case we want to change the 16:9 aspect ratio to 4:3, and therefore the video at a resolution of 4:3 aspect ratio, which in this case it will be 640x480. The ffmpeg command to make this transformation would be:

ffmpeg -i video_1920.mp4 -vf scale=640:480,setdar=4:3 video_640x480.mp4 -hide_banner

The video output that we get in this case video_640x480.mp4 changes the appearance of the original video and has distorted images a bit, but it will get the resolution we want with new look.

If on the other hand, we do not want to rely on using an aspect ratio which could be "more normal" (4:3, 16:9) or if we want to make changes to other resolutions with undefined aspect ratio and we are not afraid of possible deformations of images that will appear, we can use the "setsar" filter that will save you from having to keep those aspect ratios. In this way we could transform the previous video to a resolution of 200x400 for example, with the following command:

ffmpeg -i video_1920.mp4 -vf scale=200:400,setsar=1:1 video_200x400.mp4 -hide_banner

The result in 200x400 resolution from 1920x1080 resolution makes the video output to have a distorted appearance.

Examples of video resizing

We are going to see some examples of video resizing using ffmpeg. We have an original video with a resolution of 320x180 pixels. Here it is.

As we have seen previously we can resize the video to half its original size. We are resizing it from a 320x180 pixels resolution to a 160x90 pixels resolution with the following command:

ffmpeg -i video_320x180.mp4 -vf scale=160:90 video_180x90.mp4 -hide_banner

The video has gone from a size of 1.18MB to a 354KB video (one quarter). Here is the result:

Note that the video is smaller, but we can tell the browser to make it bigger with some loss of quality compared to the original.

Now let's change the original video aspect ratio from 16:9 to 4:3. To do this we are resizing video from 320x180 to 320x240 with the following command:

ffmpeg -i video_320x180.mp4 -vf scale=320:240,setdar=4:3 video_320x240.mp4 -hide_banner

And here is the result (you can see that images appear distorted):

And now at last we will resize the video as if it has to fit in a vertical screen, so we resize from 320x180 pixels to 180x320 pixels. Here is the command which will do the task:

ffmpeg -i video_320x180.mp4 -vf scale=180:320,setsar=1:1 video_180x320.mp4 -hide_banner

And here is the distorted result:

Note that in this videos I have also included a source in webm format for maximum compatibility. I have done this way so if your browser is not able to work directly with mp4 files you can see the results in a similar webm file.