Warm tip: This article is reproduced from stackoverflow.com, please click
ffmpeg

FFMPEG: Encoding WEBM with fast-seek and copyts leads to wrong video length

发布于 2020-04-08 09:32:01

I'm trying to convert a scene from a soft-subbed MKV file into a hard-subbed WEBM file with two-pass. The video encodes fine, but the file shows the wrong length when opened on a media player (it's showing as if I had encoded the original file from the starting point all the way to the end).

This is the command I'm using:

set timestamp=-ss 12:59.069 -to 16:14.277

ffmpeg -y %timestamp% -copyts -i source.mkv -shortest -c:v libvpx-vp9 -pass 1 -b:v 0 -crf 33 -threads 8 -speed 4 -tile-columns 6 -frame-parallel 1 -an -sn -vf scale=-1:720,subtitles=source.mkv -f webm NUL
ffmpeg -y %timestamp% -copyts -i source.mkv -shortest -c:v libvpx-vp9 -pass 2 -b:v 0 -crf 33 -threads 8 -speed 2 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25 -c:a libopus -b:a 64k -sn -vf scale=-1:720,subtitles=source.mkv -f webm out.webm

When opening the video in MPC-BE, the video plays regularly until around the point shown on https://i.stack.imgur.com/6bRwc.png (which is where the scene I wanted to cut out ends) then it just skips to the end of the file, and this wrong length is giving me all sorts of issues when I try to use the encoded video.

Questioner
TheOverlord2D
Viewed
104
Gyan 2020-02-01 14:19

Apparently, your player doesn't like a non-zero starting timestamp (at least in WebMs).

So, reset the timestamps before writing (I assume you're using copyts for the subtitles filter alignment).

In pass 2,

ffmpeg -y %timestamp% -copyts -i source.mkv -shortest -c:v libvpx-vp9 -pass 2 -b:v 0 -crf 33 -threads 8 -speed 2 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25 -c:a libopus -b:a 64k -sn -vf scale=-1:720,subtitles=source.mkv -output_ts_offset -12:59.069 -f webm out.web

where the value for ts offset is the negative of your ss value.