oh god. I thought every social media was breaking my audio when uploaded, but no, they're transcoding my mp4 into a perfectly sync'd mp4.

which firefox/their video player then plays out of sync.

I feel like less shit for making a video that played wrong, I thought I fucked up the sync.

but now I have zero idea how to fix this

yeah, it's not tumblr that's fucking this, I made my own HTML that was just <title>VIDEO</title><video width="320" height="240" controls><source src="video.mp4" type="video/mp4"></video> and it still plays out of sync in firefox

ahh, if I convert the video to webm with handbrake, it burns the audio de-sync into the file.

but if I convert it to mp4, I get a mp4 that plays correct in VLC and chrome, but not firefox.

weird.

I think this is handbrake/ffmpeg doing something VERY weird when converting it to mp4
@foone I bet @lisamelton would know.

@nygl @foone Sounds to me like the problem is Firefox if that’s the only player that plays the audio out of sync. Have you tried playback with a different Web browser?

Also, both FFmpeg and HandBrake are very good at keeping audio in sync. So I doubt they are to blame.

@foone how did you create the original video? I've seen stuff like this if you try to trim the beginning of a video while using -vcodec copy. You'll often end up with a few broken frames at the beginning because it starts on an i-frame rather than a keyframe.

If so, maybe it's dropping those frames when it transcodes and throwing it out of sync.

@mcgrew it was generated by ffmpeg in the first place, with an audio track added in using avidemux I think.
@foone well it was a thought. Not sure what else could cause it but ffmpeg is weird like that sometimes.

@mcgrew @foone not sure if related but: i had an a/v desync problem with ffmpeg-trimmed videos after uploading to instagram stories (yeah i know, still have to be there for reasons) which otherwise played okay in vlc etc.

-force_key_frames "00:00:00.000" seemed to fix that for me, at least with test reuploads of same videos but with this added to the final ffmpeg prompt. hadn't tested in a browser player though.

@grischa808 @foone I didn't know about that option. That actually could be helpful in one of my projects - I'll have to try it.
@mcgrew @foone had no idea either, until last month. turns out it can also populate the video with keyframes at a specified interval (e.g. for more precise seeking in a player) but in this case i figured it would sort of help initialize a/v sync with the extra keyframe at zero (if i get the idea correctly). needs more testing anyway.
@foone as if the whole process weren't very weird to start with.
@foone webm if you don't override settings uses vp9 for video, mp4 uses h264 so it's very likely you don't have accelerated h264 playback set up correctly. edit: double checked to be sure, looks like more recent versions of firefox use the OpenH264 plugin from cisco by default now which calls libva/libvaapi directly for your video card to accelerate decoding.
@raptor85 the thing is, I can play other mp4s in firefox just fine and they don't desync. so it's something with my video
@foone what codecs are the audio/video in the other mp4s? mp4 is just the container format, vp9/opus is more or less web standard but that's not default in ffmpeg when encoding, and mp4+vp9/opus videos will play directly, they don't need the additional plugin like h264 does.
@raptor85 h264/aac mp4, I'm comparing apples to apples here
@foone hmm, maybe check the framerate on the source file and the output mp4, could have something screwy going on there, I know openh264 has had issues with defaulting to 25fps in the past when it can't properly read that info
@foone one thing that usually helps is to run video through handbrake and use vlc to view to check. then host it somewhere to check via browser

@foone holy crow I've seen this

didn't care enough to dig but I have seen this. I have a lot of bullshit in my installation (which is, to be clear, a strongly net good, my internet experience is very unlike stock) and I just assumed it was some other damn piece of fallout from all my bullshit but if you're reproing in a really simple case

YEAH okay doesn't matter really BUT I can confirm I've seen this too, so there's that

@foone so that depends on how it's encoded. For ... reasons... mp4 files have like 3 different time sources in the file. So when tumblr "fixes" your sync they might be adjusting one of these out of sync with the others, making it work on some systems and breaking on others depending on exactly how they use the multiple timecodes.

source: tried to play a Disney DVD with my own software, fixed the software to make it work

@foone what codec? firefox uses your system libs for playback, you could have something failing to load in libva/libvaapi and falling back to software which if it can't keep up can lag behind during playback.
@raptor85 looks like handbrake is outputting h264 mpeg-4 AVC part 10 "avc1", with AAC audio at 48khz