# Keyframe alignment problem with Wowza and FFMPEG

**URL:** https://community.wowza.com/t/keyframe-alignment-problem-with-wowza-and-ffmpeg/39715
**Category:** Wowza Streaming Engine
**Created:** [December 28, 2014, 12:19pm UTC](https://community.wowza.com/t/keyframe-alignment-problem-with-wowza-and-ffmpeg/39715 "2014-12-28T12:19:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Mehrdad\_Armanpour](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Mehrdad\_Armanpour](https://community.wowza.com/u/Mehrdad_Armanpour)
#### Post date: [December 28, 2014, 12:19pm UTC](https://community.wowza.com/t/keyframe-alignment-problem-with-wowza-and-ffmpeg/39715/1 "2014-12-28T12:19:31Z")

</div>

Hi guys.

I have a problem which I don’t know how to solve it. The problem is our customers have an unstable bandwidth and when they watch videos, changing bitrate happens a lot. For example they start with 128kbps but after 3 seconds they go up to 5mbps and after 10 seconds they’ll back down on 64kbps. After sometimes, video freeze or going back and forward automatically. Its like i’m watching 3rd bitrate on 00:01:30, when I shift to 4th bitrate video jump to 00:01:35. Sometimes picture freeze, audio go back on beginning of chunk and start playing! When audio reaches to video, video will continue to playback!

It happens a lot and I really don’t know how to fix it. I encoded my videos with FFMPEG exactly as Wowza instructed but I still have the problem. It seems I have keyframe alignment problem but I don’t know how to fix it.

I use Wowza perpetual 4.1.0 (build 12602) with JW Premium.

My protocol is HLS.

Here is the way I encoded videos to 7 bitrates:

ffmpeg.exe -y -i Input.mp4 -s 400x224 -y -strict experimental -acodec aac -ab 64k -ac 2 -ar 48000 -vcodec libx264 -vprofile baseline -level 30 -g 48 -b 50000 -threads 64 output\_50.mp4

ffmpeg.exe -y -i Input.mp4 -s 512x288 -y -strict experimental -acodec aac -ab 64k -ac 2 -ar 48000 -vcodec libx264 -vprofile baseline -level 30 -g 48 -b 150000 -threads 64 output\_150.mp4

ffmpeg.exe -y -i Input.mp4 -s 640x360 -y -strict experimental -acodec aac -ab 64k -ac 2 -ar 48000 -vcodec libx264 -vprofile baseline -level 30 -g 48 -b 300000 -threads 64 output\_300.mp4

ffmpeg.exe -y -i Input.mp4 -s 704x400 -y -strict experimental -acodec aac -ab 128k -ac 2 -ar 48000 -vcodec libx264 -vprofile baseline -level 30 -g 48 -b 500000 -threads 64 output\_500.mp4

ffmpeg.exe -y -i Input.mp4 -s 898x480 -y -strict experimental -acodec aac -ab 128k -ac 2 -ar 48000 -vcodec libx264 -vprofile baseline -level 30 -g 48 -b 700000 -threads 64 output\_700.mp4

ffmpeg.exe -y -i Input.mp4 -s 960x540 -y -strict experimental -acodec aac -ab 128k -ac 2 -ar 48000 -vcodec libx264 -vprofile baseline -level 30 -g 48 -b 1000000 -threads 64 output\_1000.mp4

ffmpeg.exe -y -i Input.mp4 -s 1280x720 -y -strict experimental -acodec aac -ab 128k -ac 2 -ar 48000 -vcodec libx264 -vprofile baseline -level 30 -g 48 -b 1500000 -threads 64 output\_1500.mp4

And here is latest video which has the same problem:

[http://tv.digikala.com/Video/Review/Mobile/Apple\_iPhone\_6\_Review](http://tv.digikala.com/Video/Review/Mobile/Apple_iPhone_6_Review)

---

<div class="post-metadata">

### Author: ![Andrew\_Kennedy1](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@Andrew\_Kennedy1](https://community.wowza.com/u/Andrew_Kennedy1)
#### Post date: [December 28, 2014, 1:16am UTC](https://community.wowza.com/t/keyframe-alignment-problem-with-wowza-and-ffmpeg/39715/2 "2014-12-28T01:16:54Z")

</div>

Hi,

The issue you may be experiencing is that unless 2 pass encoding is used the output from each encode will not be aligned to each other.

Please see this article

[Frequently-requested-FFMPEG-command-examples-for-Wowza](http://community.wowza.com/t/-/36326)

Specifically the example at

1. Generate keyframe aligned multi-bitrate VOD rendition (Linux)

Andrew

---

<div class="post-metadata">

### Author: ![1111](https://avatars.discourse-cdn.com/v4/letter/1/71e660/32.png) [@1111](https://community.wowza.com/u/1111)
#### Post date: [January 7, 2015, 7:44pm UTC](https://community.wowza.com/t/keyframe-alignment-problem-with-wowza-and-ffmpeg/39715/3 "2015-01-07T19:44:21Z")

</div>

> The issue you may be experiencing is that unless 2 pass encoding is used the output from each encode will not be aligned to each other.

Hello,

As far as I know two-pass encoding is used for bitrate estimation: first pass is used to analyze the media and the second for actual encoding at the target bitrate.

In the example, keyframe alignment is achieved using:

> -g 48 -sc\_threshold 0

aka setting the GOP size to 48 (one key-frame every 48 frames) and setting the scene cut detection threshold to 0.

You can also use _-force\_key\_frames_.

[https://ffmpeg.org/ffmpeg.html](https://ffmpeg.org/ffmpeg.html)

The original poster didn’t use _-sc\_threshold 0_.

Best regards.
