[offtopic] video encoding with mencoder of ffmpeg

Thread in 'Discussion' started by Burbruee, 30 Jun 2009.

  1. Hey,

    I've been busy the last couple of days redoing some parts of my video website.
    I use JW FLV Player to playback the videos, and usually I use a windows box to convert my videos and then transfer them back to the server when they're done, but I want to be able to do this server-side as well.

    I have some space where some users may upload videos, and I want to convert these to some H.264 in a mp4 container so the flash video player can play it.

    As a test I uploaded a video of myself playing some Texmaster.
    I tried making it into an flv with ffmpeg, and it worked out. But I really hate flv and you can get so much better quality with x264 for video and some aac codec for audio within an mp4 container...

    I'm not really sure how to do that though, I've spent an hour googling, but couldn't really find what I want, it seems as if mencoder can't output a real mp4 container.

    If someone here is experienced with mencoder/ffmpeg/mp4box etc and know how to make a flash compatible mp4 using x264, please post. :)
  2. I first got into video processing using the speeddemosarchive.com wiki tutorials. I believe the one relevant to your interests is here:


    That's how I personally use it so if you have trouble setting it up just ask.
  3. That's exactly what I use as well. :D
    What I want to do though is converting on the server. (which is running linux and does not run anything graphical)
    Eventually, my final goal will be to make conversion automatic, but for now manual conversion is good enough.
    But I think I got it, found this bash script:
    TEMPDIR=`mktemp -d /tmp/transcode.XXXXXXXX`
    pushd $TEMPDIR
    echo "Pass 1"
    $MENCODER $ORIGDIR/$FILE -o $VID_OUTPUT -oac faac -srate 44100 -ovc x264 -x264encopts bitrate=$BITRATE:$PARAMS:pass=1 -vf scale=$RES 2>&1 >> $LOG
    echo "Pass 2"
    $MENCODER $ORIGDIR/$FILE -o $VID_OUTPUT -oac faac -srate 44100 -ovc x264 -x264encopts bitrate=$BITRATE:$PARAMS:pass=2 -vf scale=$RES 2>&1 >> $LOG
    MP4Box -aviraw video $VID_OUTPUT
    MP4Box -aviraw audio $VID_OUTPUT
    echo TEMP is $TEMP_AUDIO
    echo AAC is $AAC_AUDIO
    echo H264 is $H264_VIDEO
    MP4Box -add $H264_VIDEO:fps=29.97 -add $AAC_AUDIO $FINAL_OUTPUT
    mv $LOG $ORIGDIR
    echo Files left in $TEMPDIR
    # rm -fr $TEMPDIR
    I just need to compile MP4Box from the gpack project. (which just finished with success, however it doesn't work, apparently some error when loading shared library..)
  4. I have it working now, but not without problems. :)
    Even though I said output fps should be 60fps, it's played back at 25 fps or something. So it looks like my grandmother is playing Texmaster.
  5. Hm, a bit of a problem.
    This is a 320x240@60fps avi video from Texmaster and then encoded with above script, looks fine:

    This is a 720x480@30fps avi I recorded uncompressed with my capture card, uploaded to my server and then encoded with the script:

    It looks a bit funky.. I encoded it with a bitrate of 2500kbps yet it looks like that. I'm aware of the fact that it's interlaced, but it should still not look like that, also it looks the same even after deinterlacing.
    Using SDA's settings for MeGUI makes it look perfect, so it must be some encoding options I need to add.

    Any ideas of what might be wrong?
  6. I'm seeing lots of interlacing artifacts, but I guess you don't mean those. Aside from that it's blurry... What sort of quality does your capture card record? Some of it is probably caused by stretching due to incorrect resolution. You'll want to deinterlace it and resize to 640x480, assuming your capture card is getting the full picture.
  7. Compare to this which is also interlaced: (encoded with MeGUI)

    EDIT: And here, deinterlaced with yadif:

    My capture card does 720x576 or 720x480 depending on PAL/NTSC/PAL60 at 25 or 30 fps. Source is S-video so image is pretty sharp.

    The blur and the blocking artifacts is what's bothering me. It's what you'd expect to get if you encode with a low bitrate, but 2500kbps should give me pretty high quality. Not at all like that, it should look like the videos in this post.

    I'll toy with the params of my script, I see now that they are quite different from what I have in MeGUI.
    program --pass 2 --bitrate 2048 --stats ".stats" --level 4.1 --ref 3 --mixed-refs --no-fast-pskip --bframes 3 --weightb --direct auto --subme 7 --trellis 2 --partitions p8x8,b8x8,i4x4,i8x8 --8x8dct --qpmin 19 --vbv-bufsize 9000 --vbv-maxrate 25000 --me umh --threads auto --thread-input --progress --no-psnr --no-ssim --output "output" "input" 
    Last edited: 30 Jun 2009
  8. Yeah, you can definitely rule out the source video and resolution being a problem. Unfortunately I'm more experienced with video processing than video encoding so I can't really help troubleshoot beyond this.
  9. Everything is working now, and I made it into a php script, I'll just modify it further to add upload forms that will insert stuff into the database and people should be able to upload videos for conversion.


    *should* work.

Share This Page