# Please add support for x264 interlaced encoding in FFMPEG recording option



## Wickerman (Dec 6, 2020)

Hi developers.

I'd be extremely grateful if you could add support for x264 interlaced encoding using the FFMPEG recording option. I have a ton of old 1080i videos which I need to convert into the H264 format but I really want to keep them as original as possible and I think x264's interlaced encoding method would be the best solution for me.

Please please please add support for interlaced recording capability.

Regards
Wickerman


----------



## R1CH (Dec 6, 2020)

You should use FFmpeg directly from the command line, OBS is not a video conversion tool. Your videos would be de-interlaced before being encoded.


----------



## sq5 (Dec 6, 2020)

I so happened to run into this only a few days ago. Interlaced support is something that one would expect to already be there via the x264 recording encoder options "tff=1 or bff=1" , or similarly by setting FFmpeg custom output with the same option.

The problem I ran into was that with recording set up either way, starting recording would produce an error with the log saying something along the lines of "interlacing support not compiled" into the x264 library. So it recognized the encoder option but the code is merely missing from the library. As of this writing the library dll version in place is libx264-157.dll.

Perhaps the OBS devs compiled this library themselves and forgot to enable the interlaced/MBAFF encoding support, but it seems just a matter of compiling that one library with the appropriate flag back on and users are good to go.


----------



## sq5 (Dec 6, 2020)

> OBS is not a video conversion tool. Your videos would be de-interlaced before being encoded.



What the OP and I are looking to do is actually avoid a conversion that the encoder in OBS would otherwise be performing. OBS would be recording the interlaced video while expecting progressive by default, and so incorrectly mashing the scan fields down into single frames instead of keeping them straight.

On the other hand, OBS does not de-interlace videos before encoding (a good thing) unless one of the included deinterlacing methods is purposely selected for a video source first, so interlaced video does pass straight to the encoder.

A single x264 encoder option is all it takes to switch encoding/recording to the correct behavior for interlaced video so long as the library isn't compiled incomplete like the current one is.

A recompiled dll posted here on the forum is enough for me.


----------



## Wickerman (Dec 6, 2020)

R1CH said:


> You should use FFmpeg directly from the command line, OBS is not a video conversion tool. Your videos would be de-interlaced before being encoded.


Sorry R1CH, I meant to say that I need to encode (not convert) several 1080i streams into the H264 format using the interlaced encoding option through OBS (FFMPEG).  

Can you please look into the info posted by sq5? Seems like it's not too much to ask and would take very little effort to provide what we are asking for?

Thanks!


----------



## sq5 (Dec 9, 2020)

If someone otherwise has a stock libx264 dll binary from elsewhere or can point where to download one, that also might work. Looked on VideoLAN.org and they're only providing a self-contained x264 executable, so perhaps it's a stock x264 file from FFmpeg that would need to be swapped in if we can't get one from the OBS devs.


----------



## R1CH (Dec 10, 2020)

Unfortunately there is no guarantee that frames from your source align with frames sent to the encoder, since the source FPS and OBS' render FPS are independent. Even if you did find an interlaced encoder, as soon as there is a clock drift your encoding would be ruined.


----------



## sq5 (Dec 10, 2020)

Sure that's an issue wherever interlaced capture will be done but it's manageable, whereas capturing with the encoder set to progressive means encoding output is unfixably ruined from the start. When the x264 encoder is set to MBAFF interlaced mode, then the encoder is expecting interlaced video for a start and can attempt to adjust itself at times every so many frames.

Is it a big deal to enable that encoder flag in the library so the "tff=1 of bff=1" options can be used? Nothing needs to change on the OBS interface, and it's something that's normally working in a stock x264/FFMPEG encoder library. Could be merely a matter of recompiling one file and dropping that into the OBS folder over the existing one.


----------



## Wickerman (Dec 10, 2020)

sq5 said:


> Sure that's an issue wherever interlaced capture will be done but it's manageable, whereas capturing with the encoder set to progressive means encoding output is unfixably ruined from the start. When the x264 encoder is set to MBAFF interlaced mode, then the encoder is expecting interlaced video for a start and can attempt to adjust itself at times every so many frames.
> 
> Is it a big deal to enable that encoder flag in the library so the "tff=1 of bff=1" options can be used? Nothing needs to change on the OBS interface, and it's something that's normally working in a stock x264/FFMPEG encoder library. Could be merely a matter of recompiling one file and dropping that into the OBS folder over the existing one.


R1CH this!!!
Please can you make this work?


----------



## Wickerman (Dec 14, 2020)

R1CH said:


> Unfortunately there is no guarantee that frames from your source align with frames sent to the encoder, since the source FPS and OBS' render FPS are independent. Even if you did find an interlaced encoder, as soon as there is a clock drift your encoding would be ruined.


Can you please enable this option? I would be really really grateful!!!!!


----------



## Wickerman (Dec 15, 2020)

R1CH said:


> Unfortunately there is no guarantee that frames from your source align with frames sent to the encoder, since the source FPS and OBS' render FPS are independent. Even if you did find an interlaced encoder, as soon as there is a clock drift your encoding would be ruined.


Ahh I can see there has been an update for OBS today, however still no interlaced encoding support :(((

Please enable this option devs!!!!!


----------



## dodgepong (Dec 15, 2020)

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


----------



## Wickerman (Dec 16, 2020)

dodgepong said:


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


Why is there no chance of interlaced support being added onto the x264 encoder? Isn't OBS used for recording as well as streaming? I have been encoding several videos using x264 and pretty much every option can be enabled except interlaced encode? Why is it such a big deal to make this work?


----------



## sq5 (Dec 16, 2020)

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



I don't understand where you get this idea. For example, maintaining common interlaced broadcast material while capturing/recording and for streaming back out for interlaced broadcast delivery is exactly something normal for Open Broadcast Studio to be used for. Nothing obscure about it. All it takes here is making sure one standard encoder option *that already exists* is correctly enabled in a library where it is *normally already enabled*.


----------



## Wickerman (Dec 18, 2020)

Seems like the OBS devs don't even know their own software :/


----------



## dodgepong (Dec 18, 2020)

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.


----------



## Wickerman (Dec 18, 2020)

dodgepong said:


> 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.


I need to encode 1080i streams into the H264 AVC format using the the x264 encoder under FFMPEG (custom output). As I mentioned, under this setting, I can pretty much change any x264 setting (like cabac, deblock, crf, bitrate etc), but when I try to enable x264's interlaced encoding using (interlaced=1 or tff/bff=1) the recording doesn't start and brings up an error message.

sq5 appears to know more than me on why this problem is occurring (see all his posts), it looks like it's just a simple matter of enabling an option under the x264 library to make this work so we really don't understand why this is being made into such a big deal?


----------



## Wickerman (Dec 21, 2020)

Any updates on this please???


----------



## dodgepong (Dec 21, 2020)

There are no updates. Posting repeatedly on this thread is not going to magically change this. I recommend you investigate an alternate solution.


----------



## Wickerman (Dec 22, 2020)

dodgepong said:


> There are no updates. Posting repeatedly on this thread is not going to magically change this. I recommend you investigate an alternate solution.


Why don't you consider recruiting sq5? He certainly appears to know your software more than you do!!!


----------



## sq5 (Dec 22, 2020)

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



dodgepong said:


> 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.





dodgepong said:


> 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 (Dec 22, 2020)

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.


----------



## dodgepong (Dec 22, 2020)

@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 (Dec 22, 2020)

dodgepong said:


> @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 (Dec 22, 2020)

dodgepong said:


> 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.



dodgepong said:


> 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.



dodgepong said:


> 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.


----------



## dodgepong (Dec 22, 2020)

sq5 said:


> 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.


sq5 said:


> 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.


sq5 said:


> 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.


sq5 said:


> 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 (Dec 22, 2020)

dodgepong said:


> 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!



dodgepong said:


> 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.



dodgepong said:


> 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.



dodgepong said:


> 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.


----------



## Wickerman (Dec 23, 2020)

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 (Dec 23, 2020)

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.


----------



## Wickerman (Dec 23, 2020)

sq5 said:


> 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.
> 
> ...


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?


----------



## R1CH (Dec 23, 2020)

Here is a rebuilt FFmpeg libs with interlaced encoding enabled, https://r-1.ch/ffmpeg-shared-git-master.7z

I still think you will not get the output you want however as the OBS graphics pipeline is still progressive.


----------



## Wickerman (Dec 23, 2020)

R1CH said:


> Here is a rebuilt FFmpeg libs with interlaced encoding enabled, https://r-1.ch/ffmpeg-shared-git-master.7z
> 
> I still think you will not get the output you want however as the OBS graphics pipeline is still progressive.


R1CH this has worked :))))

Thanks so much, I am able to encode in interlaced format using x264 now. Really appreciate your help on this matter and I'm sorry for being a nuisance at times :)


----------



## nokd (Jan 18, 2021)

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 (Jan 20, 2021)

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.


----------



## tomimidi (Jan 26, 2021)

guys! could you help me how to set it under obs, how can i fix it in interlace? thank you!


----------

