lorddoskias
Posts: 15
Joined: Tue Jun 18, 2013 10:01 pm

De-interlacing video

Sat Jun 22, 2013 2:05 pm

I've been playing around with setting different openmax pipelines for transcoding video. Currently I have an input mpeg2 stream which has 50 fps (i acquired the number by opening file info from vlc) and I want to transcode this and de-interlace it. Using default settings for everything apart from the de-interlacer (3 extra buffers as per omxplayer code and setting the appropriate filter structure of the image_fx component) I do get de-interlaced video but it is at least 2 times slower e.g. running at 25 fps as a result you get the feeling that the guy on the screen is going to sleep. What options are likely to change that? I tried artificially setting the xFrameRate of the encoder's output port definition to 50 << 16 (since it is in Q16 format) to no avail.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: De-interlacing video

Sat Jun 22, 2013 3:48 pm

The PAL video standard is 25fps interlaced therefore your mpeg-2 stream is unlikely to be 50fps interlaced unless it's non-standard.
You cannot always trust what VLC reports mpeg-2 interlaced material has double the frame rate which is technically correct but not on playback unless your TV can render odd and even fields separately at 50fps progressive scan.

Richard S.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5340
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: De-interlacing video

Sat Jun 22, 2013 4:01 pm

Your video is almost certainly 25 frame per second, or 50 fields per second.
The output of the deinterlace component will be 50 frames per second (progressive).

So, it's likely you want to treat the input as 25fps and the output as 50fps.

lorddoskias
Posts: 15
Joined: Tue Jun 18, 2013 10:01 pm

Re: De-interlacing video

Sat Jun 22, 2013 7:25 pm

Ok, but how do I do that. As I have said I tried setting the xFrameRate in encoder's output port definition.format.video and also by using OMX_IndexConfigVideoFramerate but the resulting video is still "slow". E.g. everything is in slow motion. What might be the reasons for that?

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5340
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: De-interlacing video

Sat Jun 22, 2013 11:15 pm

lorddoskias wrote:Ok, but how do I do that. As I have said I tried setting the xFrameRate in encoder's output port definition.format.video and also by using OMX_IndexConfigVideoFramerate but the resulting video is still "slow". E.g. everything is in slow motion. What might be the reasons for that?
Normally the framerate is determined by the timestamps on the video frames. Have you muxed the video into a container (e.g. with ffmpeg)? That would be the place you would set the framerate.

lorddoskias
Posts: 15
Joined: Tue Jun 18, 2013 10:01 pm

Re: De-interlacing video

Sun Jun 23, 2013 11:02 am

Hi Dom,

I'm not doing any muxing at the moment. Instead, what I'm doing is demuxing (via libavformat) mpeg2 stream, taking just the video and feeding it into an video_decode -> image_fx -> encoder -> outputing mpeg4 (CodingAVC) into an h264 file. When I do this, as I said the video is in slow motion. When I have identical setup without the image_fx component the video plays at normal speed. So far I have been omitting setting the PTS value into the decoder's input buffer's nTimeStamp field. In the hello_video demo the input buffer's nTimestamp field is also not set, yet the video plays at correct speed.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5340
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: De-interlacing video

Sun Jun 23, 2013 11:12 am

lorddoskias wrote:Hi Dom,

I'm not doing any muxing at the moment. Instead, what I'm doing is demuxing (via libavformat) mpeg2 stream, taking just the video and feeding it into an video_decode -> image_fx -> encoder -> outputing mpeg4 (CodingAVC) into an h264 file. When I do this, as I said the video is in slow motion. When I have identical setup without the image_fx component the video plays at normal speed. So far I have been omitting setting the PTS value into the decoder's input buffer's nTimeStamp field. In the hello_video demo the input buffer's nTimestamp field is also not set, yet the video plays at correct speed.
No, hello_video doesn't play the video at the correct speed. It can't - there is no timing information in a raw h264 stream. I believe OpenMAX defaults to 30fps.

If you know the framerate of the raw h264 file (and you'll have to know that through some out of band information) then set it in xFramerate field of OMX_VIDEO_PARAM_PORTFORMATTYPE (or set the timestamps).

lorddoskias
Posts: 15
Joined: Tue Jun 18, 2013 10:01 pm

Re: De-interlacing video

Sun Jun 23, 2013 11:15 am

I tried by setting the PTS values from the demuxed video stream into the input buffers to no avail. In order to make things more concrete. Here is the mpeg 2 sample I'm using: http://87.120.131.41/dl/mpeg2.ts the result after it goes through my setup is this: http://87.120.131.41/dl/mpeg4.h264

Clearly the picture in the mpeg4 video is slower than in the original. Also the reason I;m doing deinterlacing is because of the lines when he is scrubbing the pipe at second 2 of the video clip. Is this due to interlacing or not? Because I might be trying to solve a problem that is not there in the first place?!

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5340
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: De-interlacing video

Sun Jun 23, 2013 1:20 pm

Yes, mpeg2 file is interlaced, so deinterlacing is reasonable.

But what do you want to do with the output stream? A h264 cannot contain timing information.
This is what mediainfo says about your h264 stream:

Code: Select all

General 
Complete name : C:\Users\dc4\Downloads\mpeg4.h264 
Format : AVC 
Format/Info : Advanced Video Codec 
File size : 17.3 MiB 

Video 
Format : AVC 
Format/Info : Advanced Video Codec 
Format profile : High@L2.2 
Format settings, CABAC : Yes 
Format settings, ReFrames : 1 frame 
Format settings, GOP : M=1, N=60 
Width : 720 pixels 
Height : 576 pixels 
Display aspect ratio : 5:4 
Standard : PAL 
Color space : YUV 
Chroma subsampling : 4:2:0 
Bit depth : 8 bits 
Scan type : Progressive 
Note: there is no fps or framerate reported, because it doesn't exist.
You have to store the framerate outside the video bitstream. Muxing into a container file (e.g. mkv) and setting the framerate there to 50 would be one way of achieving this.

lorddoskias
Posts: 15
Joined: Tue Jun 18, 2013 10:01 pm

Re: De-interlacing video

Sun Jun 23, 2013 1:30 pm

Thanks, I will test muxing the stream and setting the framerate in the muxer. However, what remains mystery in this case is if I have an mpeg4 produced from the input mpeg2 stream but without the image_fx component it plays normally - at the same speed as the input? Why is this discrepancy happening?

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5340
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: De-interlacing video

Sun Jun 23, 2013 2:22 pm

lorddoskias wrote:Thanks, I will test muxing the stream and setting the framerate in the muxer. However, what remains mystery in this case is if I have an mpeg4 produced from the input mpeg2 stream but without the image_fx component it plays normally - at the same speed as the input? Why is this discrepancy happening?
Because deinterlacing doubles the framerate. Each field produces a whole frame.

Return to “OpenMAX”