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 > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 19th May 2019, 18:10   #1  |  Link
Nematocyst
Registered User
 
Join Date: May 2004
Location: Albuquerque, NM
Posts: 78
audio sync & AR problem.

Hi, I'm unable to use vapoursynth because I get two problems. I've not been successful getting audio muxed into the final encode without a progressive sync problem. I don't think it's a strictly mux problem because I've muxed various ways and get the exact same behavior. Also, using vapoursynth, I'm forced to do a resize to get the correct AR, which using ffmpeg is unnecessary. What's causing this?

vapoursynth script:
Quote:
from vapoursynth import core
video = core.ffms2.Source(source='<foo.mkv>')

# just use a small bit for filter testing
#video = video[0:1800]

# dot-crawl/rainbow elimination
#video = core.tcomb.TComb(video)

# deinterlace
video = core.tdm.TDeintMod(video, 1)

# denoise

# crop
video = core.std.CropAbs(video,704,464,6,10)
video = core.resize.Bicubic(video, 720, 540)

video.set_output()
and finish up with this cmdline followed by audio mux:
Quote:
vspipe --y4m <foo.vpy> - | ffmpeg -i pipe: -c:v libx265 -preset veryslow -crf 20 -vf "nlmeans=s=10" -y "outfoo.mkv"


ffmpeg commandline that works fine, but lacks comb filter
Quote:
VCODEC="-c:v libx265 -preset veryslow -crf 20"
FCHAIN='-vf "yadif,nlmeans=s=10,crop=704:464:6:10"'

ffmpeg -i "<foo.mkv>" $VCODEC -c:a copy $FCHAIN -y "<outfoo.mkv>"
[edit]
extra info regarding AR problem. If I use the vapoursynth script above, commenting out the crop+resize and issue this command:
Quote:
vspipe --y4m <foo.vpy> - | ffplay -i pipe:
I get the wrong AR compared to just:
Quote:
ffplay -i <foo.mkv>
and this output from the vpy script on the cmdline:
Quote:
Input #0, yuv4mpegpipe, from 'pipe:':B vq= 0KB sq= 0B f=0/0
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p(progressive), 720x540, 29.64 fps, 29.64 tbr, 29.64 tbn, 29.64 tbc
^C 2.87 M-V: -0.033 fd= 1 aq= 0KB vq=15380KB sq= 0B f=0/0
I don't really understand what it's telling me, but I'm guessing the pipe causes some kind of loss of stream info that the player needs to show it properly.

Last edited by Nematocyst; 19th May 2019 at 18:47.
Nematocyst is offline   Reply With Quote
Old 19th May 2019, 18:56   #2  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,383
If you dumb everything down to
Code:
from vapoursynth import core
video = core.ffms2.Source(source='foo.mkv')
video.set_output()
Code:
vspipe --y4m "foo.vpy" - | ffmpeg -i pipe: -c:v libx264 -preset ultrafast -y "outfoovideo.mkv"
ffmpeg -i "outfoovideo.mkv" -i "foo.mkv" -map 0:v -map 1:a -c copy "outfoo.mkv"
do you still have sync issues?
sneaker_ger is offline   Reply With Quote
Old 19th May 2019, 19:15   #3  |  Link
ChaosKing
Registered User
 
Join Date: Dec 2005
Location: Germany
Posts: 869
29.64 fps looks suspicious, maybe it has VFR?
ChaosKing is offline   Reply With Quote
Old 19th May 2019, 19:19   #4  |  Link
Nematocyst
Registered User
 
Join Date: May 2004
Location: Albuquerque, NM
Posts: 78
Quote:
Originally Posted by sneaker_ger View Post
If you dumb everything down to
Code:
from vapoursynth import core
video = core.ffms2.Source(source='foo.mkv')
video.set_output()
Code:
vspipe --y4m "foo.vpy" - | ffmpeg -i pipe: -c:v libx264 -preset ultrafast -y "outfoovideo.mkv"
ffmpeg -i "outfoovideo.mkv" -i "foo.mkv" -map 0:v -map 1:a -c copy "outfoo.mkv"
do you still have sync issues?
great question. yes, same exact audio problem.
Nematocyst is offline   Reply With Quote
Old 19th May 2019, 19:25   #5  |  Link
Nematocyst
Registered User
 
Join Date: May 2004
Location: Albuquerque, NM
Posts: 78
Quote:
Originally Posted by ChaosKing View Post
29.64 fps looks suspicious, maybe it has VFR?
MIght be the issue. the source is a title_00x.mkv created with makemkv. vlc's codec info shows it as 29.970030. opening the encoded video in vlc shows it as 29.637534. This is the intermediate file [no audio] from the dumbed down script suggested by sneaker_ger.
Nematocyst is offline   Reply With Quote
Old 19th May 2019, 20:00   #6  |  Link
Nematocyst
Registered User
 
Join Date: May 2004
Location: Albuquerque, NM
Posts: 78
Still don't really understand the issue, but maybe the pipe is causing both problems?

Because of warnings about finding stuff when compiling vapoursynth, I use this script for vspipe. Doesn't seem like it should cause problems. but I'm at a loss.
Quote:
#!/bin/sh
PYTHONPATH="/usr/local/lib/python3.5/site-packages/" LD_LIBRARY_PATH="/usr/local/lib" /usr/local/bin/vspipe $@
Here's the ffmpeg output when creating the intermediate file:
Quote:
eric@hiarcs:~/Desktop$ !2020
vspipe --y4m "foo.vpy" - | ffmpeg -i pipe: -c:v libx264 -preset ultrafast -y "outfoovideo.mkv"
ffmpeg version 3.3.9 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --disable-decoder=amrnb --disable-decoder=libopenjpeg --disable-mips32r2 --disable-mips32r6 --disable-mips64r6 --disable-mipsdsp --disable-mipsdspr2 --disable-mipsfpu --disable-msa --disable-libopencv --disable-podpages --disable-stripping --enable-avfilter --enable-avresample --enable-gcrypt --enable-gnutls --enable-gpl --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libilbc --enable-libkvazaar --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx265 --enable-libxvid --enable-libzvbi --enable-nonfree --enable-opengl --enable-openssl --enable-postproc --enable-pthreads --enable-shared --enable-version3 --incdir=/usr/include/x86_64-linux-gnu --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --toolchain=hardened --enable-frei0r --enable-chromaprint --enable-libx264 --enable-libiec61883 --enable-libdc1394 --enable-vaapi --disable-opencl --enable-libmfx --disable-altivec --shlibdir=/usr/lib/x86_64-linux-gnu
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, yuv4mpegpipe, from 'pipe:':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p(progressive), 720x480, 29.64 fps, 29.64 tbr, 29.64 tbn, 29.64 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
[libx264 @ 0x563cdd535460] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.1 Cache64
[libx264 @ 0x563cdd535460] profile Constrained Baseline, level 3.0
[libx264 @ 0x563cdd535460] 264 - core 150 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, matroska, to 'outfoovideo.mkv':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 720x480, q=-1--1, 29.64 fps, 1k tbn, 29.64 tbc
Metadata:
encoder : Lavc57.89.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
^Z
[1]+ Stopped vspipe --y4m "foo.vpy" - | ffmpeg -i pipe: -c:v libx264 -preset ultrafast -y "outfoovideo.mkv"

Last edited by Nematocyst; 19th May 2019 at 20:15. Reason: include ffmpeg output
Nematocyst is offline   Reply With Quote
Old 19th May 2019, 21:09   #7  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,129
If the problem is vfr, you should be able to extract the time code from the video.
lansing is offline   Reply With Quote
Old 20th May 2019, 17:58   #8  |  Link
Lypheo
Registered User
 
Join Date: Sep 2018
Posts: 4
You need to write the timecodes to a file and then mux them into the video.

Code:
vspipe --y4m <foo.vpy> --timecodes timecodes.txt - | ffmpeg -i pipe: -c:v libx265 -preset veryslow -crf 20 -vf "nlmeans=s=10" -y "outfoo.mkv"
Then:

Code:
mkvmerge --output finalfoo.mkv --timestamps 0:timecodes.txt outfoo.mkv
Lypheo is offline   Reply With Quote
Old 20th May 2019, 23:30   #9  |  Link
Nematocyst
Registered User
 
Join Date: May 2004
Location: Albuquerque, NM
Posts: 78
Quote:
Originally Posted by Lypheo View Post
You need to write the timecodes to a file and then mux them into the video.

Code:
vspipe --y4m <foo.vpy> --timecodes timecodes.txt - | ffmpeg -i pipe: -c:v libx265 -preset veryslow -crf 20 -vf "nlmeans=s=10" -y "outfoo.mkv"
Then:

Code:
mkvmerge --output finalfoo.mkv --timestamps 0:timecodes.txt outfoo.mkv
Thank you. I tried this method and it worked fine. I ended up with a video of 30.303030 according to vlc's codec information. But whatever, it looks and sounds right except the AR issue.

[edit]
Fixed the AR issue running:
Quote:
ffmpeg -i finalfoo.mkv -aspect 720:540 -c copy finalfoo2.mkv
I'm assuming adding "-aspect 720:540" in the encoder line (2nd stage) above would also work.

Last edited by Nematocyst; 20th May 2019 at 23:46. Reason: AR fix
Nematocyst is offline   Reply With Quote
Old 21st May 2019, 00:37   #10  |  Link
Keiyakusha
契約者
 
Keiyakusha's Avatar
 
Join Date: Jun 2008
Posts: 1,576
Quote:
Originally Posted by Nematocyst View Post
extra info regarding AR problem. If I use the vapoursynth script above, commenting out the crop+resize and issue this command:

I get the wrong AR compared to just:

and this output from the vpy script on the cmdline:
Image on DVDs is distorted (sorry can't come up with a better word at this time) by design. It is corrected on-playback using whatever information in mkv container or video stream itself. After passing through vapoursynth, correction information is lost (and manual scaling you don't perform). This is all as it should be. You must select correct display ratio for the video when you do encoding, muxing into container or both (since this information would be written in different places: video stream / container)

Edit: also if makemkv is responsible for making initial mkvs, there is no way the fremarate issue would be VFR-related. Correct me if i'm wrong, but makemkv doesn't do re-encoding and can't decimate frames, which is required to produce VFR. So not sure why people are suggesting that.

Last edited by Keiyakusha; 21st May 2019 at 00:45.
Keiyakusha is offline   Reply With Quote
Old 21st May 2019, 14:45   #11  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 714
Quote:
Originally Posted by Keiyakusha View Post
Edit: also if makemkv is responsible for making initial mkvs, there is no way the fremarate issue would be VFR-related. Correct me if i'm wrong, but makemkv doesn't do re-encoding and can't decimate frames, which is required to produce VFR. So not sure why people are suggesting that.
You can have NTSC DVDs where parts of the video are 24000/1001 fps with RFF flags, and parts are 30000/1001 fps.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Reply

Tags
aspect ratio, audio sync, vapoursynth

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 12:01.


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