Log in

View Full Version : VFR to CFR conversion


Sharc
17th February 2019, 15:44
VEGAS still seems to have issues (creating blended frames or fields) with the handling of (pseudo) VFR files, so I have to convert these VFR files to CFR before importing into VEGAS. I can do this without re-encoding with mkvtoolnix and subsequent remux of the .mkv to a format which Vegas accepts, e.g. m2ts with tsmuxer.
Can the VFR to CFR conversion be done in 1 step with ffmpeg? I tried various options but did not succeed without re-encoding.

sneaker_ger
17th February 2019, 15:48
What is "pseudo VFR"? What is source codec? What is source container? What are you doing in mkvtoolnix exactly?

Sharc
17th February 2019, 15:57
"Pseudo" VFR: These are for example .mp4 clips from mobile phones which are slightly off from the standard framerates, for example 30.007 fps or 29.884 fps instead of nominal 29.97 fps. Dumping the time stamps shows that the frames are pretty much CFR with the exception of say the first or last frame(s) which are way out.

I fix these by remuxing the .mp4 to .mkv with mkvtoolnix, selecting the framerate as 30000/1001 and ticking "fix bitstream timing info" in the GUI.

sneaker_ger
17th February 2019, 16:48
Try something like:
ffmpeg -y -i "input.mp4" -c:v copy -an -sn -bsf:v h264_metadata=tick_rate=1001/60000:fixed_frame_rate_flag=1 -f rawvideo - | ffmpeg -y -fflags +genpts -i - -i "input.mp4" -map 0:v -map 1:a -c copy "output.m2ts"

But it seems there's a lot broken with ffmpeg so it may or may not work depending on the source...

Sharc
17th February 2019, 18:33
Thanks a lot. Unfortunately no luck, getting the error

pipe:: Invalid data found when processing input
av_interleaved_write_frame(): Broken pipe
Error writing trailer of pipe:: Broken pipe
frame= 14 fps=0.0 q=-1.0 Lsize= 1037kB time=00:00:00.43 bitrate=19595.8kbits/s speed=3.33x
video:1108kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!


Surprisingly, VMS (Vegas Movie Studio) seems to convert these VFR sources without blending fields and without skipping/doubling frames when I select the rendering quality in VMS to the lower levels like "preview" or "draft".

Kisa_AG
22nd February 2019, 13:34
Surprisingly, VMS (Vegas Movie Studio) seems to convert these VFR sources without blending fields...

Vegas also can do this. Just set in Project Prefs > Video > Resample Mode = Disable.
Also you can do this for any particular clip in project bu changing clip's properties.

poisondeathray
22nd February 2019, 15:28
For those "pseudo" VFR files, I would use mp4fpsmod . You can batch, and even inplace edit with "-i" (the -i means inplace edit, not "input" like ffmpeg)

eg.

"mp4fpsmod.exe" --fps 0:30000/1001 "input.mp4" -o "output_cfr.mp4"


batch inplace edit all mp4 files in a directory

for %%a in ("*.mp4") do "mp4fpsmod" "%%a" -i --fps 0:30000/1001
pause

Sharc
22nd February 2019, 18:10
Vegas also can do this. Just set in Project Prefs > Video > Resample Mode = Disable.
Also you can do this for any particular clip in project bu changing clip's properties.
Thank you for the hint. Apparently it worked for "Draft" and "Preview" project quality setting because these settings disable the resampling by default.
I found that it is also advisable to import the file at project framerate in order to obtain the desired exact output framerate. New to Vegas, still learning.

Sharc
22nd February 2019, 18:14
For those "pseudo" VFR files, I would use mp4fpsmod . You can batch, and even inplace edit with "-i" (the -i means inplace edit, not "input" like ffmpeg)

eg.

"mp4fpsmod.exe" --fps 0:30000/1001 "input.mp4" -o "output_cfr.mp4"


batch inplace edit all mp4 files in a directory

for %%a in ("*.mp4") do "mp4fpsmod" "%%a" -i --fps 0:30000/1001
pause

Nice, thank you. I tried and it works. These "VFR" files are still a pain. Better to convert them all to CFR before processing them further.

hydra3333
4th March 2019, 08:09
What happens to audio sync, if the first frame is way off ?

Sharc
4th March 2019, 09:35
What happens to audio sync, if the first frame is way off ?
I didn't notice an obvious problem, like an offset or drift. I should perhaps double-check. The clips are all very short, typically less than 30 seconds

poisondeathray
4th March 2019, 19:31
What happens to audio sync, if the first frame is way off ?

If the first frame is way off, then usually other frames are way off. That would not be a "psuedo VFR" file with minor jitter in the timecodes that you could "treat" as CFR . If you look at mediainfo (view=>text) it will usually report a min/max framerate for those types of files and that will only deviate by a tiny fraction.

VFR with large deviations cannot be "fixed" with this method, you would have to convert to CFR by using the conventional re-encoding methods - adding duplicate "placeholder" frames to keep sync

Sharc
4th March 2019, 23:46
How does MediaInfo determine the min. and max. framerates for VFR video files? Does it scan all timestamps of the entire video file? If so it seems to do this pretty fast.

poisondeathray
5th March 2019, 21:04
How does MediaInfo determine the min. and max. framerates for VFR video files? Does it scan all timestamps of the entire video file? If so it seems to do this pretty fast.

I don't know, but I doubt it scans the entire video

But the videos that have large deviations usually cannot be treated as CFR with that method. Only the ones that are very slightly off can be 29.979, 30.001 etc.. can usually be treated successfully in sync