axiomatic-systems / Bento4

Full-featured MP4 format, MPEG DASH, HLS, CMAF SDK and tools
http://www.bento4.com
2.01k stars 482 forks source link

Video tracks are not aligned (different frame rates) #263

Open sasquatch74 opened 6 years ago

sasquatch74 commented 6 years ago

I am facing the following issue:

  1. The inputs are 5 multi bit-rate mp4 files. Four of these have a frame rate of 25 fps and the fifth one has 10 fps.
  2. I checked the GOP size on each of them. The 25 fps files have GOP size of 1 second (i.e., one I-frame every 25 frames). The 10 fps file has the GOP size of 1 second (i.e., one I-frame every 10 frames).
  3. mp4fragment command seems to work fine: mp4fragment.exe --fragment-duration 10000 inputfile.mp4 outputfile.mp4
  4. mp4dash always returns the following error: WARNING: video sample count mismatch between "File 5#1" and "File 4#1" ERROR: video tracks are not aligned ("File 5#1" differs from File 1#1)
  5. If I remove the 10 fps file from the mp4dash command, it works fine and generates the dash manifest.

I understand that mp4dash requires the key-frames to align, but when you have files with different frame rates, the key frames do not align by frame count but they do align if you consider the time in seconds or milliseconds.

What am I doing wrong?

maetthu commented 6 years ago

@sasquatch74 I'm facing the same issue. Did you find a solution/workaround?

barbibulle commented 6 years ago

To be honest, this isn't a scenario I have tested (different frame rates). So it may very well be an issue with the Bento4 packager. I will try this use case and followup.

maetthu commented 6 years ago

@barbibulle thanks :)

Up until now, we had all our videos up to 1080p, all being 30fps and a fixed 60 frames keyframe interval, but now we're trying to add 1080p@60 and 1440p@60 with a 120 frame keyframe interval to the mix, but with them added, mp4dash complains about the alignment. I tried forcing mp4fragment to a 2s segment size for both, but with the same result. As far as I understand, both align at 2s, despite the different framerate.

sasquatch74 commented 6 years ago

@maetthu We couldn't make Bento4 packager work when source mp4 files had different frame rates. We used a different packager (the one from Unified Streaming - this is not free) to get it to work.

maetthu commented 6 years ago

@barbibulle Did you have a chance to look into this? No worries if not, it's just that we will start with our encoding project soon and it would be nice to know if multiple framerates is something you'd consider worth supporting in the Bento4 packager.

barbibulle commented 6 years ago

@maetthu Sorry for not having looked at this earlier. Would it be possible for send me a link to some sample files that I could use to easily replicate the issue on my side? This would save me some time. Thanks.

maetthu commented 6 years ago

@barbibulle sure! thanks for looking at it :slightly_smiling_face:

These are streaming versions I transcoded from 1080p@60fps version of the Big Buck Bunny video:

Steps to reproduce:

$ mp4fragment 1080p_60.mp4 1080p_60.fmp4
found regular I-frame interval: 120 frames (at 60.000 frames per second)
$ mp4fragment 720p_30.mp4 720p_30.fmp4
found regular I-frame interval: 60 frames (at 30.000 frames per second)
$ mp4dash -o out/ -f --mpd-name=master.mpd --hls *.fmp4
Parsing media file 1: 1080p_60.fmp4
Parsing media file 2: 720p_30.fmp4
WARNING: video sample count mismatch between "File 2#2" and "File 1#2"
ERROR: video tracks are not aligned ("File 2#2" differs from File 1#2)
maetthu commented 6 years ago

@barbibulle did you have a chance looking into it?

barbibulle commented 5 years ago

I have fixed this on master (still haven't pushed a new set of pre-compiled binaries). Let me know if this works for you.

wmucheru commented 5 years ago

@barbibulle Thanks for the fix on this. I'm however facing this issue when running mp4dash for 360, 480 and 720p renditions of my mp4 file to generate an ABR stream. I'm using the latest binaries for macOS but still facing this issue. What can I do to run it successfully?

Benny739 commented 4 years ago

Same issue here

rodrigo-brito commented 4 years ago

Same problem here, the last Linux release returns the same error.

baloda commented 3 years ago

Facing the same issue. can someone help me? not sure how and what to fix FFmpeg Transcoding:

ffmpeg -loglevel error -i source.mp4 \ -map 0:v \ -movflags +faststart -vsync 1 \ -c:v libx264 \ -s 256x144 \ -g 30 \ -profile:v main \ -b:v 244894 \ -y 1.mp4

ffmpeg -loglevel error -i source.mp4 \ -map 0:v \ -movflags +faststart -vsync 1 \ -c:v libx264 \ -s 416x234 \ -b:v 424101 \ -g 30 \ -profile:v main \ -y 2.mp4

ERROR: video tracks are not aligned ("File 2#1" differs from File 1#1)

debug output of mp4dash: Segment Count = 56 Type = video Sample Count = 2767 Average segment bitrate = 253547 Max segment bitrate = 645680 Required bandwidth = 386983 Average segment duration = 2.001481481481483

Segment Count            = 56
Type                     = video
Sample Count             = 2767
Average segment bitrate  = 439965
Max segment bitrate      = 1136650
Required bandwidth       = 721261
Average segment duration = 2.001481481481483
rodrigo-brito commented 3 years ago

Hi @baloda. I solved the problem with a fixed fps (24FPS) and segments of two seconds (gop = 2 * 24 = 48). My FFMPEG parameters are:

-c:v libx264 -preset faster -x264opts keyint=48:min-keyint=48:no-scenecut -strict -2 -r 24

In mp4fragment, I also used the parameter --fragment-duration 2000

deBilla commented 9 months ago

Issue should be due to GOP Misalignment Adding following options to ffmpeg command solved my issue -keyint_min 48 -g 48 -sc_threshold 0

What these do? -keyint_min 48: keyint represents the key frame (IDR frame) interval. This option limits the IDR frame interval to a minimum of 48 frames, which is the same length as the previously set GOP. -sc_threshold 0: Disable scene recognition, that is, disable automatic addition of IDR frames

maytham553 commented 4 months ago

Any solve ?