[FFmpeg-user] Automatic encoding of .ts files gives an inexplicable delay after muxing
streamin at elitemail.org
Thu Oct 23 19:13:59 CEST 2014
I'm experiencing a weird problem which I will try to describe in the
Currently, I'm writing a perl script for automatic encoding of MPEG-TS files
using ffmpeg and x264. I'm having ffmpeg apply video filters like resize,
deinterlace and so on and am then sending the output to x264 via stdout,
which will result in a mkv file. The audio is encoded in a separate ffmpeg
instance to AC3. For testing and checking purposes I'm later muxing the
resulting mkv and ac3 files to form a new mkv file. Both ffmpeg instances
(for video and audio encoding) start at the same position in the .ts file,
or at least so I'm assuming.
For some weird reason I'm getting an unpredictable audio delay after muxing
(with mkvmerge). It is always a negative value, ranging from -300 ms to
-1000 ms audio delay. The delay is a constant value, so by remuxing the two
output files with some delay added, it'll be sync for the rest of the file.
Yet the delay changes for different files and I can't understand why it does
that and how to fix it. After some googling and reading man pages I tried
skipping the first 10 seconds of both audio and video and checked if it
would fix the problem - unfortunately it didn't, the delay was still there
and still an unpredictable value.
Another thing which I was thinking of trying was to get ffmpeg to encode
video and audio in one instance - however I do not know how to accomplish
that and I'm not even sure if it would fix the problem. ffmpeg would have to
send the video output to stdout (piping to x264) and the audio output to an
Here's the command lines I've been using: (I should mention the .ts files
are being encoded as they're written to the disk - hence the -re switch;
however "non-live" encoding doesn't fix things)
ffmpeg -hide_banner -loglevel quiet -re -ss 00:00:10 -i file.ts -vf
"yadif=0:0:0,scale=720x404" -sws_flags lanczos -f yuv4mpegpipe -pix_fmt
yuv420p - | x264_64.exe --stdin y4m --level 3.1 --output output.mkv -
ffmpeg -hide_banner -loglevel quiet -re -ss 00:00:10 -i file.ts -map #0:7
-b:a 384k output.ac3
The script is running on a windows box. I've tried google lots of times but
I can't seem to find a solution to this problem. Would you mind giving me a
push into the right direction? I feel like I'm running into a wall here.
View this message in context: http://ffmpeg-users.933282.n4.nabble.com/Automatic-encoding-of-ts-files-gives-an-inexplicable-delay-after-muxing-tp4667828.html
Sent from the FFmpeg-users mailing list archive at Nabble.com.
More information about the ffmpeg-user