Page 1 of 2

Deinterlacing with ffmpeg?

Posted: Wed Apr 04, 2007 5:31 pm
by robi
Hi!

I am experimenting with higher resolutions that present interlacing.
I'd like to have the exported video in a deinterlaced form. Consulted ffmpeg's documentation, and found that there is a `-deinterlace' option, that filled in ZM's ZM_FFMPEG_OUTPUT_OPTIONS (Additional output options to ffmpeg) option, doesn't do what it's supposed to. Other options work well here (like -b 3000), but -deinterlace is not. Any ideas why? I'm trying the mpg format.

Also, what's the difference between the formats? Is there a separate way for the avi format, for example, to use the `-vcodec codec' option. I'm thinking here that if case, authorities would be glad to accept MJPEG or DV-encoded AVI-s, that ffmpeg does support through the also opensource libavcodec.

Posted: Fri Apr 06, 2007 6:41 am
by robi
Anybody checked this one?

Posted: Fri Apr 06, 2007 11:06 am
by muzyk10
please post Your log (/var/www/localhost/htdocs/zoneminder/events/xx/xxxxxx/ffmpeg.log) after the video creation fails with yours paramaters. I remember when I upgraded my ffmpeg to something current (2007-xx - sort of) then suddenly deinterlace option stops working and now ffmpeg complainig if I want to use it with deinterlace. Sorry for my englidh, i'm not native speaker.

greetings

Posted: Fri Apr 06, 2007 4:10 pm
by robi
Okay here you go:

Can't see anywhere the deinterlace option, however in ZM settings I have it like: "-deinterlace -r 25 -b 3000 " :shock:

Code: Select all

FFmpeg version SVN-r6122, Copyright (c) 2000-2004 Fabrice Bellard
  configuration:  --prefix=/usr --enable-shared --libdir=/usr/lib --enable-a52 --enable-pp --enable-gpl --enable-pthreads --enable-mp3lame --enable-faad --enable-faac --enable-x264 --enable-xvid --enable-amr_nb 
  libavutil version: 49.0.0
  libavcodec version: 51.11.0
  libavformat version: 50.5.0
  built on Sep 13 2006 06:33:34, gcc: 4.1.1 20060724 (prerelease) (4.1.1-3mdk)
Input #0, image2, from '%05d-capture.jpg':
  Duration: 00:00:17.3, start: 0.000000, bitrate: N/A
  Stream #0.0: Video: mjpeg, yuvj420p, 640x480,  7.09 fps(r)
Output #0, mpeg, to 'Auto-2091-r1-s1.mpg':
  Stream #0.0: Video: mpeg1video, yuv420p, 640x480, q=2-31, 3000 kb/s, 25.00 fps(c)
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop encoding
frame=   35 q=2.0 size=     380kB time=1.4 bitrate=2288.9kbits/s    
frame=   71 q=2.0 size=     754kB time=2.8 bitrate=2206.0kbits/s    
frame=  106 q=2.0 size=    1184kB time=4.2 bitrate=2309.4kbits/s    
frame=  141 q=2.0 size=    1624kB time=5.6 bitrate=2375.7kbits/s    
frame=  176 q=2.0 size=    2080kB time=7.0 bitrate=2434.2kbits/s    
frame=  212 q=2.0 size=    2526kB time=8.4 bitrate=2451.8kbits/s    
frame=  247 q=2.0 size=    2976kB time=9.8 bitrate=2477.6kbits/s    
frame=  282 q=2.0 size=    3338kB time=11.2 bitrate=2432.8kbits/s    
frame=  321 q=2.0 size=    3698kB time=12.8 bitrate=2366.7kbits/s    
frame=  360 q=2.0 size=    4056kB time=14.4 bitrate=2313.8kbits/s    
frame=  398 q=2.0 size=    4422kB time=15.9 bitrate=2281.2kbits/s    
frame=  430 q=2.0 Lsize=    4698kB time=17.2 bitrate=2242.8kbits/s    
video:440kB audio:0kB global headers:0kB muxing overhead 967.817332%
It generated the valid mpeg file, but without deinterlacing.

Posted: Fri Apr 06, 2007 9:23 pm
by jameswilson
i dont think it can deinterlace a video cretaed from jpeg's and is used when capturing via ffmpeg. I may be wrong but reading the docs (which was a while ago) it didnt seem to be jpeg related

Posted: Fri Apr 06, 2007 10:10 pm
by cordel
If I recall correctly (been a while since I looked through the ffmpeg docs myself) the deinterlace option is only good if you use ffmpeg to capture directly from the device and does not work with files.

Posted: Sat Apr 07, 2007 6:46 am
by robi
Any chance to implement deinterlacing when grabbing the frames then?

Posted: Sun Apr 08, 2007 1:11 pm
by jameswilson
i beleive its on the list, but there are issues regarding modifying the footage and it not being a clean capture. Technically this would make it inadmissable. But as usual i over react on these type of things. lol

Posted: Tue May 15, 2007 3:16 pm
by kdf
I would really like to see the ability to deinterlace frames before analisis aswell. Im fine for modifying/coding php but havent a clue when it comes to C++ :( and from the research i've been doing everything important (capture, analisis and streaming to the browser) is done using zmc, zma and nph-zms which ofcourse are C++ programs.

I delved into the src and quickly decided not to bother lol..

Posted: Tue May 15, 2007 3:40 pm
by jameswilson
its a very very complicated thing and needs to be done by the bttv driver not zm, zm grabs an image from the driver, if the image is interlaced then this effect is seen, if it isnt then it wont be. But to try and de-interlace an image after the event is nigh on impossible and would be a huge resource hog. AFAIK

Posted: Tue May 15, 2007 10:30 pm
by kdf
Thanks for your input.. I know its complicated as I couldnt even follow the C++ code with all the includes etc. :shock:

Im using a wintv go card using V4l and the cx88 driver. There doesnt seem to be a way to deinterlace on the fly..

I had written a php function to do the deinterlacing but obviously that wont work pre-analisis !

Posted: Tue May 15, 2007 10:54 pm
by jameswilson
you have a php function that will deinterlace the jpg's?

Posted: Tue May 15, 2007 11:12 pm
by kdf
Yes,

I havent tested it to see what kind of impact it would have on the system, i'll be testing it tommorow with say 200 full quality 720x576 jpeg images to see how long it takes to process them... at best though I would only be able to provide post event deinterlacing so that if you go to watch the alerts it will all be deinterlaced for you.

The added advantage would be that ffmpeg encoded video of the events will also be deinterlaced ;)

If it works well I will post the code..

I was thinking though that if the images were to be deinterlaced before they were captured then it would provide better motion detection. Unfortunatly it is outwith my skillset to patch/modify the C++ code :(


EDIT: oh, and as pointed out in another thread, it shouldnt de-interlace the timestamp so im gonna have to work on trying to provide an exclusion zone to the function based on the stored timestamp preferecnes in the mysqlDB heh...

Posted: Tue May 15, 2007 11:44 pm
by jameswilson
id be interested to know as i spent a while trying to do this on zm4ms but i gave up deciding it was impossible

Posted: Thu May 17, 2007 11:58 am
by kdf
Quick update.

After a LOT of reading about deinterlacing techniques.. and testing.. I have learned..

1) My php script used field duplication to deinterlace (50% reduction in quality due to dropping every odd or even field)
2) There is not one perfect method of deinterlacing
3) If you want the best quality deinterlacing prepare to shell out up to $100,000 on the hardware, if not you can go for a software Bob+weave which would give you good results but there doesnt appear to be a Bob+weave deinterlacing program for linux and even if there was it might be too difficult to implement into ZM.
4) Its cheaper to just buy a progressive scan camera (Axis springs to mind)
5) If you dont want to do that Its easier to just half the camera resolution = no interlacing
6) The interlaced method was created in 1930.. and is still used today.. damn !!

PMSL @ my wasted time .. oh well :(