[FFmpeg-user] Automatic encoding of .ts files gives an inexplicable delay after muxing

Henk D. Schoneveld belcampo at zonnet.nl
Fri Oct 24 15:52:39 CEST 2014


On 23 Oct 2014, at 19:13, marsupilami <streamin at elitemail.org> wrote:

> Hello,
> 
> I'm experiencing a weird problem which I will try to describe in the
> following post.
> 
> 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.
The source files almost always have audio or video delayed from each other. If you encode both video and audio in one step they are kept synchronised.
If you separately encode audio and thereafter video the audio encoding starts -ss 00:00:10 after the first audio part and 
the video encoding starts -ss 00:00:10 after the first video part, so the ‘original’ delay between video and audio is lost. Everything AFAIK.
> 
> 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
> ac3 file.
> 
> 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)
> 
> Video:
> 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 -
> 
> Audio:
> 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.
> 
> Greetings
> 
> 
> 
> --
> 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.
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://ffmpeg.org/pipermail/ffmpeg-user/attachments/20141024/52e2ea3a/attachment.asc>


More information about the ffmpeg-user mailing list