in

andy vt's tools & blog

Automating lazy

Help testing MEncoder with DVR-MS support

Last post 10-08-2007 2:44 PM by onlydarksets. 358 replies.
Page 2 of 24 (359 items) < Previous 1 2 3 4 5 Next > ... Last »
Sort Posts: Previous Next
  • 02-16-2007 9:28 PM In reply to

    Re: Help testing MEncoder with DVR-MS support

    Legend:

    The first thing you should do to get the video the way you want is to delete the "scale" video filter.  That should improve things dramatically without doing anything else.  You can also try to use a lower quantizer value (essentially a lower compression ratio).  If that doesn't give you the control you need, try using the lavc video codec instead of xvid - it seems to give you more nuanced control.

    Here's what I'm using for my WM5 Smartphone (I've lowered the audio bitrate, normalized the volume, and used slightly higher compression):

    mencoder -demuxer 35 "INPUT.dvr-ms" -af volnorm -vf scale=320:240 -ofps 29.97 -ovc xvid -xvidencopts fixed_quant=5 -oac mp3lame -lameopts cbr:br=64 -o "OUTPUT.avi"

    As an aside, PocketDivXEncoder uses this command line to create very small files:

    mencoder.exe "%InputFile%" -audio-preload 0.8 -delay 0.1 -af volnorm  -srate 22050 -oac mp3lame -lameopts mode=3:cbr:br=24 -noodml -demuxer 35 -vf pp=ac,scale=320:240,eq2=1.0:1.0:0.03:1.0,harddup  -sws 9   -ovc lavc -lavcopts vcodec=mpeg4:mbd=1:last_pred=2:vstrict=1:threads=2:vmax_b_frames=0:vbitrate=248 -ffourcc DX50 -o "G:\DTb Files\%OutputFile%"

    I've made a few notes on what the parameters mean, which may help someone else getting started with mencoder: 

    Required parameters

    • Input file (list first)
    • Output file (-0)
    • Audio codec (-oac)
      • Lame [MP3] (mp3lame)
        • Options (-lameopts a:b:c:d)
          • Average, Constant, or Variable Bitrate (abr | cbr | vbr)
          • Bitrate (br=)
    • Video codec (-ovc)
      • XviD [Mpeg4] (xvid)
      • libavcodec [Mpeg4, more] (lavc)

      Optional parameters

      • Video filters (-vf)
        • Scale (scale=w:h)
      • Audio filters (-af)
        • Normalize volume (volnorm)
    • 02-17-2007 12:01 PM In reply to

      Re: Help testing MEncoder with DVR-MS support

      jelwood:
      Wow, I didn't think about shows that are 4:3 but broadcast 16:9.  Can you point me to an application that "skips through some frames in the file and figures out the best crop/resolution values automatically"?  I'd really like to see how they are doing this.  You can do this manually by using the crop/zoom feature in MEncoder, but automatically determining when there are black bars to remove may be above my skills.

      I was thinking along the lines of applications like GordianKnot, which I've used to convert HD shows into Xvid before (however to do that they have to be converted into MPEG first). The resolution configuration screen allows automatically determining the crop values to get rid of black bars. I think programmatically it's not that difficult, you just take a couple of frames and test for each of them how far you can go "into" the picture from the top, left, bottom, and right, and find only pixels below a certain threshhold (since black is not necessarily black), and take those values as your crop values. Alternatively simply displaying a frame from the middle of the file and allowing the user to determine the crop values manually (with a real-time preview) is also helpful.

      jelwood:
      Regarding the command line.  Maybe there are too many options to integrate this into Dtb.  I'll keep thinking about it, but it may be best to just keep it an executable that you can call from Dtb.

      Well I could imagine having a set of pre-defined profiles for different target platforms, or even better a configuration screen with the options people are most likely to change: Resolution, Quality/Bitrate/Quantizer, Audio Bitrate, and maybe threads but you can detect the CPU type from within DTb to predetermine that value.

      jelwood:
      Yes, I would like a sample, it will really help.  Thank you for all your help!

      I made a separate file with the first 50 MB (around 25 seconds of the show) of the "dirty" Survivor episode. I tested it and the behavior is reproducible on that short file already, so I'm uploading it to MegaUpload now. Right now it's saying 42 minutes upload time left, I will post the link here as soon as it's done! Edit: It's done now, here is the link: http://www.megaupload.com/?d=FUPL7WSP. If after doing your tests you need more of the file I can upload a bigger chunk, but I thought providing a shorter sample is easier for the beginning.

      I also did some more testing, but I will put the results into the reply to the next posting about different command lines, since I want to post the command line I'm using as well.

    • 02-17-2007 12:17 PM In reply to

      Re: Help testing MEncoder with DVR-MS support

      onlydarksets:
      The first thing you should do to get the video the way you want is to delete the "scale" video filter.  That should improve things dramatically without doing anything else.  You can also try to use a lower quantizer value (essentially a lower compression ratio).  If that doesn't give you the control you need, try using the lavc video codec instead of xvid - it seems to give you more nuanced control.

      That's exactly what I did. I started off by stripping away pretty much all of the parameters and then added them one by one to achieve the results I liked. In case there is anybody else except me who isn't converting for a mobile device but for his HDTV set, here is the command line I'm using:

      mencoder -demuxer 35 -vf scale=944:528 -lavdopts threads=2 -ofps 29.97 -ovc xvid -xvidencopts bitrate=1600:threads=2 -oac mp3lame -lameopts abr:br=160 "InputFile.dvr-ms" -o "OutputFile.avi" > "MEncoder.log" 2> "MEncoderError.log"

      The scales I use are values which have proven to get a pretty good balance between resolution, file size, bitrate, and quality. For a 16:9 show I use 944x528, for a 4:3 show it would be 704x528. When keeping the bitrate around 1600, the resulting file will be somewhere between 650 and 700 MB in size for a one hour show. Also, I raised the audio bitrate to 160, even though I openly admit that I probably wouldn't notice the difference to 128 much, it's simply personal preference. You will notice that at the end I'm writing the stdout log and stderr log into separate files, so that I can see what's going on.

      I used this on a working show I recorded, and while the Xvid file looks good, I noticed slight AV synch problems. Not everywhere in the file, and not with identical delays, which brings me to the conclusion that it has to do with cutting out the commercials. I am running the conversion on the original file right now that still has the commercials in it to prove my suspicion. I've had problems like this long time ago. Cutting commercials messes with the time stream embedded in the video stream, and after demuxing the audio the time information is lost and the encoder can only put audio and video together at the beginning of both streams without applying any delay. When playing back the original dvr-ms there might be a split-second after a commercials break without audio which it uses to synchs up again, so there you don't have that delay, because the time information is still intact. I know from experience that there is no easy way around this except making sure to keep everything as "clean" as possible (only cut on key frames etc.) when cutting out the commercials.

      Once again, I'll post more results as they come in (this is a time-consuming process as jelwood pointed out!).

      Update: When playing back the Xvid that I created from the dvr-ms without commercials on my Xbox I did not notice any AV synch problems anymore, which really surprised me. Now I'm testing with different players on my machine to track down what might have caused it. But it seems now that the commercials have indeed been cut out "clean" and that they don't cause problems when reencoding the file!

      Update 2: I've been going through both the Xvid with and the one without commercials with different players now, and sometimes it seems that there is some AV synch problem (in both files), but then when I skip back 30 seconds and wait for the same scene it's gone, so I think it's just from jumping around in the file before the synch has been restored by the player. So it might be nothing really. Also, I realized that Survivor is probably the worst show to detect AV synch problems with, because most of the time there are voice overs and people talking that you can't really see, and you have to jump around a lot to find a scene where you can watch somebody's lips move with the audio. I will try out a different show and get back to you on this one. For now disregard any synch problems I've mentioned.

    • 02-17-2007 6:58 PM In reply to

      Re: Help testing MEncoder with DVR-MS support

      Legend:
      For now disregard any synch problems I've mentioned.

      This is good news.  Let's hope there really arn't any AV sync issues.

      Right now here are the things we are working on.

      1) the fps issue

      2) AAC encoding.  Right now I'm having big problems getting the AAC library to work with MEncoder.  It works fine when I compile ffmpeg, but it just doesn't work with MPlayer.  I'm trying ot figure out why.

      3) Threads.  Right now it looks like Mencoder only works with pthreads (Linux).  pthreads don't work very well under Windows, which is why ffmpeg uses win32 threads under Windows.  I'm trying to figure out if I can somehow use win32 threads because I'm not seeing much of a performance difference when I set "threads=2".  However, on ffmpeg when I set "threads=2" there is a big performance difference.  This confirms that it's a pthread issue and not an issue with the external libraries.

    • 02-17-2007 8:39 PM In reply to

      Re: Help testing MEncoder with DVR-MS support

      I can't seem to get this version of mencoder to work.

      For a while now I've been using a profile to go dvr-ms -> cut commercials to dvr-ms -> to mpg -> to xvid.avi type file. It's working well though it does add all those steps that this would eliminate.

      Outside of dtb I built a batch file using onlydarksets string and I got the first frame of video and all the audio from a 5 minute recording. I thought something might be up so I went back to my profile that calls the original mencoder and tried the same 5 minute recording and it worked fine. I then edited my profile to call this new version of mencoder and I can't get a vaild file out of it.

      I feel like there is something I missed installing or a switch I forgot to set.
       

      Home Built Media Server | Windows 7 RC (x86) | HP MediaSmart Connect Extender | www.techlifeweb.com | @techlifeweb on Twitter
    • 02-18-2007 1:25 AM In reply to

      Re: Help testing MEncoder with DVR-MS support

      kingtone:
      Outside of dtb I built a batch file using onlydarksets string and I got the first frame of video and all the audio from a 5 minute recording. I thought something might be up so I went back to my profile that calls the original mencoder and tried the same 5 minute recording and it worked fine. I then edited my profile to call this new version of mencoder and I can't get a vaild file out of it.

      This is exactly what I saw with what I called "dirty" recordings. The first frame would appear as freeze frame, and then after that nothing anymore while audio is fine. Can you look at the output of mencoder and see if you can find similar error messages to the ones I posted before? Something along the lines that it cannot determine aspect ratio or cannot find the header information. It is also true that these "dirty" files seem to work fine when converted into mpeg first and then into xvid. I think it really has something to do with the first couple of frames being invalid and then mencoder gets hung up on it.

      kingtone:
      I feel like there is something I missed installing or a switch I forgot to set.

      No, on your side everything is fine, this is one of the problems jelwood is working on right now. He will probably ask you for a copy of your source file to reproduce the problem.
       

    • 02-18-2007 1:27 AM In reply to

      Re: Help testing MEncoder with DVR-MS support

      jelwood:
      1) the fps issue

      Jelwood, that reminds me that the file I uploaded to MegaUpload was one which didn't work at all, if you go back to my initial post I described freeze frame on the first frame with working audio. I will also make a 50 MB snapshot of the X-Men2 recording which had the fps issue, where it was detected as 0.8fps for you! I'll update this post when the MegaUpload is done.

       

    • 02-18-2007 5:52 AM In reply to

      Re: Help testing MEncoder with DVR-MS support

      jelwood:

      http://www.megaupload.com/?d=5UJ58HH3

      Above is a link to a version of MEncoder that can now read dvr-ms files natively.  A really BIG thank you goes to John Donaghy for all the hours he spent looking through Hex dumps, reverse engineering the dvr-ms format.  John put in a lot of time and deserves all the credit for making this happen.

      [snip] 

      Sweet.  This is working very nicely with UK DVB-T now, no synch problems as before.  I'm getting this error with lavc encoding, though:

      Compiler did not align stack variables. Libavcodec has been miscompiled and may be very slow or crash. This is not a bug in libavcodec, but in the compiler. Do not report crashes to FFmpeg developers.

      Using:

      "C:\mplayer\mencoder.exe" -demuxer 35 -sws 2 -vfm ffmpeg -vf pp=md,scale=624:352 -oac mp3lame -lameopts fast:preset=medium -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:vbitrate=900:autoaspect -ffourcc DX50 -noodml -o "Output.avi" "Input.dvr-ms"
       

    • 02-18-2007 6:39 AM In reply to

      Re: Help testing MEncoder with DVR-MS support

      kingtone:

      I can't seem to get this version of mencoder to work.

      For a while now I've been using a profile to go dvr-ms -> cut commercials to dvr-ms -> to mpg -> to xvid.avi type file. It's working well though it does add all those steps that this would eliminate.

      Outside of dtb I built a batch file using onlydarksets string and I got the first frame of video and all the audio from a 5 minute recording. I thought something might be up so I went back to my profile that calls the original mencoder and tried the same 5 minute recording and it worked fine. I then edited my profile to call this new version of mencoder and I can't get a vaild file out of it.

      I feel like there is something I missed installing or a switch I forgot to set.
       

      I doubt it is anything you did incorrectly.  Legend predicted this, but can you upload that 5 minutes to megaupload.com?  I’m still digging through the code, but I think this issue may be related to the others.  Right now it appears we are having an issue finding the key frames at the beginning of some shows.  In your example, it seems we have an extreme case of never finding key frames in the video stream.  I know it’s a pain sending the samples, but they really help because I don’t understand everything they are doing in this code, so I’m doing a lot of trial and error…

       

    • 02-18-2007 6:47 AM In reply to

      Re: Help testing MEncoder with DVR-MS support

      Hecks:
      Compiler did not align stack variables. Libavcodec has been miscompiled and may be very slow or crash. This is not a bug in libavcodec, but in the compiler. Do not report crashes to FFmpeg developers.

      I noticed this as well…  My theory is it was a problem because I was using to Cygwin.  I switched to Msys, however, I can’t get the AAC library to work in Msys.  Anyway, thank you for pointing it out (for now, it doesn’t seem to affect anything).  It’s on my list to work on along with the threads issue I’m seeing.

    • 02-18-2007 10:42 AM In reply to

      Re: Help testing MEncoder with DVR-MS support

      Legend:

      Can you look at the output of mencoder and see if you can find similar error messages to the ones I posted before? Something along the lines that it cannot determine aspect ratio or cannot find the header information. It is also true that these "dirty" files seem to work fine when converted into mpeg first and then into xvid. I think it really has something to do with the first couple of frames being invalid and then mencoder gets hung up on it.

      The output has reams and reams of:

       Writing header...
      ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
      Writing header...
      ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
      Writing header...
      ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
      Writing header...

      {snip}

      ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
      Writing header...
      ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
      Pos:  73.4s      1f ( 1%)  0.06fps Trem:  26min   2mb  A-V:0.000 [0:0]
      Maybe you are playing a non-interleaved stream/file or the codec failed?
      For AVI files, try to force non-interleaved mode with the -ni option.
      Writing header...
      ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
      Pos:  73.5s      2f (15%)  0.11fps Trem:   1min   1mb  A-V:1.200 [0:151]
      Maybe you are playing a non-interleaved stream/file or the codec failed?
      For AVI files, try to force non-interleaved mode with the -ni option.
      Writing header...
      ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
      Writing header...
      ODML: Aspect information not (yet?) available or unspecified, not 

      {snip}

       writing vprp header.
      Writing header...
      ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
      Writing header...
      ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.
      Pos:  73.6s      3f (15%)  0.16fps Trem:   1min   1mb  A-V:2.367 [0:152]
      Maybe you are playing a non-interleaved stream/file or the codec failed?
      For AVI files, try to force non-interleaved mode with the -ni option.
      VDec: vo config request - 720 x 480 (preferred colorspace: Planar YV12)
      VDec: using Planar YV12 as output csp (no 0)
      Movie-Aspect is 1.33:1 - prescaling to correct movie aspect.
      videocodec: XviD (704x528 fourcc=44495658 [XVID])
      xvid: par=0/0 (vga11), displayed=704x528, sampled=704x528
      xvid: CBR Rate Control -- bitrate=1600kbit/s
      Writing header...
      ODML: vprp aspect is 4:3.
      Writing header...
      ODML: vprp aspect is 4:3.

      {snip} 

       Pos:  85.5s      4f (15%)  0.19fps Trem:   1min   1mb  A-V:3.533 [0:152]
      Maybe you are playing a non-interleaved stream/file or the codec failed?
      For AVI files, try to force non-interleaved mode with the -ni option.
      Pos:  85.5s      5f (15%)  0.24fps Trem:   1min   1mb  A-V:4.700 [0:152]

      seems like it is trying to do something a that point

       Ending with

      Pos:7132.7s   1759f (100%) 16.36fps Trem:   0min  10mb  A-V:2050.975 [8:150]
      Flushing video frames.
      Writing index...
      Writing header...
      ODML: vprp aspect is 4:3.

      Video stream:    8.588 kbit/s  (1073 B/s)  size: 7657325 bytes  7132.766 secs  1759 frames

      Audio stream:  150.976 kbit/s  (18872 B/s)  size: 1104240 bytes  58.512 secs

      I'll post the original...its actually only about a minute

      UPDATE:  Here is the original dvr-ms: http://www.megaupload.com/?d=2A5JZHV7

      Home Built Media Server | Windows 7 RC (x86) | HP MediaSmart Connect Extender | www.techlifeweb.com | @techlifeweb on Twitter
    • 02-19-2007 2:17 PM In reply to

      Re: Help testing MEncoder with DVR-MS support

      Thank you to everyone for your testing and samples.  Here is the link to the new version: http://www.megaupload.com/?d=Z0SE949S  Below is the command line I used for my testing.

      mencoder -lavdopts threads=2 "Input file.dvr-ms" -vf expand=:::::4/3,scale=320:240 -ofps 29.97 -ovc lavc  -lavcopts vcodec=xvid:vqscale=4:threads=2 -oac mp3lame -lameopts abr:br=128 -o "output file.avi"

      Because of the "fps change" detection logic, I recommend using the "-lavdopts threads=2" switch if you have Hyperthreading or a dual core system.  If you don't have this switch everything will work fine, it will just be a little slower because of all the reading and re-reading it is doing.

      Now, the challenge to really speed things up will be getting win32 threads working instead of pthreads.  I don't know if it's possible, but I'll try.

      Let me know if this version works better detecting your fps and reading the dvr-ms format.  Also, if we can't get Win32 threads to work, I'm a little concerned about the speed of converting HD shows.  The encoding may end up being faster with Directshow.  Let me know what your experience is with the speed of this build (warning: it will be slower than the previous version, but hopefully not too slow).

      Things still outstanding:

      • Try to get Win32 threads to work.
      • Getting AAC audio encoding library to work.
    • 02-19-2007 4:51 PM In reply to

      Re: Help testing MEncoder with DVR-MS support

      jelwood:
      Let me know if this version works better detecting your fps and reading the dvr-ms format.  Also, if we can't get Win32 threads to work, I'm a little concerned about the speed of converting HD shows.  The encoding may end up being faster with Directshow.  Let me know what your experience is with the speed of this build (warning: it will be slower than the previous version, but hopefully not too slow).

      I did some testing tonight with Directshow and I feel better.  This version of Mencoder is still roughly 20% faster on the hardest HD shows (1920x1080i at 60fps).  On shows with less resolution and fps it did even better.

      I'm still going to work on the threads because I think we can do better (at least for multi-core processors).  However, I feel better now that we didn't slow down things too much.

    • 02-19-2007 9:27 PM In reply to

      Re: Help testing MEncoder with DVR-MS support

      Lookin' good! I used your (jelwood's) script and it took about an hour to convert a 2 hour 30 min standard def show. Output size was 600MB.

       My computer is year or so old Pentium 4 3GHz with 1GB RAM, Windows Vista

      I haven't watched all 2.5 hours of output yet but my samples look in sync.

      My next quest is to figure out how to use the -edl switch. I think I understand it but haven't figured out how to create the edl file with SA. 

      Home Built Media Server | Windows 7 RC (x86) | HP MediaSmart Connect Extender | www.techlifeweb.com | @techlifeweb on Twitter
    • 02-20-2007 10:40 AM In reply to

      Re: Help testing MEncoder with DVR-MS support

      kingtone:

      Lookin' good! I used your (jelwood's) script and it took about an hour to convert a 2 hour 30 min standard def show. Output size was 600MB.

       My computer is year or so old Pentium 4 3GHz with 1GB RAM, Windows Vista

      I haven't watched all 2.5 hours of output yet but my samples look in sync.

      My next quest is to figure out how to use the -edl switch. I think I understand it but haven't figured out how to create the edl file with SA. 

      In SA, you need to enable mplayer output, IIRC (don't have it installed right now).  In Comskip.ini (DVRMSToolbox\Applications folder), set output_edl=1.

      -Hecks 

    Page 2 of 24 (359 items) < Previous 1 2 3 4 5 Next > ... Last »
    @2008 andy vt
    Powered by Community Server (Non-Commercial Edition), by Telligent Systems