1

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!

2 Answers 2

3

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/

0
1

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

1
  • 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, 2013 at 21:35

You must log in to answer this question.