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, 22:26   #1  |  Link
doomleox999
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:
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 01:15. Reason: code -> quote
doomleox999 is offline   Reply With Quote
Old 28th August 2018, 22:30   #2  |  Link
doomleox999
Registered User
 
Join Date: Nov 2015
Posts: 81
Non-related question: is it not possible to edit my own thread anymore?
doomleox999 is offline   Reply With Quote
Old 29th August 2018, 01:19   #3  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
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.
tebasuna51 is offline   Reply With Quote
Old 29th August 2018, 22:46   #4  |  Link
doomleox999
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
doomleox999 is offline   Reply With Quote
Old 29th August 2018, 23:33   #5  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
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, 18:04   #6  |  Link
doomleox999
Registered User
 
Join Date: Nov 2015
Posts: 81
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, 18:09   #7  |  Link
sneaker_ger
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).
sneaker_ger is offline   Reply With Quote
Old 30th August 2018, 18:38   #8  |  Link
doomleox999
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.
doomleox999 is offline   Reply With Quote
Old 30th August 2018, 20:32   #9  |  Link
sneaker_ger
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
https://trac.ffmpeg.org/wiki/Encode/...presetsettings

Last edited by sneaker_ger; 30th August 2018 at 20:34.
sneaker_ger is offline   Reply With Quote
Old 31st August 2018, 01:00   #10  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,823
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 01:32.
hello_hello is offline   Reply With Quote
Old 31st August 2018, 11:53   #11  |  Link
doomleox999
Registered User
 
Join Date: Nov 2015
Posts: 81
I'm getting this error no matter what output I choose (MKV - MP4):

doomleox999 is offline   Reply With Quote
Old 31st August 2018, 16:36   #12  |  Link
hello_hello
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.
hello_hello is offline   Reply With Quote
Old 1st September 2018, 17:20   #13  |  Link
doomleox999
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.
doomleox999 is offline   Reply With Quote
Old 2nd September 2018, 21:00   #14  |  Link
hello_hello
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.
hello_hello is offline   Reply With Quote
Old 8th May 2019, 23:08   #15  |  Link
HDVProjection
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:
Format : MPEG-4
Format profile : Base Media / Version 2
Codec ID : mp42 (mp42/mp41/isom/avc1)
File size : 25.9 MiB
Duration : 43 s 882 ms
Overall bit rate mode : Variable
Overall bit rate : 4 956 kb/s
Encoded date : UTC 2019-04-19 16:36:16
Tagged date : UTC 2019-04-19 16:36:16

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4
Format settings : CABAC / 5 Ref Frames
Format settings, CABAC : Yes
Format settings, ReFrames : 5 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 43 s 877 ms
Bit rate : 4 816 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.097
Stream size : 25.2 MiB (97%)
Writing library : x264 core 157 r10 d4099dd
Encoding settings : cabac=1 / ref=5 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=8 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=34 / lookahead_threads=5 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / stitchable=1 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=2 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=infinite / keyint_min=23 / scenecut=40 / intra_refresh=0 / rc_lookahead=50 / rc=crf / mbtree=1 / crf=20.0 / qcomp=0.60 / qpmin=5 / qpmax=69 / qpstep=4 / vbv_maxrate=5500 / vbv_bufsize=15000 / crf_max=0.0 / nal_hrd=none / filler=0 / ip_ratio=1.40 / aq=1:1.00
Encoded date : UTC 2019-04-19 16:36:16
Tagged date : UTC 2019-04-19 16:36:16
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709
Codec configuration box : avcC

Audio
ID : 2
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 43 s 882 ms
Bit rate mode : Variable
Bit rate : 137 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 734 KiB (3%)
Encoded date : UTC 2019-04-19 16:36:16
Tagged date : UTC 2019-04-19 16:36:16
I don't understand how the framerates of audio and video on the same file can be so drastically different. I find it particularly odd that the audio framerate isn't exactly double the video FPS. For whatever reason, my brain could somehow get around it if it was a nice round number.

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.
HDVProjection is offline   Reply With Quote
Old 9th May 2019, 01:53   #16  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
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.
tebasuna51 is offline   Reply With Quote
Old 9th May 2019, 19:46   #17  |  Link
HDVProjection
Registered User
 
Join Date: Jul 2012
Posts: 6
Quote:
Originally Posted by tebasuna51 View Post
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.
What about for MOVs? 99% of the time we are receiving QT 422/4444 files. The rest of the time it's MP4.
HDVProjection is offline   Reply With Quote
Old 10th May 2019, 11:53   #18  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
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.
tebasuna51 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 20:14.


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