Log in

View Full Version : Weird Encoding Results


doomleox999
5th November 2017, 09:53
Hi everyone, I'm having trouble with some files I want to encode with MeGUI. The thing is that the results' duration has 10 extra seconds and the audio is out of sync. I suspect the unusual frame rate (23.810 FPS) has something to do but I'm no expert.

I put here relevant data that MediaInfo tells me about one of the original files and after that the data of the encoded one.

ORIGINAL FILE

Format : Matroska
Format version : Version 4 / Version 2
File size : 325 MiB
Duration : 23 min 51 s
Overall bit rate : 1 906 kb/s
Encoded date : UTC 2010-02-22 21:41:29

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4
Format settings : CABAC / 6 Ref Frames
Format settings, CABAC : Yes
Format settings, RefFrames : 6 frames
Codec ID : V_MPEG4/ISO/AVC
Duration : 23 min 50 s
Nominal bit rate : 1 776 kb/s
Width : 1 280 pixels
Height : 720 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.810 FPS
Original frame rate : 23.976 (23976/1000) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.081
Writing library : x264 core 120 r2120 0c7dab9
Encoding settings : cabac=1 / ref=6 / deblock=1:1:1 / analyse=0x3:0x113 / me=umh / subme=8 / psy=1 / psy_rd=0.40:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=4 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=2 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=23 / scenecut=40 / intra_refresh=0 / rc_lookahead=50 / rc=2pass / mbtree=1 / bitrate=1776 / ratetol=1.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / vbv_maxrate=3552 / vbv_bufsize=8880 / nal_hrd=none / ip_ratio=1.40 / aq=1:0.60
Default : Yes
Forced : No
FromStats_BitRate : 1774771
FromStats_Duration : 00:23:50.138000000
FromStats_FrameCount : 34290
FromStats_StreamSize : 317271038

Audio
ID : 2
Format : AAC
Format/Info : Advanced Audio Codec
Format profile : LC
Codec ID : A_AAC-2
Duration : 23 min 51 s
Channel(s) : 2 channels
Channel positions : Front: L R
Sampling rate : 44.1 kHz
Frame rate : 43.066 FPS (1024 SPF)
Compression mode : Lossy
Default : Yes
Forced : No
FromStats_BitRate : 127999
FromStats_Duration : 00:23:50.303000000
FromStats_FrameCount : 61598
FromStats_StreamSize : 22884844


ENCODED FILE

Format : MPEG-4
Format profile : Base Media
Codec ID : isom (isom/avc1)
File size : 151 MiB
Duration : 24 min 0 s
Overall bit rate mode : Variable
Overall bit rate : 877 kb/s

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4
Format settings : CABAC / 6 Ref Frames
Format settings, CABAC : Yes
Format settings, RefFrames : 6 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 24 min 0 s
Bit rate : 809 kb/s
Maximum bit rate : 8 061 kb/s
Width : 1 280 pixels
Height : 720 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.810 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.037
Stream size : 139 MiB (92%)
Writing library : x264 core 152 r2851 ba24899
Encoding settings : cabac=1 / ref=6 / deblock=1:1:1 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=0.40:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=3 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=5 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=238 / keyint_min=23 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=2pass / mbtree=1 / bitrate=809 / ratetol=1.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / aq=1:0.60

Audio
ID : 2
Format : AAC
Format/Info : Advanced Audio Codec
Format profile : HE-AAC / LC
Format settings : Explicit
Codec ID : mp4a-40-2
Duration : 23 min 50 s
Bit rate mode : Variable
Bit rate : 64.7 kb/s
Maximum bit rate : 83.0 kb/s
Channel(s) : 2 channels
Channel positions : Front: L R
Sampling rate : 44.1 kHz / 22.05 kHz
Frame rate : 21.533 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 11.0 MiB (7%)


Please let me know if you need more information.

Thanks in advance!

tebasuna51
5th November 2017, 14:26
Relevant data from source:

Frame rate mode : Constant
Frame rate : 23.810 FPS
Original frame rate : 23.976 (23976/1000) FPS
FromStats_Duration : 00:23:50.138
FromStats_FrameCount : 34290

Duration at 23.810 fps = 34290 / 23.81 = 1466,610667 sec = 24:26.611
Duration at 23.976 fps = 34920 / 23.976 = 1456,455 sec = 24:16.455

None of them match the correct duration 23:50.138
If source play in sync can be only if real frame rate mode is variable (VFR).

You can extract the video timestamps from source and remux the encodec file with the same timestamps.

doomleox999
6th November 2017, 03:37
You can extract the video timestamps from source and remux the encodec file with the same timestamps.

How can I do that?

tebasuna51
6th November 2017, 14:27
You need mkvextract.exe (already in MeGUI package) and mp4fpsmod.exe like seems your ENCODED file is a mp4.

Download and extract in a new folder mp4fpsmod_0.25.zip (https://sites.google.com/site/qaacpage/cabinet)

At same folder put your ORIGINAL.mkv, your ENCODED.mp4 and a .bat file with this content:

rem modify path to mkvextract
"D:\Programa\megui\tools\mkvmerge\mkvextract.exe" timecodes_v2 "ORIGINAL.mkv" 0:"timecodes.txt"
mp4fpsmod -t timecodes.txt -x -c "ENCODED.mp4" -o "SYNC.mp4"
pause

Remember modify the path to your MeGUI folder.
Execute the bat file and verify if SYNC.mp4 is in sync.
I don't have now a VFR file to test myself.

imsrk48
6th November 2017, 18:53
Meet me on personal

Sent from my P4 using Tapatalk

doomleox999
7th November 2017, 06:56
You need mkvextract.exe (already in MeGUI package) and mp4fpsmod.exe like seems your ENCODED file is a mp4.

Download and extract in a new folder mp4fpsmod_0.25.zip (https://sites.google.com/site/qaacpage/cabinet)

At same folder put your ORIGINAL.mkv, your ENCODED.mp4 and a .bat file with this content:



Remember modify the path to your MeGUI folder.
Execute the bat file and verify if SYNC.mp4 is in sync.
I don't have now a VFR file to test myself.


I only got a timecodes.txt file, not a SYNC.mp4.

"Timecode is not monotone increasing! at line 3"

Does that mean anything?

tebasuna51
7th November 2017, 10:34
Attach the timecodes.txt to analyze it.

doomleox999
7th November 2017, 11:04
Attach the timecodes.txt to analyze it.

timecodes.txt (http://m.uploadedit.com/bbtc/1510048968892.txt)

tebasuna51
7th November 2017, 14:48
Relevant data from source:

Duration at 23.810 fps = 34290 / 23.81 = 1466,610667 sec = 24:26.611
Duration at 23.976 fps = 34920 / 23.976 = 1456,455 sec = 24:16.455

Sorry, my fault. The correct value is:

Duration at 23.976 fps = 34290 / 23.976 = 1430,17875 sec = 23:50.178

Than match, with a frame of difference, with:
FromStats_Duration : 00:23:50.138

That diference and the error than show mp4fpsmod ("Timecode is not monotone increasing! at line 3") is because the wrong timecode of second frame:
# timecode format v2
0
0
42
...

you can replace the second 0 with 21

# timecode format v2
0
21
42
...

and

mp4fpsmod -t timecodes.txt -x -c "ENCODED.mp4" -o "SYNC.mp4"

doomleox999
7th November 2017, 17:41
Sorry, my fault. The correct value is:

Duration at 23.976 fps = 34290 / 23.976 = 1430,17875 sec = 23:50.178

Than match, with a frame of difference, with:
FromStats_Duration : 00:23:50.138

That diference and the error than show mp4fpsmod ("Timecode is not monotone increasing! at line 3") is because the wrong timecode of second frame:


you can replace the second 0 with 21



and

mp4fpsmod -t timecodes.txt -x -c "ENCODED.mp4" -o "SYNC.mp4"

Wow! It worked! Thatīs awesome! Thanks man!!

However, I have a few final questions:

Why does this happen? Is the problem is the source?

Is there any way to prevent this when I encode with MeGUI or do I have to do all these steps everytime I encounter this issue?

Finally, is it possible to batch this? (meaning to extract timecodes from multiple original files to multiple encoded files and remux multiple "SYNC.mp4" files)

tebasuna51
7th November 2017, 22:55
Why does this happen? Is the problem is the source?

The source have two problems:

- That second absurd timecode.
- The wrong Frame rate : 23.810 FPS, witouth sense.

with a standard framerate 23.976 the movie play with a little delay (41 ms) and can be unnoticeable.

Is there any way to prevent this when I encode with MeGUI or do I have to do all these steps everytime I encounter this issue?

That process (extract and insert timecodes) is only recommended for Variable FrameRate sources.

If MediaInfo show: Frame rate mode : Constant
we can't expect troubles.

But when encode I always use in avs script a Assumefps(24000,1001) or Assumefps(24) or Assumefps(25) or Assumefps(30000,1001), never let non-standard fps because most the times are wrong, like here.

Finally, is it possible to batch this? (meaning to extract timecodes from multiple original files to multiple encoded files and remux multiple "SYNC.mp4" files)

If the name or mkv's and mp4's are the same:

movie_01.mkv, movie_02.mkv, ...
movie_01.mp4, movie_02.mp4, ...

You can use:

rem modify path to mkvextract
FOR %%I IN (*.mkv) DO "D:\Programa\megui\tools\mkvmerge\mkvextract.exe" timecodes_v2 "%%I" 0:"%%~nI.txt"
FOR %%I IN (*.mkv) DO mp4fpsmod -t "%%~nI.txt" -x -c ""%%~nI.mp4" -o ""%%~nI_SYNC.mp4"
pause

doomleox999
7th November 2017, 23:55
The source have two problems:

- That second absurd timecode.
- The wrong Frame rate : 23.810 FPS, witouth sense.

with a standard framerate 23.976 the movie play with a little delay (41 ms) and can be unnoticeable.



That process (extract and insert timecodes) is only recommended for Variable FrameRate sources.

If MediaInfo show: Frame rate mode : Constant
we can't expect troubles.

But when encode I always use in avs script a Assumefps(24000,1001) or Assumefps(24) or Assumefps(25) or Assumefps(30000,1001), never let non-standard fps because most the times are wrong, like here.



If the name or mkv's and mp4's are the same:

movie_01.mkv, movie_02.mkv, ...
movie_01.mp4, movie_02.mp4, ...

You can use:

Thanks man, I learnt a lot from your answers.

I'll be mindful of everything you told me from now on and I'll try the batch bat as soon as I can.

Thanks for everything!