Monday, July 23, 2012

ffmpeg filters, PTS timestamps and mencoder

Well, today I learned a lot more from ffmpeg and video formats and it's encoding in general.

First of all, i'm really happy with the filters it provides.

The drawtext allows you to burn timestamps in your video. I used it to burn it into my scene detection mosaic (see post below) so I can see at which time the scene changes.

The showinfo filter shows you some detailed frame information, first I was wondering why the (PTS) timestamps didn't match with the timestamps in my mosaic, but then (after a few hours) I discovered that the PTS timestamps are relative and can be changed to zero-baed with the "setpts" video filter.

The command I use to get a nice timestamped mosaic with scene changes and a log file that can be parsed to create a chapters file is:

ffmpeg -i $INPUT -vf drawtext="fontfile='/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf':timecode='00\\:00\\:00\\:00':rate=25:fontsize=72:fontcolor=white@0.8: x=0: y=0",select='gt(scene\,0.5)',scale=160:120,showinfo,tile=10x16 -s 1920x1200 -frames:v 1 $OUTPUT 1> output.txt 2>&1

The problem is that there is no audio-filter which modifies the audio "frame" pts, so the audio-track is out-of-sync. There was a patch proposed in the mailinglist some time go but was declined because it share some code with the video-pts-set filter.

Then I found out that mencoder also does things like ffmpeg, so I simply tried to copy the audio and video stream and apparently the PTS timestamps are reset. There are a lot of issues though.

Apparently the mencoder libavformat muxing is broken for a looong time (I see mailinglist messages dated from 2008 with the same message), so now I try repacking it with ffmpeg or just get separate tracks and merge them together with ffmpeg.

No comments:

Post a Comment