Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

i am using ffmpeg to create some h264 transport streams. the bitrate for video is 496k, for audio 64k. However when the ( 2-pass ) encoding is done, i get a stream with more then 600k. i am using the following syntax in my script:

codec=h264
streamsuffix=ts
audiocutoff=15000
audioprofile=aac_low
audiosamplerate=48000
video_med=496k
audio_med=64k
suffix_med=_med
preset=veryslow
threads=4
dirname="${1%/*}"
filename=$(basename "$1")
extension="${filename##*.}"
filename="${filename%.*}"

ffmpeg -i $filename"."$extension -preset $preset -strict experimental -threads $threads -c:v $codec -b:v $video_med -bsf:v h264_mp4toannexb -pass 1 -an -f rawvideo -y /dev/null 
ffmpeg -y -i $filename"."$extension -preset $preset -strict experimental -threads $threads -c:a aac -cutoff $audiocutoff -profile:a $audioprofile -b:a $audio_med -ar $audiosamplerate  -c:v $codec -b:v $video_med -bsf:v h264_mp4toannexb -pass 2 $filename$suffix_med"."$streamsuffix

did i miss something? do i need to enforce the target bitrate? thanks a lot!

share|improve this question

migrated from stackoverflow.com Oct 8 '13 at 10:20

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

up vote 3 down vote accepted

Thats about 7% overhead for the TS. Thats about right. ffmpeg's transport stream output is very inefficient. TS streams are divided into 188 byte packets. Each packet has a 4 byte header(leaving 184 bytes of payload), and there is one additional PES header per frame. After the overhead is added to each frame, if the frame does not end on a TS boundary, the final packet is padded out with 0xFF bytes. You can confirm this by looking at the ts file with a hex editor. You can also try to encode to an mp4 and look at the file size.

More info here: http://blog.zencoder.com/2011/12/08/announcing-the-clouds-most-efficient-http-live-streaming/

share|improve this answer
    
thanks mate. that explains a lot! –  zantafio Oct 7 '13 at 21:38
add comment

Where is $video_hi defined, and where is video_med used? Are you sure you have the right variables in the command?

share|improve this answer
    
hi beroe, thanks for that info. i snipped some stuff out of the code, so it got lost ... the original shellscript is correct. –  zantafio Oct 7 '13 at 21:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.