Discussion:
[Mlt-devel] Deinterlace / Frame doubling
David Noble
2017-04-07 20:18:17 UTC
Permalink
Hi

I've got a couple 1080i25 sources[1], [2] that I'm trying to output to
a 1080p50 avformat consumer, and I seem to be struggling!

It seems that there's some interesting quirks in how mlt behaves
contra how the yadif deinterlacer in ffmpeg works. I'm aiming for an
output that looks like this: [3]; created using the following ffmpeg
command:

% ffmpeg -i 5sec.mov -vf yadif=1 5sec.mp4

So, my first attempt here was to try and get the avformat consumer to
do the deinterlacing for me:

% melt -profile atsc_1080i_50 -producer 5sec.mov -consumer
avformat:lol1.mp4 -deinterlace

This yielded this: [4]. Interestingly, this was a correctly interlaced
1080i25 file. Next up, I tried telling the consumer that I actually
wanted a 50fps file.

% melt -profile atsc_1080i_50 -producer 5sec.mov -consumer
avformat:lol2.mp4 mlt_profile=atsc_1080p_50

However, this is where things started going wrong. The resulting file
[5] had the correct number of frames, and the right number of frames
per second; e.g. it was a 1080p50 file, but the content was 25p; where
frames had been repeated to make up. Half of the temporal information
had been lost. It appears yadif is used, but not in frame doubling
mode.

I then tried the following:

% ffmpeg -i 5sec.mov -vf yadif=1 -c:v rawvideo -f nut pipe: > hueg.nut
% melt -profile atsc_1080p_50 -verbose title-audio.mov hueg.nut -mix
25 -mixer luma -mixer mix:-1 -consumer avformat:lol3.mp4

This had the desired result [6]. I then tried using named pipes to
pipe from ffmpeg to the avformat melt producer; but this did not work,
as it appears the file is opened and closed twice.

I'm trying to get the deinterlace to happen inside melt; so that I
don't have to have another transcode step, or resort to piping /
writing raw frames to files. Have any of you been able to do this
successfully?

Cheers in advance,


David.

[1] https://home.nuug.no/~daven/20170407-melt/5sec.mov
[2] https://home.nuug.no/~daven/20170407-melt/title-audio.mov
[3] https://home.nuug.no/~daven/20170407-melt/5sec.mp4
[4] https://home.nuug.no/~daven/20170407-melt/lol1.mp4
[5] https://home.nuug.no/~daven/20170407-melt/lol2.mp4
[6] https://home.nuug.no/~daven/20170407-melt/lol3.mp4
Brian Matherly
2017-04-07 20:51:27 UTC
Permalink
Hi David,
Post by David Noble
Hi
I've got a couple 1080i25 sources[1], [2] that I'm trying to output to
a 1080p50 avformat consumer, and I seem to be struggling!
It seems that there's some interesting quirks in how mlt behaves
contra how the yadif deinterlacer in ffmpeg works. I'm aiming for an
output that looks like this: [3]; created using the following ffmpeg
% ffmpeg -i 5sec.mov -vf yadif=1 5sec.mp4
So, my first attempt here was to try and get the avformat consumer to
% melt -profile atsc_1080i_50 -producer 5sec.mov -consumer
avformat:lol1.mp4 -deinterlace
This yielded this: [4]. Interestingly, this was a correctly interlaced
1080i25 file. Next up, I tried telling the consumer that I actually
wanted a 50fps file.
% melt -profile atsc_1080i_50 -producer 5sec.mov -consumer
avformat:lol2.mp4 mlt_profile=atsc_1080p_50
However, this is where things started going wrong. The resulting file
[5] had the correct number of frames, and the right number of frames
per second; e.g. it was a 1080p50 file, but the content was 25p; where
frames had been repeated to make up. Half of the temporal information
had been lost. It appears yadif is used, but not in frame doubling
mode.
<snip>

I understand exactly what you are trying to do. The short answer is the
MLT does not support frame-doubling deinterlacing. The expected behavior
of your command is that MLT will deinterlace two fields into one frame
and then double those resulting frames to achieve the requested frame
rate. No matter how hard you try, you will lose temporal information if
you deinterlace in MLT.

I pursued this some time ago:
http://mlt-devel.narkive.com/xJ5RNWDu/yadif-doubler
The architecture of MLT makes this feature quite tricky.

After I grasped the difficulty of adding the feature to MLT, I decided
instead to add a step to my workflow to normalize all my files. Here are
some scripts which I use and you are welcome to use/modify:
https://gist.github.com/bmatherly/e39fb68c876161d5b17b
https://gist.github.com/bmatherly/8995878
The extra encode step concerned me, as well. But I found that dnxhd
provides "loss-less enough" quality for all my own needs.

Also, I would mention that since I wrote those scripts, ffmpeg has added
a new deinterlacing filter that combines the strengths of the yadiff and
w3fdif filters:
http://ffmpeg.org/ffmpeg-filters.html#bwdif
I have had very good luck with the deinterlacing quality using the bwdif
filter.

Cheers,

~Brian
David Noble
2017-04-07 21:15:12 UTC
Permalink
Hi Brian,

Cheers for the really quick response!

2017-04-07 22:51 GMT+02:00 Brian Matherly <***@brianmatherly.com>:
*snip*
Post by Brian Matherly
It appears yadif is used, but not in frame doubling mode.
<snip>
I understand exactly what you are trying to do. The short answer is the MLT
does not support frame-doubling deinterlacing. The expected behavior of your
command is that MLT will deinterlace two fields into one frame and then
double those resulting frames to achieve the requested frame rate. No matter
how hard you try, you will lose temporal information if you deinterlace in
MLT.
http://mlt-devel.narkive.com/xJ5RNWDu/yadif-doubler
The architecture of MLT makes this feature quite tricky.
Understandable. Thanks for pointing this out :-)
Post by Brian Matherly
After I grasped the difficulty of adding the feature to MLT, I decided
instead to add a step to my workflow to normalize all my files. Here are
Thank you very much!
Post by Brian Matherly
Also, I would mention that since I wrote those scripts, ffmpeg has added a
new deinterlacing filter that combines the strengths of the yadiff and
http://ffmpeg.org/ffmpeg-filters.html#bwdif
I have had very good luck with the deinterlacing quality using the bwdif
filter.
Excellent, I'll give this a look.

I think I'll also try a bit harder to see whether I can get the
avformat consumer to write to a named pipe. It seems that melt runs
pretty nicely with native interlaced stuff, so if I can just get that
out without an extra step of compression / storage, that would make me
pretty happy. I'll let you know how I get on :-)

Cheers,


David.
David Noble
2017-04-07 22:12:29 UTC
Permalink
Hi again,

Just to follow up:

2017-04-07 23:15 GMT+02:00 David Noble <***@gmail.com>:
*snip*
Post by David Noble
I think I'll also try a bit harder to see whether I can get the
avformat consumer to write to a named pipe. It seems that melt runs
pretty nicely with native interlaced stuff, so if I can just get that
out without an extra step of compression / storage, that would make me
pretty happy. I'll let you know how I get on :-)
This is super hackish:
- it involves having a named pipe ending in .nut
- it involves setting the video codec to huffyuv, as rawvideo causes
melt to segfault
- there is a weird field-order issue that seems to require an explicit
bottom-field-first argument
- in contrast to yadif, bwdif seems to actually need the deint option
set to "all", despite it claiming this is the default

but it seems to do the trick for me:

Session A:
% mkfifo fifo.nut
% melt -profile atsc_1080i_50 -verbose title-audio.mov 15sec.mov -mix
25 -mixer luma -mixer mix:-1 -consumer avformat:fifo.nut progressive=0
field_order=tt vcodec=huffyuv acodec=pcm_s16le

Session B:
% ffmpeg -i fifo.nut -vf bwdif=1:1:0 deinterlaced-bwdif.mp4

Source and target files available here for those interested:

https://home.nuug.no/~daven/20170407-melt/title-audio.mov
https://home.nuug.no/~daven/20170407-melt/15sec.mov
https://home.nuug.no/~daven/20170407-melt/deinterlaced-bwdif.mp4
Post by David Noble
From what I can see, Brian's suggestion of using bwdif looks really
good - I'm pleased to see the improvement in picture quality here!

Cheers,


David.

Loading...