Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
28th August 2018, 22:26 | #1 | Link | |
Registered User
Join Date: Nov 2015
Posts: 81
|
Audio and video out of sync after encoding
Hi everyone, so I have this 1080p 800MB video I want to encode to 720p 150MB, but no matter what I do, the final result is always out of sync (audio and video) and I think it has something to do with the weird framerate of the file and the FLAC audio.
Here's what MediaInfo shows: Quote:
Should I share with you the file or a sample of it? Thanks in advance! Last edited by tebasuna51; 29th August 2018 at 01:15. Reason: code -> quote |
|
29th August 2018, 01:19 | #3 | Link |
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,890
|
Of course is possible (the blue button at lower rigth, maybe you can see it now after my edit ).
About the sync, seems your video is: Frame rate mode : Variable Extract the timecodes from the original mkv (mkvextract) and load them into the recoded one (MkvToolNixGUI).
__________________
BeHappy, AviSynth audio transcoder. Last edited by tebasuna51; 29th August 2018 at 01:24. |
29th August 2018, 22:46 | #4 | Link |
Registered User
Join Date: Nov 2015
Posts: 81
|
It works, but I have 2 problems: my final result is an MP4 file, not MKV, is it possible to load the timecodes to an MP4 with MeGUI maybe?
I didn't mention it before, but I'm also hardsubbing a subtitle that I extracted from another MKV which framerate is 23.976, and now the hardsubbed subs are out of sync. I guess I have to edit somehow those subs because of the change in framerate or something like that. Is it possible? MKV "A" (23.976 FPS) --> I extracted subs MKV "B" (24.376 FPS) --> I want to encode to MP4 with those subs hardsubbed |
30th August 2018, 18:09 | #7 | Link |
Registered User
Join Date: Dec 2002
Posts: 5,565
|
Processing time is a function that is usually and for the most part dependent on video encoding time. If you use the same encoder (e.g. x264) and encoder settings you used in MeGUI you should get about the same overall processing time with HandBrake. If it's too slow use faster encoder preset or a faster encoder (e.g. x264 instead of x265, hardware instead of software).
|
30th August 2018, 18:38 | #8 | Link |
Registered User
Join Date: Nov 2015
Posts: 81
|
I realized that I used the "slower" preset, but in MeGUI I use the same with some modifications, does Handbrake allow you to edit the presets like MeGUI? So you have no idea how to make this all work WITH MG? Handbrake works fine but I'm used to MG.
|
30th August 2018, 20:32 | #9 | Link |
Registered User
Join Date: Dec 2002
Posts: 5,565
|
With MeGUI it's complicated because it's not build to be variable framerate aware. Easiest is to either force constant framerate in the AviSynth source filter or to copy timecodes from source to target file using mkvtoolnix (like tebasuna51 said).
About HandBrake: you can add extra x264 options in the "Extra Options" field in the ffmpeg style. E.g.: Code:
keyint=100:ref=3 Last edited by sneaker_ger; 30th August 2018 at 20:34. |
31st August 2018, 01:00 | #10 | Link | ||
Registered User
Join Date: Mar 2011
Posts: 4,823
|
Quote:
Simply extract the timecodes from your VFR MKV source and give them to the x264 encoder to play with. It's VFR aware. Just add something like the following to the custom command line section of the x264 encoder configuration. --tcfile-in "D:\Timecodes.txt" http://www.chaneru.com/Roku/HLS/X264....htm#tcfile-in (Anyone know if x265 has a similar option? I couldn't see anything in the help file) It works a treat when the output is MKV, but it mightn't be so simple when the desired output is MP4, as MeGUI only outputs a raw video stream and then muxes it into an MP4. Someone else might know if that's okay, otherwise.... You might have to output MKV and remux it as an MP4 with ffmpeg. I've not tried that process myself as I rarely work with MP4s. I think this is all the command line you need to remux an MKV as MP4 with ffmpeg. ffmpeg.exe -i MyVideo.mkv -y -vcodec copy -acodec copy "MyVideo.mp4" Quote:
Last edited by hello_hello; 31st August 2018 at 01:32. |
||
31st August 2018, 16:36 | #12 | Link |
Registered User
Join Date: Mar 2011
Posts: 4,823
|
I'm not sure why. If you're on a 64 bit Windows MeGUI is probably using avs4x26x.exe to send the video to the encoder, so maybe that's the problem. Some guesses:
It could be an avs4x26x.exe issue because it's not used on 32 bit Windows (I'm running XP), although when I ran a test, the encoder kept rejecting the timecodes file. Eventually I discovered it's not happy with "# timestamp format v2" at the top of the timecodes file. When I changed it to "# timecode format v2" it was accepted, so you probably should try that first. It seems MKVToolNix will accept timecodes with either heading, so maybe at some stage it was officially changed from "timecode" to "timestamp" to annoy everyone. If that doesn't help, remux your MKV while adding --timecode-scale -1 to the MKVToolNix command line. When you extract them, instead of looking like this: # timestamp format v2 0 40 80 They might look like this: # timestamp format v2 0 39.99744 79.99488 See if that helps. If you can get the encoder to accept the timecodes file you might have to specify a timebase manually. I don't fully understand how the timebase works, but as a test I fed the encoder timecodes from a CFR 23.976fps MKV (accurate to 1ms) and the result was: timecode [info]: automatic timebase generation 1/1000000000 So try adding --timebase 1/1000000000 to the custom command line along with the timecodes file if the encoder won't automatically generate one. Maybe someone who understands how the timebase works will come along and explain it. I'll confess I haven't used v2 timecodes that way for quite a while. I generally convert NTSC DVDs with TIVTC generating timecodes, and it uses the original format, which has never been a problem for me. # timecode format v1 Assume 54.940030 3735, 8034, 23.976024 8965, 9439, 23.976024 This *&*^ should be easy!!! That'll teach me for saying it is. Last edited by hello_hello; 31st August 2018 at 17:07. |
1st September 2018, 17:20 | #13 | Link |
Registered User
Join Date: Nov 2015
Posts: 81
|
I tried everything you said (that's why I didn't answer sooner) but I still get the same out of sync result. It's really frustrating, mainly because Handbrake has no problem with this and MeGUI (which I prefer) does.
I'm using Windows x64. At the top of the timecodes file says "timecode" not "timestamp" never the less, I tried change it but didn't work. I used the command "--timecode-scale -1" and I got new timecodes but didn't work. Finally I used the command "--timebase 1/1000000000" and it worked, MeGUI accepted it, but the result was out of sync. Again, why is so easy for Handbrake to deal with VFR? MeGUI should improve that. It's been long since it got any update. |
2nd September 2018, 21:00 | #14 | Link |
Registered User
Join Date: Mar 2011
Posts: 4,823
|
VFR is really up to the encoder. MeGUI is Avisynth based and Avisynth has no concept of VFR, so it feeds the encoder at the average frame rate, or some other constant frame rate, depending on the decoder, and the VFR part needs to be handled by the encoder via a timecodes file.
Aside from the timecode vs timestamp issue, it always works flawlessly for me. Is there a setting in Options to force the use of the 32 bit encoder? I kind of remember there being one, although I can't find it. Maybe it doesn't appear when MeGUI is running on 32 bit Windows, or maybe I just imagined it, but if it's there, try using the 32 bit encoder instead. I assume that'll bypass the need for avs4x26x.exe. Edit 1: I scanned through the changelog and it appears there's no longer an option to use the 32 bit x264. I'm not sure why. 2681 [x264] removed option to select 32bit x264 on a 64bit OS and merged the 8- and 10-bit packages Edit 2: Maybe try tctool-v1.3.44.7z from here. https://astrataro.wordpress.com/2012...r-avs4x264mod/ I gave it a spin and it'll convert between version 1 and version 2 timecodes, so maybe try converting your version 2 timecodes to version 1 to see if they'll be accepted, or even outputting a new version 2 timecodes file to see if doing that somehow magically fixes the problem. It's command line, but usage is pretty simple, with -v specifying the output timecodes version. It rejects timecodes with a "timestamp" heading. tctool.exe -v 1 "input_timecodes.txt" > "output_timecodes.txt" Other than that, when Zathor appears again maybe he'll be willing to look at the timecodes problem, because it should work. In the mean time, you might have to encode them at a CFR and mux the timecodes file into the output MKV, then remux as MP4. I think the only real advantage of encoding with a timecodes file is it allows x264 to distribute the quality a little more evenly, because it knows how long the frames will display. Or have you tried converting to CFR and encoding that way? Something like: LWLibavVideoSource("D:\Video.mkv", FPSNum=24000, FPSDen=1001) Or if it's jittery, which it sometimes is when the input and output frame rates are very similar, try converting to a higher frame rate and then decimating. LWLibavVideoSource("D:\Video.mkv", FPSNum=30000, FPSDen=1001) TDecimate() Last edited by hello_hello; 2nd September 2018 at 21:55. |
8th May 2019, 23:08 | #15 | Link | |
Registered User
Join Date: Jul 2012
Posts: 6
|
We've been experiencing a sync issue more and more frequently, and I'm wondering if what is discussed in this thread is applicable to the latest instance.
Just for background, we encode DCPs for use in cinemas (pre-show entertainment and ads, basically). This by definition involves splitting audio and video from our source files and re-encoding them into separate MXF files, with additional XML files governing playback. 99% of the time picture and sound are the same duration, with no sync issues. Lately, we're getting picture and sound of the same duration, but out of sync, which seems weird. When I examine the source files, there doesn't appear to be any additional timecode "channel" which would explain why the source plays fine, but not any resulting re-encode. And then there's cases like this: Quote:
Needless to say, the resulting DCP has sync issues; it starts in sync and slowly drifts. Would a Handbrake re-encode help with this? Finally, for the cases where clearly the file contains special timecode instructions (like "start video at frame 0, audio at frame 4...") what program could I use to actually see what the instructions are? MediaInfo, as stated, will tell us that a timecode channel is present, but gives no details, no content. Thanks in advance for any help. Last edited by tebasuna51; 9th May 2019 at 01:09. |
|
9th May 2019, 01:53 | #16 | Link |
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,890
|
Video Frame = 1 image
Video Frame Rate = Number of images to show in 1 second. A video with Constant Frame Rate 23.976 show a frame 41708333 ns When a video have a Variable Frame Rate there are a different time to show each image. You can obtain the info in a txt file from a mkv with: mkvextract "input.mkv" timestamps_v2 0:"Video_times.txt" Audio Frame = A set of audio Samples encoded together, for instance for AAC 1024 Samples Per Frame (SPF). Audio Sample Rate = the number of audio Samples to play in 1 second (here 48000) Audio Frame Rate is not relevant for audio and not related at all with Video Frame Rate. The equivalent for Video Frame Rate is the Audio Sample Rate. The Audio Sample Rate can't be variable and any control by timestamps of the audio can produce audio clicks and must be avoided.
__________________
BeHappy, AviSynth audio transcoder. |
9th May 2019, 19:46 | #17 | Link | |
Registered User
Join Date: Jul 2012
Posts: 6
|
Quote:
|
|
10th May 2019, 11:53 | #18 | Link |
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,890
|
I can't help you with MOV's QT 422/4444 files. Use Quick Time software to manage this proprietary container format.
For MP4 there are mp4fpsmod to manage timestamps (timecodes): mp4fpsmod -p "timecodes.txt" "input.mp4" Output current timecodes into timecode-v2 format. mp4fpsmod -o "new.mp4" -t "timecodes.txt" "old.mp4" Insert timecodes with timecode-v2 file.
__________________
BeHappy, AviSynth audio transcoder. Last edited by tebasuna51; 10th May 2019 at 11:56. |
Tags |
megui, mp4 audio, out-of-sync |
Thread Tools | Search this Thread |
Display Modes | |
|
|