Please add support for x264 interlaced encoding in FFMPEG recording option

sq5

New Member
OP, I think dodgepong and R1CH are conflating a few things you are saying and getting the wrong idea what your goal is.

You said you wanted to use OBS to convert 1080i videos into h.264 but maintain the interlacing. As R1CH explained to you, this would be impossible with OBS even if OBS supported interlaced output.

There is basically no chance of this happening. This is not what OBS is supposed to be used for.

When you are saying "convert videos" I believe you really mean "capture/record videos". They are hearing the word "convert" and immediately thinking you're on the wrong program. When you ask to add interlacing in x264, you really mean "fix" interlacing in x264 since libx264 has done it for over 15 years.

It's important to note then that R1CH is correct that if you have a video file saved as 1080i and merely want to convert it to another file format without messing up the interlacing, then something like ffmpeg by itself (or handbrake, etc.) would be better suited.

It's also important for whoever comes across this thread looking for help on this later knows that Dodgepong's statements are incorrect, misleading, and unhelpful. OBS actually uses ffmpeg and its libraries, so it is not only very possible to preserve interlace content in OBS, OBS in fact CAN and DOES produce interlaced output just as ffmpeg itself does. It has little to do with OBS at all.

What this thread is really about was not a feature request, but a bug report. More specifically, a particular standard encoder parameter for x264 that normally works but is throwing an error when clicking "Start Recording" and needs to be fixed. Other codecs do not have this problem. It appears limited to libx264.

In the mean time, depending on your overall project, there is a workaround or two I can share that you may be able to use in OBS to get an acceptable, result for your intended content delivery.
 

dodgepong

Administrator
Forum Admin
I never said outputting interlaced video was impossible. I said converting interlaced video that was added to OBS as a media source (or more generally, taking any interlaced video input) to another interlaced format was impossible. In complete fairness, it is technically not "impossible" as much as it is "extremely difficult to get right" due to how OBS decodes and then re-encodes video. If it were to come out right, it would almost be by accident.

The reason for this is twofold: First, OBS effectively works in a progressive-scan environment. It would de-interlace the video, and then re-interlace it on output, which will severely degrade the quality. Second, OBS does not change its framerate to match a media source's framerate. Matching the frame rate is more complicated than putting the same number into OBS's FPS box because videos can have variable frame rates and are not always exact. As R1CH said, if timing gets off even a little bit, then the entire video is ruined. If you really want to convert the file, it should be done in an environment where your content never gets deinterlaced in the first place, and where framerate is matched between input and output for the duration of the conversion.

I don't think the project is completely closed to the idea of investigating the enablement of interlaced encoding output, but the work would have to be properly motivated, and converting interlaced videos into other interlaced formats is not a proper motivation.
 
Last edited:

dodgepong

Administrator
Forum Admin
@Wickerman Can I ask once gain why FFmpeg by itself can't accomplish what you want? It has the ability to take interlaced input and then output it in another interlaced format as I described above.
 

sq5

New Member
@Wickerman Can I ask once gain why FFmpeg by itself can't accomplish what you want? It has the ability to take interlaced input and then output it in another interlaced format as I described above.

I think the OP is trying to CAPTURE 1080i video and correctly record it from real time video source input. Entirely different than adding a 1080i video file as a media source and convert it to another kind of video file.

I agree FFmpeg by itself is a better choice for the latter, but OBS is already perfectly suited to the former.
 

sq5

New Member
OBS effectively works in a progressive-scan environment. It would de-interlace the video, and then re-interlace it on output, which will severely degrade the quality.

OBS won't deinterlace video from a source unless you purposely tell it to by setting a deinterlacing mode for that media source. Otherwise OBS deinterlacing is disabled and it leaves that source alone, passing it through as interlaced.

OBS does not change its framerate to match a media source's framerate. Matching the frame rate is more complicated than putting the same number into OBS's FPS box because videos can have variable frame rates and are not always exact. As R1CH said, if timing gets off even a little bit, then the entire video is ruined. If you really want to convert the file, it should be done in an environment where your content never gets deinterlaced in the first place, and where framerate is matched between input and output for the duration of the conversion.

I can't speak for him, but I think the OP IS NOT TRYING TO CONVERT A FILE. If he is however, then you are correct here.

I don't think the project is completely closed to the idea of investigating the enablement of interlaced encoding output, but the work would have to be properly motivated, and converting interlaced videos into other interlaced formats is not a proper motivation.

The project doesn't need to investigate enabling interlaced output in OBS. It is already there. Try recording interlaced video in OBS with some of the other codecs available there and it already works fine. Only libx264 produces an error where it should usually work the same as all the others.

I agree that there is not a motivation to make OBS work as a video conversion tool. It doesn't sound like anyone is asking for that though. I certainly am not.

This whole thread comes down to what is more of a bug in the libx264 library as compiled in OBS. Maybe the OP and I have very different use cases and I should have started a separate thread instead of posting in this one.
 
Last edited:

dodgepong

Administrator
Forum Admin
I think the OP is trying to CAPTURE 1080i video and correctly record it from real time video source input. Entirely different than adding a 1080i video file as a media source and convert it to another kind of video file.

I agree FFmpeg by itself is a better choice for the latter, but OBS is already perfectly suited to the former.
Hard disagree on it being different. FFmpeg can take input from video capture devices by itself just fine. This is a job for FFmpeg. OBS is not perfectly suited for this job.
OBS won't deinterlace video from a source unless you purposely tell it to by setting a deinterlacing mode for that media source. Otherwise OBS deinterlacing is disabled and it leaves that source alone, passing it through as interlaced.
Let me be more specific then. You're correct that OBS won't apply a deinterlacing filter to the video that eliminates the deinterlacing artifacts. But it still decodes and renders the interlaced video as a full-frame image, and it would have to be back-converted to interlaced video on the other side. So no, it doesn't apply a deinterlacing filter, but rather it turns the deinterlaced video into a full-frame video with deinterlacing artifacts when it's decoded and rendered. That will still cause significant artifacting on the re-encode, especially if frame timings or resolution scales are off by even a little bit.
I can't speak for him, but I think the OP IS NOT TRYING TO CONVERT A FILE. If he is however, then you are correct here.
It doesn't really matter either way. This applies for all interlaced source content, whether live from a video capture device or pre-recorded from a media source.
This whole thread comes down to what is more of a bug in the libx264 library as compiled in OBS. Maybe the OP and I have very different use cases and I should have started a separate thread instead of posting in this one.
Possibly. If you just want to be able to save deinterlaced video regardless of source content then perhaps you should start a different thread about that, or post an idea to the ideas page.
 

sq5

New Member
Hard disagree on it being different. FFmpeg can take input from video capture devices by itself just fine. This is a job for FFmpeg. OBS is not perfectly suited for this job.

At that rate you could say the same for a huge chunk of what users do with OBS daily. Plus try getting a live preview of multiple input sources on ffmpeg, or a decent live preview on there at all!

Let me be more specific then. You're correct that OBS won't apply a deinterlacing filter to the video that eliminates the deinterlacing artifacts. But it still decodes and renders the interlaced video as a full-frame image, and it would have to be back-converted to interlaced video on the other side. So no, it doesn't apply a deinterlacing filter, but rather it turns the deinterlaced video into a full-frame video with deinterlacing artifacts when it's decoded and rendered. That will still cause significant artifacting on the re-encode, especially if frame timings or resolution scales are off by even a little bit.

Appreciate these specifics. I wonder however if this applies to real time video, like from a capture card. Video capture devices can be spitting out pretty raw video and feeding it to OBS through Directshow (on Windows) so no decoding going on there.

In my experience with OBS and interlaced video, it has been left alone and passed to the encoder. Maybe that changes when there are multiple mixed progressive/interlaced sources on the canvas and that's to be expected. I can confirm though that I have been able to preserve interlacing in single video sources on OBS just fine, only not with x264 because of an error that comes up in the current version.

This applies for all interlaced source content, whether live from a video capture device or pre-recorded from a media source.

That's mainly why I ended up in this thread. The bug I wanted to bring up hits you whether you are encoding from a real time source or a file media source or both, so I thought it spoke to the OP's problem.

Possibly. If you just want to be able to save deinterlaced video regardless of source content then perhaps you should start a different thread about that, or post an idea to the ideas page.

Thanks I'll do that.

As you said about FFmpeg, it does this (the encoding part) just fine already, including with x264. So since FFmpeg is integrated into OBS, and interlaced content already works with several other codecs in OBS as it does in FFmpeg itself, then getting a program error in OBS only with x264 is not intended program behavior as I'm seeing it.
 
Last edited:

Wickerman

New Member
Guys, just to clarify I AM TRYING TO RECORD/CAPTURE 1080i (NOT CONVERT) videos using the x264 interlaced encoding setting. Note, that videos are recorded in the MBAFF scan field when using x264 interlaced encoding. This option looks entirely achievable if only the libx264 library could be corrected to enable interlaced encoding. Feels like we're just going around in circles without anyone from the dev team knowing how to make this work.
 

sq5

New Member
Wickerman- I assumed that is what you meant from the beginning so thanks for clarifying.

What you can do until the dev team corrects their libx264 build is change from the standard x264 codec selection to another suitable codec. Mpeg2 and FFV1 are probably your next choices. In the encoder options, enter field_order=tt or field_order=bb with no dashes and no spaces, that's how OBS wants it. I think it is the same for both of those codecs. This should help whoever comes across this thread later too.

Depending on how long your videos are, ffv1 is going to eat up a lot of hard drive space so maybe try mpeg2 first. If you want them specifically in x264 then you can reencode them with Handbrake afterward, making sure to use the tff or bff encoder option as usual there for libx264's MBAFF interlaced mode.

If you were also looking to stream/broadcast these videos back out with OBS right now and the interlacing is important then you may be out of luck in that department.
 
Last edited:

Wickerman

New Member
Wickerman- I assumed that is what you meant from the beginning so thanks for clarifying.

What you can do until the dev team corrects their libx264 build is change from the standard x264 codec selection to another suitable codec. Mpeg2 and FFV1 are probably your next choices. In the encoder options, enter field_order=tt or field_order=bb with no dashes and no spaces, that's how OBS wants it. I think it is the same for both of those codecs. This should help whoever comes across this thread later too.

Depending on how long your videos are, ffv1 is going to eat up a lot of hard drive space so maybe try mpeg2 first. If you want them specifically in x264 then you can reencode them with Handbrake afterward, making sure to use the tff or bff encoder option as usual there for libx264's MBAFF interlaced mode.

If you were also looking to stream/broadcast these videos back out with OBS right now and the interlacing is important then you may be out of luck in that department.
Thanks so much for the info, I will check out the mpeg2 encoding option. Can you also please tell me how I can adjust the cabac frames with mpeg2?
 

nokd

New Member
sorry to bother you. can you show me how to set a OBSoption to output with interlaced? I tried many times but It didn't work. please help
 

sq5

New Member
R1CH, thanks very much for this patch!

I wanted to follow up in this thread that I too was able to try it out and the improvement in output is OUTSTANDING. Regardless how the graphics pipeline sees them, interlaced frames are now correctly surviving through the encoder and properly maintained in x264/MBAFF output as hoped.

I endorse merging this patch into the main OBS build.
 
Top