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.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 Encoder GUIs

Reply
 
Thread Tools Search this Thread Display Modes
Old 28th August 2018, 23:26   #1  |  Link
doomleox999
Registered User
 
Join Date: Nov 2015
Posts: 78
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:
General
Unique ID : 178136575921514182527058359694120503115 (0x8603DB488CF90598AC0D2428ABDCC74B)
Complete name : C:\Users\LTX\Desktop\FSN EAS 01.mkv
Format : Matroska
Format version : Version 2
File size : 839 MiB
Duration : 24 min 12 s
Overall bit rate mode : Variable
Overall bit rate : 4 847 kb/s
Encoded date : UTC 2012-05-20 00:47:02
Writing application : mkvmerge v5.4.0 ('Piper') built on Mar 10 2012 13:34:39
Writing library : libebml v1.2.3 + libmatroska v1.3.0

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L5
Format settings : CABAC / 5 Ref Frames
Format settings, CABAC : Yes
Format settings, ReFrames : 5 frames
Format settings, GOP : N=1
Muxing mode : Header stripping
Codec ID : V_MPEG4/ISO/AVC
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Variable
Original frame rate : 24.376 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Title : AVC
Writing library : x264 core 67 r1145 d2e1e1c
Encoding settings : cabac=1 / ref=5 / deblock=1:0:0 / analyse=0x3:0x133 / me=umh / subme=7 / psy_rd=1.0:0.0 / mixed_ref=1 / me_range=18 / chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 / chroma_qp_offset=-2 / threads=6 / nr=0 / decimate=1 / mbaff=0 / bframes=3 / b_pyramid=1 / b_adapt=2 / b_bias=0 / direct=1 / wpredb=1 / keyint=250 / keyint_min=25 / scenecut=75 / rc=cqp / qp=17 / ip_ratio=1.40 / pb_ratio=1.30 / aq=0
Language : Japanese
Default : Yes
Forced : No

Audio
ID : 2
Format : FLAC
Format/Info : Free Lossless Audio Codec
Codec ID : A_FLAC
Duration : 24 min 12 s
Bit rate mode : Variable
Channel(s) : 2 channels
Channel positions : Front: L R
Sampling rate : 48.0 kHz
Bit depth : 16 bits
Title : FLAC
Writing library : libFLAC 1.2.1 (UTC 2007-09-17)
Language : Japanese
Default : Yes
Forced : No

Text
ID : 3
Format : ASS
Codec ID : S_TEXT/ASS
Codec ID/Info : Advanced Sub Station Alpha
Compression mode : Lossless
Default : Yes
Forced : No

Should I share with you the file or a sample of it?

Thanks in advance!

Last edited by tebasuna51; 29th August 2018 at 02:15. Reason: code -> quote
doomleox999 is offline   Reply With Quote
Old 28th August 2018, 23:30   #2  |  Link
doomleox999
Registered User
 
Join Date: Nov 2015
Posts: 78
Non-related question: is it not possible to edit my own thread anymore?
doomleox999 is offline   Reply With Quote
Old 29th August 2018, 02:19   #3  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 5,473
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, in Doom9 forums. NicAudio, BassAudio, audio decoders.

Last edited by tebasuna51; 29th August 2018 at 02:24.
tebasuna51 is offline   Reply With Quote
Old 29th August 2018, 23:46   #4  |  Link
doomleox999
Registered User
 
Join Date: Nov 2015
Posts: 78
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
doomleox999 is offline   Reply With Quote
Old 30th August 2018, 00:33   #5  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,263
1. Mux subtitles into file using mkvtoolnix
2. Load mkv from step 1 into HandBrake, set subtitle track to "burn-in" and encode to mp4

HandBrake can handle variable framerate.
sneaker_ger is offline   Reply With Quote
Old 30th August 2018, 19:04   #6  |  Link
doomleox999
Registered User
 
Join Date: Nov 2015
Posts: 78
Quote:
Originally Posted by sneaker_ger View Post
1. Mux subtitles into file using mkvtoolnix
2. Load mkv from step 1 into HandBrake, set subtitle track to "burn-in" and encode to mp4

HandBrake can handle variable framerate.
This works amazingly, audio, video and subs are sync, but it's slower than MeGUI, it takes almost double the time to encode. Is there any way to achieve this same result but using MeGUI?
doomleox999 is offline   Reply With Quote
Old 30th August 2018, 19:09   #7  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,263
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).
sneaker_ger is offline   Reply With Quote
Old 30th August 2018, 19:38   #8  |  Link
doomleox999
Registered User
 
Join Date: Nov 2015
Posts: 78
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.
doomleox999 is offline   Reply With Quote
Old 30th August 2018, 21:32   #9  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,263
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
https://trac.ffmpeg.org/wiki/Encode/...presetsettings

Last edited by sneaker_ger; 30th August 2018 at 21:34.
sneaker_ger is offline   Reply With Quote
Old 31st August 2018, 02:00   #10  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 3,821
Quote:
Originally Posted by doomleox999 View Post
This works amazingly, audio, video and subs are sync, but it's slower than MeGUI, it takes almost double the time to encode. Is there any way to achieve this same result but using MeGUI?
You can encode as VFR easily enough with MeGUI, although an MP4 output might be a bit of a speed bump.

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:
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?
Subtitle Edit can time-stretch subtitles.

Last edited by hello_hello; 31st August 2018 at 02:32.
hello_hello is offline   Reply With Quote
Old 31st August 2018, 12:53   #11  |  Link
doomleox999
Registered User
 
Join Date: Nov 2015
Posts: 78
I'm getting this error no matter what output I choose (MKV - MP4):

doomleox999 is offline   Reply With Quote
Old 31st August 2018, 17:36   #12  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 3,821
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 18:07.
hello_hello is offline   Reply With Quote
Old 1st September 2018, 18:20   #13  |  Link
doomleox999
Registered User
 
Join Date: Nov 2015
Posts: 78
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.
doomleox999 is offline   Reply With Quote
Old 2nd September 2018, 22:00   #14  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 3,821
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 22:55.
hello_hello is offline   Reply With Quote
Reply

Tags
megui, mp4 audio, out-of-sync

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 22:01.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.