Log in

View Full Version : How to switch a H264 stream from VFR to CFR without recompressing?


PaulJBis
10th April 2016, 20:27
Hi all:

First of all, apologies. I've been out of the loop with everything related to video codecs, compression tools, etc., so I don't know about the newest developments. Also, if this is the wrong forum, please tell me so.

My problem: I have a HD DVB-T program saved using ElGato's EyeTV, which I want to convert so that I can edit it using Premiere. The program's video stream uses H264, so I just used Avidemux 2.6 to convert it to a MP4 container, copying the video stream "as-is", without recompressing...

...But the problem is that, when Premiere imports the resulting MP4 file, it reads the frame rate wrong. Opening the file with Media Player Classic, I see that it says the following about the H264 stream:


Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : Main@L4
Format settings, CABAC : Yes
Format settings, ReFrames : 4 frames
Format settings, GOP : N=16
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 34mn 23s
Bit rate : 3 435 Kbps
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Variable
Frame rate : 20.827 fps
Original frame rate : 25.000 fps
Minimum frame rate : 0.003 fps
Maximum frame rate : 25.000 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : MBAFF
Scan order : Top Field First
Bits/(Pixel*Frame) : 0.080
Stream size : 845 MiB (96%)
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709

And Premiere, indeed, reads the file's framerate as 20.827, instead of 25.

Now, the question is: is there any tool that I can use to turn this VFR H264 stream into a constant frame rate stream, without recompressing? (I could recompress if I had to, but I'd rather not, to preserve the original quality as much as possible).

hello_hello
12th April 2016, 15:29
You could try ffmsindex or L-Smash. Are you familiar with Avisynth?

Both can convert the frame rate by duplicating or dropping frames, which is probably all you need. An Avisynth script to open the video with ffmsindex like this would do it.

LoadPlugin("C:\Program Files\ffms\ffms2.dll")
FFVideoSource("E:\video.mp4", fpsnum=25, fpsden=1, threads=1)

Someone else will probably know the best way to please Premier. I don't use it. You could no doubt convert the video with a script like that to a lossless format and open the lossless file with Premier, or possibly use Avisynth to frame serve the video directly to Premier. Although as it's interlaced converting to a lossless format first might be less problematic.

sneaker_ger
12th April 2016, 16:14
To just change the flag you can use either:
1.) http://forum.doom9.org/showthread.php?t=152419 or
2.) mkvmerge (set fps/default-duration and --fix-bitstream-timing-information) or
(3.) maybe Premier will be happy with a muxer-level conversion using ffmpeg/mp4box/lsmash? I can't tell you.)

But there is a risk of your stream going out-of-sync if you do this. If that happens you have to do a conversion like described by hello_hello. Then you will need no re-encode eventually but you could at least feed Premier via a frame-server (if it supports AVI/VfW?) or lossless intermediate file. (lossless except for added/deleted frames)