View Full Version : reducing bitrate with ffmpeg
loldmanjenkins
11th February 2011, 03:39
Hi, I have a video file encoded in h.264 inside of mp4. I'd like to reduce the video and audio bit rate while retaining the same file format. How do I do that?
Blue_MiSfit
11th February 2011, 04:58
Hi loldmanjenkins, welcome to doom9!
A few thoughts:
1) Simply reducing the bitrate of a file without completely decoding and re-encoding it is typically impossible. There are exceptions to this rule (see tools like DVD Shrink that can perform so-called "compressed domain transcoding"), but even when possible it's generally a poor idea if you're concerned with quality.
2) Thankfully, you can probably re-encode this video without much trouble. Can you provide more information about the source file? A mediainfo dump would be nice :)
3) What are you trying to transcode this file to? Is there a particular piece of hardware you'd like to ensure compatibility with, or are you just playing back on PC? Are you just transcoding in an attempt to save space?
Again, welcome!
Thanks,
Derek
loldmanjenkins
11th February 2011, 06:27
Here's a mediainfo dump:
General
Complete name : D:\videos\rendered\Produce0.MP4
Format : MPEG-4
Format profile : Sony PSP
Codec ID : MSNV
File size : 830 MiB
Duration : 1h 12mn
Overall bit rate : 1 603 Kbps
Encoded date : UTC 2011-02-11 03:18:45
Tagged date : UTC 2011-02-11 03:18:45
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : Baseline@L3.0
Format settings, CABAC : No
Format settings, ReFrames : 2 frames
Format settings, GOP : M=1, N=29
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 1h 12mn
Bit rate mode : Variable
Bit rate : 1 505 Kbps
Width : 640 pixels
Height : 480 pixels
Display aspect ratio : 4:3
Frame rate mode : Variable
Frame rate : 29.970 fps
Minimum frame rate : 29.940 fps
Maximum frame rate : 29.970 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.163
Stream size : 779 MiB (94%)
Language : English
Encoded date : UTC 2011-02-11 03:18:45
Tagged date : UTC 2011-02-11 03:18:45
Audio
ID : 2
Format : AAC
Format/Info : Advanced Audio Codec
Format profile : LC
Codec ID : 40
Duration : 1h 12mn
Bit rate mode : Constant
Bit rate : 96.0 Kbps
Nominal bit rate : 128 Kbps
Channel(s) : 2 channels
Channel positions : Front: L R
Sampling rate : 48.0 KHz
Compression mode : Lossy
Stream size : 49.5 MiB (6%)
Language : English
Encoded date : UTC 2011-02-11 03:18:45
Tagged date : UTC 2011-02-11 03:18:45
I'm trying to encode for streaming, playback is with flash.
Thanks :)
Blue_MiSfit
11th February 2011, 08:14
This file should stream through flash as-is, without any transcoding.
Here is some good general reading: http://mewiki.project357.com/wiki/X264_Encoding_Suggestions
If you need a lower bitrate, or the bitrate simply varies too much, I'd suggest using the following x264 command to encode the video. I'm assuming here that you want 1mbps average bitrate, but are targeting a client with a 1.5mbps connection speed, and want a very short buffer time - say half a second. Furthermore, I'm assuming that you're OK with the cpu requirements of high profile (which aren't so bad actually). Finally, I'm assuming the content is either film or 3D CGI. If you are encoding traditional animation, swap --tune film for --tune animation. Oh... and I'm not taking audio into consideration :)
As always with x264, use the slowest preset you can stand, in terms of encoding time. I wouldn't go faster then --preset faster unless you really need to, and wouldn't go over --preset veryslow unless you really don't care how long it takes to encode.
x264 input.mp4 --level 30 --bitrate 1000 --vbv-maxrate 1500 --vbv-bufsize 500 --tune film --pass 1 --output nul
x264 input.mp4 --level 30 --bitrate 1000 --vbv-maxrate 1500 --vbv-bufsize 500 --tune film --pass 2 --output output.mp4
Take this all with a grain of salt. I do mostly CRF encoding, and CBR encoding - neither of which are optimal for this case ;)
Cheers,
Derek
loldmanjenkins
11th February 2011, 11:14
hey that works, only how do I insert the audio stream back in into the output file?
Blue_MiSfit
11th February 2011, 21:43
You can use mp4box, with or without its GUI, YAMB.
I'd suggest using the GUI :)
Also, you may want to re-encode the audio to CBR to prevent any bitrate spikes. I'd use ffmpeg to decode the audio to a WAV file, and then use NeroAACEnc to encode a CBR m4a file. You can then use MP4Box on this m4a, plus the MP4 from x264.
Cheers,
Derek
loldmanjenkins
13th February 2011, 06:45
cool I've done that and it works very well, one thing though, some users report that sometimes the audio goes out of sync or mutes all together.
Here's my command line:
x264 input.mp4 --level 30 --bitrate 400 --vbv-maxrate 500 --vbv-bufsize 500 --tune film --pass 1 --output nul
x264 input.mp4 --level 30 --bitrate 400 --vbv-maxrate 500 --vbv-bufsize 500 --tune film --pass 2 --output output1.mp4
ffmpeg -i input.mp4 -acodec pcm_s16le audiotemp.wav
neroAacEnc.exe -cbr 80000 -if audiotemp.wav -of audiotemp.m4a
MP4Box.exe -add output1.mp4 -add audiotemp.m4a -itags tool="qwerty" "output1combined.mp4"
Blue_MiSfit
13th February 2011, 10:53
Interesting. My experience with streaming via flash is not very extensive. I'm assuming you've QCd the video in a software player and don't experience any sync / mute issues? Do you have data on which versions of Flash player your users are running?
Some fairly random ideas:
1) Try a different version of mp4box, or a different muxer altogether.
2) Try encoding CBR video - i.e. make bitrate=maxrate
3) ???
Derek
loldmanjenkins
13th February 2011, 11:54
I'll try cbr video
what's another good muxer?
Blue_MiSfit
14th February 2011, 02:44
Dunno, there are a few commercial solutions available (Monogram etc). ffmpeg can mux mp4 IIRC, Other than that not sure.
I'd look into the player situation, personally.
Derek
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.