'mkv file out of sync with linear drift

I have a bunch of mkv files, with FLAC as the audio codec and FFV1 as the video one.

The files were created using an EasyCap aquisition dongle from a VCR analog source. Specifically, I used VLC's "open acquisition device" prompt and selected PAL. Then, I converted the files (audio PCM, video raw YUV) to (FLAC, FFV1) using

ffmpeg.exe -i input.avi -acodec flac -vcodec ffv1 -level 3 -threads 4 -coder 1 -context 1 -g 1 -slices 24 -slicecrc 1 output.mkv

Now, the files are progressively out of sync. It may be due to the fact that while (maybe) the video has a constant framerate, the FLAC track has variable framerate. So, is there a way to sync the track to audio, or something alike? Can FFmpeg do this? Thanks

EDIT

On Mulvya hint, I plotted the difference in sync at various times; the first column shows the seconds elapsed, the second shows the difference - in secs. The plot seems to behave linearly, with 0.0078 as a constant slope. NOTE: measurements taken by hands, by means of a chronometer

enter image description here

EDIT 2

Playing around with VirtualDub, I found that changing the framerate to 25 fps from the original 24.889 (Video->Frame rate...->Change frame rate to) and using the track converted to wav definitely does work. Two problems, though: VirtualDub crashes when importing the original FFV1-FLAC mkv file, so I had to convert the video to H264 to try it out; more, I find it difficult to use an external encoder to save VirtualDub output.

So, could I avoid using VirtualDub, and simply use ffmpeg for it? Here's the exported vdscript:

    VirtualDub.audio.SetSource("E:\\4_track2.wav", "");
    VirtualDub.audio.SetMode(0);
    VirtualDub.audio.SetInterleave(1,500,1,0,0);
    VirtualDub.audio.SetClipMode(1,1);
    VirtualDub.audio.SetEditMode(1);
    VirtualDub.audio.SetConversion(0,0,0,0,0);
    VirtualDub.audio.SetVolume();
    VirtualDub.audio.SetCompression();
    VirtualDub.audio.EnableFilterGraph(0);
    VirtualDub.video.SetInputFormat(0);
    VirtualDub.video.SetOutputFormat(7);
    VirtualDub.video.SetMode(3);
    VirtualDub.video.SetSmartRendering(0);
    VirtualDub.video.SetPreserveEmptyFrames(0);
    VirtualDub.video.SetFrameRate2(25,1,1);
    VirtualDub.video.SetIVTC(0, 0, 0, 0);
    VirtualDub.video.SetCompression();
    VirtualDub.video.filters.Clear();
    VirtualDub.audio.filters.Clear();

The first line imports the wav-converted audio track. Can I set an equivalent pipe in ffmpeg (possibly, using FLAC - not wav)? SetFrameRate2 is maybe the key, here.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source