PDA

View Full Version : ffmpeg: -vsync 0 versus -r (frame rate)


i5mast
1st December 2011, 21:47
Are these two options mutually exclusive?

I have Office LiveMeeting presentation encoded in WMV3 and WMA. The video is about 1h long and it contains only static slides. There are a total of 151 key frames in WMV video. Some frames stay up for over one minute.

I'm using ffmpeg (v0.8.6)/libx264 to transcode the video to MP4.

ffmpeg -i "presentation.wmv" -acodec libfaac -ab 16k -vcodec libx264 -fpre "\ffmpeg-0.8.6\ffpresets\libx264-baseline.ffpreset" -profile main -s 480x360 -aspect 4:3 "presentation.mp4"

This gives me two issues when trying to play MP4 video.

1. Video does not sync up very well with audio. The slide may change a second or two earlier/sooner than expected.

2. The playback of MP4 video in a JWPlayer widget: I cannot advance the slider to fast forward or back, eg., the slider is jumping from 00:00 to 9:00 (nine minutes). I cannot advance to anything in between.

The issue #1 can be resolved with -vsync 0 option. The video and audio then sync up perfectly.

The issue #2 can be resolved -r 6 (setting fps to 6). If I don't set the frame rate then it ends up being 0.4.

Here comes my third issue: I cannot seem to use both of these options at the same time :( If I set vsync 0 then frame rate option is ignored and it ends up being 0.4 (which gives me issues with JWPlayer).

Are there any workarounds to both achieve higher fps than default 0.4 and to have audio and video in perfect sync?

I tried uploading the video to YouTube and they got it right. I downloaded the encoded video and then was able play/advance in JWPlayer, audio and video were synced up too.

Help :)

P.S. I do use qt-faststart to move "moov" atom to the beginning.

smok3
1st December 2011, 23:01
is your generated mp4 some sort of variable frame rate? does jwplayer/flash support such files? did you try forcing keyframe distance? http://mewiki.project357.com/wiki/X264_Settings#keyint

i5mast
2nd December 2011, 16:51
I didn't use anything special outside of ffmpeg baseline presets:

Here are the options:

[libx264 @ 01868520] 264 - core 118 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=0 keyint=250 keyint_min=6 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

did you try forcing keyframe distance?
what would be a reasonable setting for keyframe?

is your generated mp4 some sort of variable frame rate? does jwplayer/flash support such files?
I'm not sure how to answer these questions. Like I said, there are only 151 frames in the whole video. So yes, it should be a variable frame rate in that sense that one frame stays for 1 minute, second frame may stay for 15 seconds.

Btw, MP4 ends up with 0.04 fps if I don't specify -r 6.

b66pak
2nd December 2011, 17:55
use "-async 1" instead "-vsync 0" and "-r 23.976"...
_

i5mast
2nd December 2011, 21:41
use "-async 1" instead "-vsync 0" and "-r 23.976"...
"-async 1" and "-r 23.976" did not help with my syncing issues. However, what helped in my situation was a little bit of AviSynth

script.avs:
DirectShowSource("presentation.wmv", fps=6, ConvertFPS=True)

I think this created more frames and I generated a second WMV file.

ffmpeg -i "script.avs" -sameq "presentation2.wmv"

Then the final conversion gave me the desired result: FPS at 6 and a working seeking in JWPlayer.

ffmpeg -i "presentation2.wmv" -acodec libfaac -ab 16k -vcodec libx264 -fpre "\code\ffmpeg-0.8.6\ffpresets\libx264-baseline.ffpreset" -profile main -s 480x360 -aspect 4:3 "presentation.mp4"

:)

nm
3rd December 2011, 01:02
"-async 1" and "-r 23.976" did not help with my syncing issues.

Have you tried -vsync 1 -r 23.976 (or 6 or whatever rate)?

ffmpeg -i "script.avs" -sameq "presentation2.wmv"

This is not a good idea. You are re-encoding the video with FFmpeg's wmv2 encoder, which is bad compared to almost anything. Just encode using the AVS script as source in your final stage. That does the same thing.

Would you happen to have a sample clip that you could share with us?

Maccara
4th December 2011, 16:20
One thing that has worked for me with "problematic" VFR sources (flagged "interestingly" etc etc problems from one customer):

ffmpeg -fflags +genpts+igndts -i <input> <other encoding options> -r:v 30 -vsync 2 -async 1 -map 0:v,0:a -map 0:a <output.mp4>

That effectively tries to sync the video to the audio and drops frames to prevent frames with same pts, flags the stream as 30fps (was proper for this particular source, adjust to yours) and keeps it VFR still (i.e. does not output duplicate frames).

EDIT: using -vsync 1 will duplicate frames instead to reach the requested framerate, which seems to be what you want. Other options stay the same.

That's with a recent git version (there has been some syntax changes "recently", just using -r does not work anymore correctly without stream index specifier and -map syntax is completely different too). Also, this method didn't use to work so well with older ffmpeg anyway, so recent git master version suggested.

Hmm. I'm not sure if the -fflags actually do anything, so might want to omit that (or test it).

i5mast
5th December 2011, 23:39
Have you tried -vsync 1 -r 23.976 (or 6 or whatever rate)?

Yes, I've tried that. It didn't fix the issues with sync.

Would you happen to have a sample clip that you could share with us?
I'll have it for a limited time here: http://www.accordant.net/press/presentation.wmv
To see any sync issues, you have to watch from minute 5:00 to 6:00.

One thing that has worked for me with "problematic" VFR sources (flagged "interestingly" etc etc problems from one customer):

ffmpeg -fflags +genpts+igndts -i <input> <other encoding options> -r:v 30 -vsync 2 -async 1 -map 0:v,0:a -map 0:a <output.mp4>

I couldn't figure out the map command. It wouldn't work for me. WMV has audio as a first stream which I think was the issue.

Thank you for all of your suggestions.