Inaccurate trimming with re-encoding

Any other question that don't fit into the other support categorizes.
Post Reply
Posts: 1
Joined: Sun Aug 04, 2013 7:48 pm

Inaccurate trimming with re-encoding

Post by charwood89 »

Hi all,

I'm a fairly new ffmpeg user, but I've found it really helpful for processing videos as part of my graduate research. I've got a mess of videos (about 800 recordings of experiments from different angles) that I'm trying to synchronize. I coded my data acquisition system such that an LED turns on when I begin collecting data, giving me a visual indicator of where I can sync the videos, which should be accurate to within ~1/2 frame.

So I've got a matlab script to trim my videos to the frames at which I see the LED turn on (in HH:MM:SS[.ms] format). It feeds a ffmpeg command from matlab to a windows command prompt. I tried it with -vcodec copy, but (predictably) I found my outputs began at the nearest I-frame, up to 1s away from my desired trim point.

My understanding is that, if I decompress the video and re-encode, I should be able to trim at exactly the desired time because an I-frame will be placed at the beginning of the saved output during encoding. An example command, using a gopro video shot at 59.94 fps, with h.264 codec:

ffmpeg -t 30 -i GOPR0103.mp4 -vcodec libx264 –threads 0 -preset ultrafast -an -y -ss 00:03:09[.606] Run041_UW1.avi

Here's where I'm confused. If I execute the above command, I do get a trimmed output, but the resulting video starts 40 frames away from the desired frame. In contrast, if I use -vcodec copy on the same file, the output is only off by ~26 frames. I used avidemux to find the frame I wanted, and I see that 00:03:09[.606] corresponds to a P-frame, but using -vcodec libx264 should result in frame-accurate splitting, no?

What am I doing wrong here? Is there any way for me to get frame-accurate splitting? Any help is really appreciated. I've been reduced to banging my head on the keyboard over this.

Thanks very much!

Post Reply