[MEncoder-users] -ss and -endpos cutting creates very visible h264 artifacts

Marc MERLIN marc_mplayer at merlins.org
Sun Feb 28 08:23:16 CET 2010


On Sun, Feb 28, 2010 at 08:08:07AM +0100, Reimar Döffinger wrote:
> On Sat, Feb 27, 2010 at 10:15:04PM -0800, Marc MERLIN wrote:
> > On Tue, Feb 23, 2010 at 11:37:57PM -0800, Marc MERLIN wrote:
> > > I sometimes trim videos like this:
> > > mencoder -oac copy -ovc copy  -ss 0 -endpos 4:00 source.avi -o dest.avi
> > > 
> > > This worked fine until I started doing it with h264 encoded videos.
> > > 
> > > Problem is that the first resulting keyframe isn't computed right and
> > > you get very visible artifacts like here:
> > > http://www.youtube.com/watch?v=AZJkFHWaTRI
> > > (see upper right of the picture for the first 10 seconds)
> > > 
> > > I'm using SVN-r29237-4.4.1.
> > > 
> > > Is there a fix to this problem?
> > 
> > I've been working on that one a bit more.
> > 
> > Is whoever is using h264 using other tools to cut an h264 video?
> > 
> > Looking at it again, it may just be that cutting an h264 video without
> > re-encoding it, is not possible due to the time between consecutive
> > keyframes. Is that correct?
> 
> Cutting it exactly at the right point usually is not possible with most video
> formats, however the specific issue here is probably that keyframes are not marked
> as such in the avi file. How was it created?

Basically, I get very high bitrate h264 from my camera, and then re-encode
at 2000/3000kbps

crux of the script is:

    for i in 1 2
    do
	echo "DOING $codec PASS $i"
	echo "------------------"
	    vf=$vf,scale
	    nice -19 mencoder -passlogfile "$pass" $demux $aud_channels $aud_srate -oac mp3lame -lameopts mode=3:abr:br=$abr $time $aspect $vf -ovc x264 -x264encopts bitrate=$br:turbo=1:pass=1:threads=0 $rot -o "$dest" "$src" || die "multipass failed on pass $i"
	fi
    done

Encoded video is great. Then I decide that I want to cut pieces out of it, which I 
do without re-encoding, like so:
mencoder -ss 0:10:20 -endpos 0:0:13 -oac copy -ovc copy source.mp4 -o dest.mp4

I was able to do this fine with divx/avi, but avc1/mov doesn't seem nearly
as happy with it.  It looks like the keyframes could be a good 10 sec apart
and mencoder doesn't try making an intermediate one when it just cuts at some offset.

I suppose the problem is that I do tell it to cut and not re-encode. Maybe
it just worked before with divx because I had a keyframe every second?

> Copying the video completely into a different format forst, e.g. mkv, with ffmpeg or mkvmerge
> or so might fix it...

Yes, if I re-encode it will likely work. It just takes a long time to
re-encode and loses quality :)

Marc
-- 
"A mouse is a device used to point at the xterm you want to type in" - A.S.R.
Microsoft is to operating systems & security ....
                                      .... what McDonalds is to gourmet cooking
Home page: http://marc.merlins.org/  


More information about the MEncoder-users mailing list