Automatic encoding of .ts files gives an inexplicable delay after muxing

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Automatic encoding of .ts files gives an inexplicable delay after muxing

marsupilami
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.

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
Reply | Threaded
Open this post in threaded view
|

Re: Automatic encoding of .ts files gives an inexplicable delay after muxing

Carl Eugen Hoyos
marsupilami <streamin <at> elitemail.org> writes:

> Here's the command lines I've been using

What's wrong with the following?
$ ffmpeg -i file.ts -vf yadif -vcodec libx264 -acodec ac3 out.mkv
(You have to add the remaining options you need.)

If this doesn't work, please provide the actual
command line you used together with the
complete, uncut console output (including banner!!)

Carl Eugen

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Automatic encoding of .ts files gives an inexplicable delay after muxing

marsupilami
Carl Eugen Hoyos wrote
marsupilami <streamin <at> elitemail.org> writes:

What's wrong with the following?
$ ffmpeg -i file.ts -vf yadif -vcodec libx264 -acodec ac3 out.mkv
(You have to add the remaining options you need.)
The main reason why I didn't try this sooner was because I was worried ffmpeg wouldn't include the latest version of x264 or it would maybe be too slow. However after trying out your command line I realised I was wrong and maybe I was thinking too complex when there was a cleaner and simpler solution available.

Encoding with my command line produces the following output:

E:\enc>ffmpeg -ss 00:00:10 -i input.ts -vf "framestep=2,scale=720x404" -sws_flags lanczos -f yuv4mpegpipe -pix_fmt yuv420p - | x264_64.exe --stdin y4m --level 3.1 --preset slow --crf 19.0 --deblo
ck -2:-2 --aq-strength 0.8 --sar 1:1 --output output.mkv -
ffmpeg version N-66742-gf6777ce Copyright (c) 2000-2014 the FFmpeg developers
  built on Oct  8 2014 22:01:47 with gcc 4.9.1 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libblu
ray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrw
b --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --
enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      54. 10.100 / 54. 10.100
  libavcodec     56.  4.101 / 56.  4.101
  libavformat    56.  9.100 / 56.  9.100
  libavdevice    56.  1.100 / 56.  1.100
  libavfilter     5.  1.103 /  5.  1.103
  libswscale      3.  1.100 /  3.  1.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  1.100 / 53.  1.100
[h264 @ 029df000] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 029df000] decode_slice_header error
[h264 @ 029df000] no frame!
[h264 @ 029df000] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 029df000] decode_slice_header error
[h264 @ 029df000] no frame!
[h264 @ 029df000] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 029df000] decode_slice_header error
[h264 @ 029df000] no frame!
[h264 @ 029df000] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 029df000] decode_slice_header error
[h264 @ 029df000] no frame!
[h264 @ 029df000] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 029df000] decode_slice_header error
[h264 @ 029df000] no frame!
[h264 @ 029df000] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 029df000] decode_slice_header error
[h264 @ 029df000] no frame!
[NULL @ 0426d300] start time for stream 8 is not set in estimate_timings_from_pts
[mpegts @ 0426e300] PES packet size mismatch
    Last message repeated 3 times
[mpegts @ 0426e300] Could not find codec parameters for stream 0 (Unknown: none ([5][0][0][0] / 0x0005)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[mpegts @ 0426e300] PES packet size mismatch
    Last message repeated 10 times
Input #0, mpegts, from 'input.ts':
  Duration: 01:15:01.04, start: 42121.255633, bitrate: 10866 kb/s
  Program 10301
  Program 10302
    Stream #0:0[0x4f6]: Unknown: none ([5][0][0][0] / 0x0005)
    Stream #0:1[0x13f7]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
    Stream #0:2[0x13f8](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 190 kb/s
    Stream #0:3[0x13f9](fra): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 190 kb/s
    Stream #0:4[0x13fa](deu): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
    Stream #0:5[0x13fb](deu): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006) (hearing impaired)
    Stream #0:6[0x13fc](mul): Audio: ac3 ([6][0][0][0] / 0x0006), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:7[0x13fd](mis): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 190 kb/s
    Stream #0:8[0x13fe](fra): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
    Stream #0:9[0x13ff](deu): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
  Program 10303
  Program 10304
Output #0, yuv4mpegpipe, to 'pipe:':
  Metadata:
    encoder         : Lavf56.9.100
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 720x404 [SAR 404:405 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.4.101 rawvideo
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> rawvideo (native))
Press [q] to stop, [?] for help
[yuv4mpegpipe @ 05140060] Encoder did not produce proper pts, making some up.
y4m [info]: 720x404p 404:405 @ 25/1 fps (cfr)
x264 [info]: using SAR=1/1
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2 FMA3 LZCNT BMI2
x264 [info]: profile High, level 3.1
frame=112275 fps=121 q=0.0 Lsize=47840334kB time=01:14:51.00 bitrate=87265.2kbits/s dup=14 drop=0
video:7017kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 681659.375000%
x264 [info]: frame I:954   Avg QP:15.72  size: 32986
x264 [info]: frame P:30208 Avg QP:18.51  size:  7304
x264 [info]: frame B:81113 Avg QP:21.12  size:  1656
x264 [info]: consecutive B-frames:  1.7%  2.9%  9.3% 86.1%
x264 [info]: mb I  I16..4: 11.9% 64.1% 24.0%
x264 [info]: mb P  I16..4:  2.0%  4.7%  1.2%  P16..4: 41.1% 17.5% 11.5%  0.0%  0.0%    skip:22.0%
x264 [info]: mb B  I16..4:  0.1%  0.3%  0.1%  B16..8: 32.9%  4.2%  0.9%  direct: 2.1%  skip:59.4%  L0:40.8% L1:49.1% BI:10.0%
x264 [info]: 8x8 transform intra:59.6% inter:75.6%
x264 [info]: direct mvs  spatial:100.0% temporal:0.0%
x264 [info]: coded y,uvDC,uvAC intra: 59.1% 66.7% 38.4% inter: 13.5% 16.9% 1.1%
x264 [info]: i16 v,h,dc,p: 46% 21%  9% 25%
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18%  9% 15%  8% 11% 12% 10% 10%  9%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29%  9%  5%  7% 11% 12% 10%  9%  9%
x264 [info]: i8c dc,h,v,p: 42% 23% 24% 11%
x264 [info]: Weighted P-Frames: Y:2.0% UV:0.8%
x264 [info]: ref P L0: 53.6% 10.7% 19.6%  8.4%  7.1%  0.7%  0.0%
x264 [info]: ref B L0: 80.3% 13.2%  4.5%  1.9%
x264 [info]: ref B L1: 95.8%  4.2%
x264 [info]: kb/s:688.38

encoded 112275 frames, 121.31 fps, 688.39 kb/s

For the sake of speed I omitted the -re switch.

Audio encoding produces this output:

E:\enc>ffmpeg -ss 00:00:10 -i input.ts -map 0:6 -b:a 384k output.ac3
ffmpeg version N-66742-gf6777ce Copyright (c) 2000-2014 the FFmpeg developers
  built on Oct  8 2014 22:01:47 with gcc 4.9.1 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libblu
ray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrw
b --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --
enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      54. 10.100 / 54. 10.100
  libavcodec     56.  4.101 / 56.  4.101
  libavformat    56.  9.100 / 56.  9.100
  libavdevice    56.  1.100 / 56.  1.100
  libavfilter     5.  1.103 /  5.  1.103
  libswscale      3.  1.100 /  3.  1.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  1.100 / 53.  1.100
[h264 @ 0412b620] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0412b620] decode_slice_header error
[h264 @ 0412b620] no frame!
[h264 @ 0412b620] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0412b620] decode_slice_header error
[h264 @ 0412b620] no frame!
[h264 @ 0412b620] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0412b620] decode_slice_header error
[h264 @ 0412b620] no frame!
[h264 @ 0412b620] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0412b620] decode_slice_header error
[h264 @ 0412b620] no frame!
[h264 @ 0412b620] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0412b620] decode_slice_header error
[h264 @ 0412b620] no frame!
[h264 @ 0412b620] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0412b620] decode_slice_header error
[h264 @ 0412b620] no frame!
[NULL @ 0410f820] start time for stream 8 is not set in estimate_timings_from_pts
[mpegts @ 040fdf60] PES packet size mismatch
    Last message repeated 3 times
[mpegts @ 040fdf60] Could not find codec parameters for stream 0 (Unknown: none ([5][0][0][0] / 0x0005)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[mpegts @ 040fdf60] PES packet size mismatch
    Last message repeated 10 times
Input #0, mpegts, from 'input.ts':
  Duration: 01:15:01.04, start: 42121.255633, bitrate: 10866 kb/s
  Program 10301
  Program 10302
    Stream #0:0[0x4f6]: Unknown: none ([5][0][0][0] / 0x0005)
    Stream #0:1[0x13f7]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
    Stream #0:2[0x13f8](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 190 kb/s
    Stream #0:3[0x13f9](fra): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 190 kb/s
    Stream #0:4[0x13fa](deu): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
    Stream #0:5[0x13fb](deu): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006) (hearing impaired)
    Stream #0:6[0x13fc](mul): Audio: ac3 ([6][0][0][0] / 0x0006), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:7[0x13fd](mis): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 190 kb/s
    Stream #0:8[0x13fe](fra): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
    Stream #0:9[0x13ff](deu): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
  Program 10303
  Program 10304
Output #0, ac3, to 'output.ac3':
  Metadata:
    encoder         : Lavf56.9.100
    Stream #0:0(mul): Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
    Metadata:
      encoder         : Lavc56.4.101 ac3
Stream mapping:
  Stream #0:6 -> #0:0 (ac3 (native) -> ac3 (native))
Press [q] to stop, [?] for help
[mpegts @ 040fdf60] PES packet size mismatch4.0kbits/s
[ac3 @ 04654440] incomplete frame
size=  210456kB time=01:14:49.72 bitrate= 384.0kbits/s
video:0kB audio:210456kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%

Encoding with your provided command line (altered to match my needs) produces the following output:

E:\enc>ffmpeg -i input.ts -vf "framestep=2,scale=720x404" -sws_flags lanczos -vcodec libx264 -map 0:v -preset slow -level 3.1 -crf 19 -sar 1:1 -deblock -2:-2 -aq-strength 0.8 -acodec ac3 -map 0:6
 -b:a 384k output2.mkv
ffmpeg version N-66742-gf6777ce Copyright (c) 2000-2014 the FFmpeg developers
  built on Oct  8 2014 22:01:47 with gcc 4.9.1 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libblu
ray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrw
b --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --
enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      54. 10.100 / 54. 10.100
  libavcodec     56.  4.101 / 56.  4.101
  libavformat    56.  9.100 / 56.  9.100
  libavdevice    56.  1.100 / 56.  1.100
  libavfilter     5.  1.103 /  5.  1.103
  libswscale      3.  1.100 /  3.  1.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  1.100 / 53.  1.100
[h264 @ 0423c600] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0423c600] decode_slice_header error
[h264 @ 0423c600] no frame!
[h264 @ 0423c600] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0423c600] decode_slice_header error
[h264 @ 0423c600] no frame!
[h264 @ 0423c600] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0423c600] decode_slice_header error
[h264 @ 0423c600] no frame!
[h264 @ 0423c600] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0423c600] decode_slice_header error
[h264 @ 0423c600] no frame!
[h264 @ 0423c600] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0423c600] decode_slice_header error
[h264 @ 0423c600] no frame!
[h264 @ 0423c600] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0423c600] decode_slice_header error
[h264 @ 0423c600] no frame!
[NULL @ 02aaab40] start time for stream 8 is not set in estimate_timings_from_pts
[mpegts @ 0420e000] PES packet size mismatch
    Last message repeated 3 times
[mpegts @ 0420e000] Could not find codec parameters for stream 0 (Unknown: none ([5][0][0][0] / 0x0005)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mpegts, from 'input.ts':
  Duration: 01:15:01.04, start: 42121.255633, bitrate: 10866 kb/s
  Program 10301
  Program 10302
    Stream #0:0[0x4f6]: Unknown: none ([5][0][0][0] / 0x0005)
    Stream #0:1[0x13f7]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
    Stream #0:2[0x13f8](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 190 kb/s
    Stream #0:3[0x13f9](fra): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 190 kb/s
    Stream #0:4[0x13fa](deu): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
    Stream #0:5[0x13fb](deu): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006) (hearing impaired)
    Stream #0:6[0x13fc](mul): Audio: ac3 ([6][0][0][0] / 0x0006), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:7[0x13fd](mis): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 190 kb/s
    Stream #0:8[0x13fe](fra): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
    Stream #0:9[0x13ff](deu): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
  Program 10303
  Program 10304
[libx264 @ 05469e80] using SAR=404/405
[libx264 @ 05469e80] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2 FMA3 LZCNT BMI2
[libx264 @ 05469e80] profile High, level 3.1
[libx264 @ 05469e80] 264 - core 142 r2479 dd79a61 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:-2:-2 analyse=0x3:0x113 me=umh su
bme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=
1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=50
 rc=crf mbtree=1 crf=19.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:0.80
Output #0, matroska, to 'output2.mkv':
  Metadata:
    encoder         : Lavf56.9.100
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 720x404 [SAR 404:405 DAR 16:9], q=-1--1, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.4.101 libx264
    Stream #0:1(mul): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 384 kb/s
    Metadata:
      encoder         : Lavc56.4.101 ac3
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:6 -> #0:1 (ac3 (native) -> ac3 (native))
Press [q] to stop, [?] for help
[mpegts @ 0420e000] PES packet size mismatchtime=01:14:57.65 bitrate=1076.2kbits/s
[ac3 @ 055b6500] incomplete frame
frame=112493 fps=110 q=-1.0 Lsize=  591301kB time=01:15:00.80 bitrate=1076.2kbits/s
video:378608kB audio:210918kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.301056%
[libx264 @ 05469e80] frame I:958   Avg QP:15.73  size: 33004
[libx264 @ 05469e80] frame P:30266 Avg QP:18.51  size:  7312
[libx264 @ 05469e80] frame B:81269 Avg QP:21.13  size:  1658
[libx264 @ 05469e80] consecutive B-frames:  1.7%  2.9%  9.3% 86.1%
[libx264 @ 05469e80] mb I  I16..4: 11.9% 64.1% 24.0%
[libx264 @ 05469e80] mb P  I16..4:  2.0%  4.7%  1.2%  P16..4: 41.1% 17.5% 11.5%  0.0%  0.0%    skip:21.9%
[libx264 @ 05469e80] mb B  I16..4:  0.1%  0.2%  0.1%  B16..8: 32.9%  4.2%  0.9%  direct: 2.1%  skip:59.3%  L0:40.9% L1:49.1% BI:10.1%
[libx264 @ 05469e80] 8x8 transform intra:59.3% inter:75.6%
[libx264 @ 05469e80] direct mvs  spatial:100.0% temporal:0.0%
[libx264 @ 05469e80] coded y,uvDC,uvAC intra: 59.2% 66.8% 38.5% inter: 13.5% 17.0% 1.1%
[libx264 @ 05469e80] i16 v,h,dc,p: 46% 21%  9% 25%
[libx264 @ 05469e80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18%  9% 15%  8% 11% 12% 10% 10%  9%
[libx264 @ 05469e80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28%  9%  6%  7% 11% 12% 10%  9%  9%
[libx264 @ 05469e80] i8c dc,h,v,p: 42% 23% 24% 11%
[libx264 @ 05469e80] Weighted P-Frames: Y:2.0% UV:0.8%
[libx264 @ 05469e80] ref P L0: 53.5% 10.7% 19.6%  8.4%  7.1%  0.7%  0.0%
[libx264 @ 05469e80] ref B L0: 80.3% 13.2%  4.5%  2.0%
[libx264 @ 05469e80] ref B L1: 95.8%  4.2%
[libx264 @ 05469e80] kb/s:689.28

It seems to need the -map 0:v switch or it won't encode the video stream. I've tested your command line with multiple files and it seems to work like a charm. I'll test some more later but for your assistance I offer you a big virtual cup of coffee and my thanks. However, it's still strange why separate encoding of video and audio would result in this delay.

Cheerio!
Reply | Threaded
Open this post in threaded view
|

Re: Automatic encoding of .ts files gives an inexplicable delay after muxing

Francois Visagie
> -----Original Message-----
> From: [hidden email] [mailto:ffmpeg-user-
> [hidden email]] On Behalf Of marsupilami
> Sent: 24 October 2014 11:28
> To: [hidden email]
> Subject: Re: [FFmpeg-user] Automatic encoding of .ts files gives an
> inexplicable delay after muxing
>
> Carl Eugen Hoyos wrote
> > marsupilami
> > <streamin <at>
> >  elitemail.org> writes:
> >
> > What's wrong with the following?
> > $ ffmpeg -i file.ts -vf yadif -vcodec libx264 -acodec ac3 out.mkv (You
> > have to add the remaining options you need.)
>
> The main reason why I didn't try this sooner was because I was worried
> ffmpeg wouldn't include the latest version of x264 or it would maybe be
too
> slow. However after trying out your command line I realised I was wrong
and
> maybe I was thinking too complex when there was a cleaner and simpler
> solution available.
>
> Encoding with my command line produces the following output:
>
> E:\enc>ffmpeg -ss 00:00:10 -i input.ts -vf "framestep=2,scale=720x404"
> -sws_flags lanczos -f yuv4mpegpipe -pix_fmt yuv420p - | x264_64.exe
--stdin
> y4m --level 3.1 --preset slow --crf 19.0 --deblo ck -2:-2 --aq-strength
0.8 --sar
> 1:1 --output output.mkv - ffmpeg version N-66742-gf6777ce Copyright (c)
> 2000-2014 the FFmpeg developers
>   built on Oct  8 2014 22:01:47 with gcc 4.9.1 (GCC)
>   configuration: --enable-gpl --enable-version3 --disable-w32threads --
> enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r
--enable-
> gnutls --enable-iconv --enable-libass --enable-libblu ray --enable-libbs2b
--
> enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --
> enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-
> libopencore-amrnb --enable-libopencore-amrw b --enable-libopenjpeg --
> enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr
--
> enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab
-

> -enable-libvo-aacenc -- enable-libvo-amrwbenc --enable-libvorbis --enable-
> libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-
> libx265 --enable-libxavs --enable-libxvid --enable-zlib
>   libavutil      54. 10.100 / 54. 10.100
>   libavcodec     56.  4.101 / 56.  4.101
>   libavformat    56.  9.100 / 56.  9.100
>   libavdevice    56.  1.100 / 56.  1.100
>   libavfilter     5.  1.103 /  5.  1.103
>   libswscale      3.  1.100 /  3.  1.100
>   libswresample   1.  1.100 /  1.  1.100
>   libpostproc    53.  1.100 / 53.  1.100
> [h264 @ 029df000] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 029df000] decode_slice_header error
> [h264 @ 029df000] no frame!
> [h264 @ 029df000] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 029df000] decode_slice_header error
> [h264 @ 029df000] no frame!
> [h264 @ 029df000] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 029df000] decode_slice_header error
> [h264 @ 029df000] no frame!
> [h264 @ 029df000] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 029df000] decode_slice_header error
> [h264 @ 029df000] no frame!
> [h264 @ 029df000] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 029df000] decode_slice_header error
> [h264 @ 029df000] no frame!
> [h264 @ 029df000] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 029df000] decode_slice_header error
> [h264 @ 029df000] no frame!
> [NULL @ 0426d300] start time for stream 8 is not set in
> estimate_timings_from_pts [mpegts @ 0426e300] PES packet size mismatch
>     Last message repeated 3 times
> [mpegts @ 0426e300] Could not find codec parameters for stream 0
> (Unknown:
> none ([5][0][0][0] / 0x0005)): unknown codec Consider increasing the value
> for the 'analyzeduration' and 'probesize'
> options
> [mpegts @ 0426e300] PES packet size mismatch
>     Last message repeated 10 times
> Input #0, mpegts, from 'input.ts':
>   Duration: 01:15:01.04, start: 42121.255633, bitrate: 10866 kb/s
>   Program 10301
>   Program 10302
>     Stream #0:0[0x4f6]: Unknown: none ([5][0][0][0] / 0x0005)
>     Stream #0:1[0x13f7]: Video: h264 (High) ([27][0][0][0] / 0x001B),
yuv420p,
> 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
>     Stream #0:2[0x13f8](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000
Hz,
> stereo, s16p, 190 kb/s
>     Stream #0:3[0x13f9](fra): Audio: mp2 ([3][0][0][0] / 0x0003), 48000
Hz,
> stereo, s16p, 190 kb/s
>     Stream #0:4[0x13fa](deu): Subtitle: dvb_teletext ([6][0][0][0] /
0x0006)
>     Stream #0:5[0x13fb](deu): Subtitle: dvb_subtitle ([6][0][0][0] /
0x0006)
> (hearing impaired)
>     Stream #0:6[0x13fc](mul): Audio: ac3 ([6][0][0][0] / 0x0006), 48000
Hz,
> 5.1(side), fltp, 448 kb/s
>     Stream #0:7[0x13fd](mis): Audio: mp2 ([3][0][0][0] / 0x0003), 48000
Hz,
> stereo, s16p, 190 kb/s
>     Stream #0:8[0x13fe](fra): Subtitle: dvb_subtitle ([6][0][0][0] /
0x0006)
>     Stream #0:9[0x13ff](deu): Subtitle: dvb_subtitle ([6][0][0][0] /
0x0006)
>   Program 10303
>   Program 10304
> Output #0, yuv4mpegpipe, to 'pipe:':
>   Metadata:
>     encoder         : Lavf56.9.100
>     Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 720x404
[SAR
> 404:405 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
>     Metadata:
>       encoder         : Lavc56.4.101 rawvideo
> Stream mapping:
>   Stream #0:1 -> #0:0 (h264 (native) -> rawvideo (native)) Press [q] to
stop,

> [?] for help [yuv4mpegpipe @ 05140060] Encoder did not produce proper
> pts, making some up.
> y4m [info]: 720x404p 404:405 @ 25/1 fps (cfr)
> x264 [info]: using SAR=1/1
> x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2
> FMA3 LZCNT BMI2
> x264 [info]: profile High, level 3.1
> frame=112275 fps=121 q=0.0 Lsize=47840334kB time=01:14:51.00
> bitrate=87265.2kbits/s dup=14 drop=0 video:7017kB audio:0kB subtitle:0kB
> other streams:0kB global headers:0kB muxing overhead: 681659.375000%
> x264 [info]: frame I:954   Avg QP:15.72  size: 32986
> x264 [info]: frame P:30208 Avg QP:18.51  size:  7304
> x264 [info]: frame B:81113 Avg QP:21.12  size:  1656
> x264 [info]: consecutive B-frames:  1.7%  2.9%  9.3% 86.1%
> x264 [info]: mb I  I16..4: 11.9% 64.1% 24.0%
> x264 [info]: mb P  I16..4:  2.0%  4.7%  1.2%  P16..4: 41.1% 17.5% 11.5%
> 0.0%  0.0%    skip:22.0%
> x264 [info]: mb B  I16..4:  0.1%  0.3%  0.1%  B16..8: 32.9%  4.2%  0.9%
> direct: 2.1%  skip:59.4%  L0:40.8% L1:49.1% BI:10.0%
> x264 [info]: 8x8 transform intra:59.6% inter:75.6%
> x264 [info]: direct mvs  spatial:100.0% temporal:0.0%
> x264 [info]: coded y,uvDC,uvAC intra: 59.1% 66.7% 38.4% inter: 13.5% 16.9%
> 1.1%
> x264 [info]: i16 v,h,dc,p: 46% 21%  9% 25%
> x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18%  9% 15%  8% 11% 12% 10%
10%
> 9%
> x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29%  9%  5%  7% 11% 12% 10%
9%

> 9%
> x264 [info]: i8c dc,h,v,p: 42% 23% 24% 11%
> x264 [info]: Weighted P-Frames: Y:2.0% UV:0.8%
> x264 [info]: ref P L0: 53.6% 10.7% 19.6%  8.4%  7.1%  0.7%  0.0%
> x264 [info]: ref B L0: 80.3% 13.2%  4.5%  1.9%
> x264 [info]: ref B L1: 95.8%  4.2%
> x264 [info]: kb/s:688.38
>
> encoded 112275 frames, 121.31 fps, 688.39 kb/s
>
> For the sake of speed I omitted the -re switch.
>
> Audio encoding produces this output:
>
> E:\enc>ffmpeg -ss 00:00:10 -i input.ts -map 0:6 -b:a 384k output.ac3
ffmpeg
> version N-66742-gf6777ce Copyright (c) 2000-2014 the FFmpeg developers
>   built on Oct  8 2014 22:01:47 with gcc 4.9.1 (GCC)
>   configuration: --enable-gpl --enable-version3 --disable-w32threads --
> enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r
--enable-
> gnutls --enable-iconv --enable-libass --enable-libblu ray --enable-libbs2b
--
> enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --
> enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-
> libopencore-amrnb --enable-libopencore-amrw b --enable-libopenjpeg --
> enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr
--
> enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab
-

> -enable-libvo-aacenc -- enable-libvo-amrwbenc --enable-libvorbis --enable-
> libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-
> libx265 --enable-libxavs --enable-libxvid --enable-zlib
>   libavutil      54. 10.100 / 54. 10.100
>   libavcodec     56.  4.101 / 56.  4.101
>   libavformat    56.  9.100 / 56.  9.100
>   libavdevice    56.  1.100 / 56.  1.100
>   libavfilter     5.  1.103 /  5.  1.103
>   libswscale      3.  1.100 /  3.  1.100
>   libswresample   1.  1.100 /  1.  1.100
>   libpostproc    53.  1.100 / 53.  1.100
> [h264 @ 0412b620] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 0412b620] decode_slice_header error
> [h264 @ 0412b620] no frame!
> [h264 @ 0412b620] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 0412b620] decode_slice_header error
> [h264 @ 0412b620] no frame!
> [h264 @ 0412b620] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 0412b620] decode_slice_header error
> [h264 @ 0412b620] no frame!
> [h264 @ 0412b620] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 0412b620] decode_slice_header error
> [h264 @ 0412b620] no frame!
> [h264 @ 0412b620] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 0412b620] decode_slice_header error
> [h264 @ 0412b620] no frame!
> [h264 @ 0412b620] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 0412b620] decode_slice_header error
> [h264 @ 0412b620] no frame!
> [NULL @ 0410f820] start time for stream 8 is not set in
> estimate_timings_from_pts [mpegts @ 040fdf60] PES packet size mismatch
>     Last message repeated 3 times
> [mpegts @ 040fdf60] Could not find codec parameters for stream 0
> (Unknown:
> none ([5][0][0][0] / 0x0005)): unknown codec Consider increasing the value
> for the 'analyzeduration' and 'probesize'
> options
> [mpegts @ 040fdf60] PES packet size mismatch
>     Last message repeated 10 times
> Input #0, mpegts, from 'input.ts':
>   Duration: 01:15:01.04, start: 42121.255633, bitrate: 10866 kb/s
>   Program 10301
>   Program 10302
>     Stream #0:0[0x4f6]: Unknown: none ([5][0][0][0] / 0x0005)
>     Stream #0:1[0x13f7]: Video: h264 (High) ([27][0][0][0] / 0x001B),
yuv420p,
> 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
>     Stream #0:2[0x13f8](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000
Hz,
> stereo, s16p, 190 kb/s
>     Stream #0:3[0x13f9](fra): Audio: mp2 ([3][0][0][0] / 0x0003), 48000
Hz,
> stereo, s16p, 190 kb/s
>     Stream #0:4[0x13fa](deu): Subtitle: dvb_teletext ([6][0][0][0] /
0x0006)
>     Stream #0:5[0x13fb](deu): Subtitle: dvb_subtitle ([6][0][0][0] /
0x0006)
> (hearing impaired)
>     Stream #0:6[0x13fc](mul): Audio: ac3 ([6][0][0][0] / 0x0006), 48000
Hz,
> 5.1(side), fltp, 448 kb/s
>     Stream #0:7[0x13fd](mis): Audio: mp2 ([3][0][0][0] / 0x0003), 48000
Hz,
> stereo, s16p, 190 kb/s
>     Stream #0:8[0x13fe](fra): Subtitle: dvb_subtitle ([6][0][0][0] /
0x0006)
>     Stream #0:9[0x13ff](deu): Subtitle: dvb_subtitle ([6][0][0][0] /
0x0006)

>   Program 10303
>   Program 10304
> Output #0, ac3, to 'output.ac3':
>   Metadata:
>     encoder         : Lavf56.9.100
>     Stream #0:0(mul): Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
>     Metadata:
>       encoder         : Lavc56.4.101 ac3
> Stream mapping:
>   Stream #0:6 -> #0:0 (ac3 (native) -> ac3 (native)) Press [q] to stop,
[?] for

> help [mpegts @ 040fdf60] PES packet size mismatch4.0kbits/s
> [ac3 @ 04654440] incomplete frame
> size=  210456kB time=01:14:49.72 bitrate= 384.0kbits/s video:0kB
> audio:210456kB subtitle:0kB other streams:0kB global headers:0kB muxing
> overhead: 0.000000%
>
> Encoding with your provided command line (altered to match my needs)
> produces the following output:
>
> E:\enc>ffmpeg -i input.ts -vf "framestep=2,scale=720x404" -sws_flags
> lanczos -vcodec libx264 -map 0:v -preset slow -level 3.1 -crf 19 -sar 1:1
-
> deblock
> -2:-2 -aq-strength 0.8 -acodec ac3 -map 0:6  -b:a 384k output2.mkv ffmpeg
> version N-66742-gf6777ce Copyright (c) 2000-2014 the FFmpeg developers
>   built on Oct  8 2014 22:01:47 with gcc 4.9.1 (GCC)
>   configuration: --enable-gpl --enable-version3 --disable-w32threads --
> enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r
--enable-
> gnutls --enable-iconv --enable-libass --enable-libblu ray --enable-libbs2b
--
> enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --
> enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-
> libopencore-amrnb --enable-libopencore-amrw b --enable-libopenjpeg --
> enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr
--
> enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab
-

> -enable-libvo-aacenc -- enable-libvo-amrwbenc --enable-libvorbis --enable-
> libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-
> libx265 --enable-libxavs --enable-libxvid --enable-zlib
>   libavutil      54. 10.100 / 54. 10.100
>   libavcodec     56.  4.101 / 56.  4.101
>   libavformat    56.  9.100 / 56.  9.100
>   libavdevice    56.  1.100 / 56.  1.100
>   libavfilter     5.  1.103 /  5.  1.103
>   libswscale      3.  1.100 /  3.  1.100
>   libswresample   1.  1.100 /  1.  1.100
>   libpostproc    53.  1.100 / 53.  1.100
> [h264 @ 0423c600] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 0423c600] decode_slice_header error
> [h264 @ 0423c600] no frame!
> [h264 @ 0423c600] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 0423c600] decode_slice_header error
> [h264 @ 0423c600] no frame!
> [h264 @ 0423c600] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 0423c600] decode_slice_header error
> [h264 @ 0423c600] no frame!
> [h264 @ 0423c600] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 0423c600] decode_slice_header error
> [h264 @ 0423c600] no frame!
> [h264 @ 0423c600] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 0423c600] decode_slice_header error
> [h264 @ 0423c600] no frame!
> [h264 @ 0423c600] non-existing PPS 0 referenced
>     Last message repeated 1 times
> [h264 @ 0423c600] decode_slice_header error
> [h264 @ 0423c600] no frame!
> [NULL @ 02aaab40] start time for stream 8 is not set in
> estimate_timings_from_pts [mpegts @ 0420e000] PES packet size mismatch
>     Last message repeated 3 times
> [mpegts @ 0420e000] Could not find codec parameters for stream 0
> (Unknown:
> none ([5][0][0][0] / 0x0005)): unknown codec Consider increasing the value
> for the 'analyzeduration' and 'probesize'
> options
> Input #0, mpegts, from 'input.ts':
>   Duration: 01:15:01.04, start: 42121.255633, bitrate: 10866 kb/s
>   Program 10301
>   Program 10302
>     Stream #0:0[0x4f6]: Unknown: none ([5][0][0][0] / 0x0005)
>     Stream #0:1[0x13f7]: Video: h264 (High) ([27][0][0][0] / 0x001B),
yuv420p,
> 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
>     Stream #0:2[0x13f8](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000
Hz,
> stereo, s16p, 190 kb/s
>     Stream #0:3[0x13f9](fra): Audio: mp2 ([3][0][0][0] / 0x0003), 48000
Hz,
> stereo, s16p, 190 kb/s
>     Stream #0:4[0x13fa](deu): Subtitle: dvb_teletext ([6][0][0][0] /
0x0006)
>     Stream #0:5[0x13fb](deu): Subtitle: dvb_subtitle ([6][0][0][0] /
0x0006)
> (hearing impaired)
>     Stream #0:6[0x13fc](mul): Audio: ac3 ([6][0][0][0] / 0x0006), 48000
Hz,
> 5.1(side), fltp, 448 kb/s
>     Stream #0:7[0x13fd](mis): Audio: mp2 ([3][0][0][0] / 0x0003), 48000
Hz,
> stereo, s16p, 190 kb/s
>     Stream #0:8[0x13fe](fra): Subtitle: dvb_subtitle ([6][0][0][0] /
0x0006)
>     Stream #0:9[0x13ff](deu): Subtitle: dvb_subtitle ([6][0][0][0] /
0x0006)

>   Program 10303
>   Program 10304
> [libx264 @ 05469e80] using SAR=404/405
> [libx264 @ 05469e80] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
> AVX
> AVX2 FMA3 LZCNT BMI2
> [libx264 @ 05469e80] profile High, level 3.1
> [libx264 @ 05469e80] 264 - core 142 r2479 dd79a61 - H.264/MPEG-4 AVC
> codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options:
> cabac=1
> ref=5 deblock=1:-2:-2 analyse=0x3:0x113 me=umh su
> bme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1
> trellis=1
> 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2
> threads=12
> lookahead_threads=2 sliced_threads=0 nr=0 decimate=
> 1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3
> b_pyramid=2
> b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250
> keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=50  rc=crf
> mbtree=1 crf=19.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40
> aq=1:0.80
> Output #0, matroska, to 'output2.mkv':
>   Metadata:
>     encoder         : Lavf56.9.100
>     Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p,
720x404
> [SAR 404:405 DAR 16:9], q=-1--1, 25 fps, 1k tbn, 25 tbc
>     Metadata:
>       encoder         : Lavc56.4.101 libx264
>     Stream #0:1(mul): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz,
5.1(side), fltp,
> 384 kb/s
>     Metadata:
>       encoder         : Lavc56.4.101 ac3
> Stream mapping:
>   Stream #0:1 -> #0:0 (h264 (native) -> h264 (libx264))
>   Stream #0:6 -> #0:1 (ac3 (native) -> ac3 (native)) Press [q] to stop,
[?] for

> help [mpegts @ 0420e000] PES packet size mismatchtime=01:14:57.65
> bitrate=1076.2kbits/s
> [ac3 @ 055b6500] incomplete frame
> frame=112493 fps=110 q=-1.0 Lsize=  591301kB time=01:15:00.80
> bitrate=1076.2kbits/s video:378608kB audio:210918kB subtitle:0kB other
> streams:0kB global headers:0kB muxing overhead: 0.301056%
> [libx264 @ 05469e80] frame I:958   Avg QP:15.73  size: 33004
> [libx264 @ 05469e80] frame P:30266 Avg QP:18.51  size:  7312
> [libx264 @ 05469e80] frame B:81269 Avg QP:21.13  size:  1658
> [libx264 @ 05469e80] consecutive B-frames:  1.7%  2.9%  9.3% 86.1%
> [libx264 @ 05469e80] mb I  I16..4: 11.9% 64.1% 24.0%
> [libx264 @ 05469e80] mb P  I16..4:  2.0%  4.7%  1.2%  P16..4: 41.1% 17.5%
> 11.5%  0.0%  0.0%    skip:21.9%
> [libx264 @ 05469e80] mb B  I16..4:  0.1%  0.2%  0.1%  B16..8: 32.9%  4.2%
0.9%
> direct: 2.1%  skip:59.3%  L0:40.9% L1:49.1% BI:10.1%
> [libx264 @ 05469e80] 8x8 transform intra:59.3% inter:75.6%
> [libx264 @ 05469e80] direct mvs  spatial:100.0% temporal:0.0%
> [libx264 @ 05469e80] coded y,uvDC,uvAC intra: 59.2% 66.8% 38.5% inter:
> 13.5% 17.0% 1.1%
> [libx264 @ 05469e80] i16 v,h,dc,p: 46% 21%  9% 25%
> [libx264 @ 05469e80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18%  9% 15%  8% 11%
12%
> 10% 10%  9%
> [libx264 @ 05469e80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28%  9%  6%  7% 11%
12%

> 10%  9%  9%
> [libx264 @ 05469e80] i8c dc,h,v,p: 42% 23% 24% 11%
> [libx264 @ 05469e80] Weighted P-Frames: Y:2.0% UV:0.8%
> [libx264 @ 05469e80] ref P L0: 53.5% 10.7% 19.6%  8.4%  7.1%  0.7%  0.0%
> [libx264 @ 05469e80] ref B L0: 80.3% 13.2%  4.5%  2.0%
> [libx264 @ 05469e80] ref B L1: 95.8%  4.2%
> [libx264 @ 05469e80] kb/s:689.28
>
> It seems to need the -map 0:v switch or it won't encode the video stream.
> I've tested your command line with multiple files and it seems to work
like a
> charm. I'll test some more later but for your assistance I offer you a big
virtual
> cup of coffee and my thanks. However, it's still strange why separate
> encoding of video and audio would result in this delay.

From my experience I'd say it has to do with the piping. Although I encoded
to other formats, using piped inputs has introduced similar audio-video
offsets for me, but only with certain inputs.

>
> Cheerio!
>
>
>
> --
> View this message in context: http://ffmpeg-
> users.933282.n4.nabble.com/Automatic-encoding-of-ts-files-gives-an-
> inexplicable-delay-after-muxing-tp4667828p4667836.html
> Sent from the FFmpeg-users mailing list archive at Nabble.com.
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Automatic encoding of .ts files gives an inexplicable delay after muxing

Carl Eugen Hoyos
In reply to this post by marsupilami
marsupilami <streamin <at> elitemail.org> writes:

> The main reason why I didn't try this sooner was
> because I was worried ffmpeg wouldn't include
> the latest version of x264

It is entirely up to you which version of x264 you
use when you compile FFmpeg (remember that the
project FFmpeg only ships source code and only
supports the source code).

> or it would maybe be too slow.

Video encoding is exactly as fast as x264 allows
(with your compilation options and your runtime
options), overall speed is of course faster if
you don't use separate encodings.

Carl Eugen

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Automatic encoding of .ts files gives an inexplicable delay after muxing

Henk D. Schoneveld
In reply to this post by marsupilami

On 23 Oct 2014, at 19:13, marsupilami <[hidden email]> 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
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

signature.asc (859 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Automatic encoding of .ts files gives an inexplicable delay after muxing

marsupilami
So most things work alright now. But I'd like to have the "Encoding Settings" header back in my mkv files like the standalone x264 adds them - ffmpeg's muxer doesn't seem to do that. What would I have to do to fix that? I've tried ffmpeg's -metadata option, but it doesn't work like I want it to.
Reply | Threaded
Open this post in threaded view
|

Re: Automatic encoding of .ts files gives an inexplicable delay after muxing

Moritz Barsnick
On Mon, Oct 27, 2014 at 09:36:57 -0700, marsupilami wrote:
> So most things work alright now. But I'd like to have the "Encoding Settings"
> header back in my mkv files like the standalone x264 adds them - ffmpeg's
> muxer doesn't seem to do that. What would I have to do to fix that? I've
> tried ffmpeg's -metadata option, but it doesn't work like I want it to.

Oh, I think it's in there somewhere, because mediainfo kindly displays
it.

File created with:

$ ffmpeg -f lavfi -i testsrc -c:v libx264 -t 3 /tmp/test.mkv

and checked with mediainfo:

$ mediainfo /tmp/test.mkv | grep -E "Encoding|Writing"
Writing application                      : Lavf56.9.100
Writing library                          : Lavf56.9.100
Writing library                          : x264 core 142
Encoding settings                        : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=4 / threads=3 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00

(Sorry, I couldn't tickle that info out of ffprobe, nor find it in the
metadata displayed by ffmpeg.)

Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Automatic encoding of .ts files gives an inexplicable delay after muxing

marsupilami
Now I've had some time to test this issue more extensively and you're right, the header really is there. However after encoding I'm using mkvmerge to cut (split) the file so only the parts I want will be there in the final mkv. This all condenses down to one problem:

mkvmerge (as well as ffmpeg) in cutting mode does not read all headers that are included in the mkv file and includes them in the cut mkv file - so the encoding settings header gets lost if I'm not cutting from the beginning from the file but from somewhere in let's say the first quarter. It seems somewhat logical that the two tools don't do that, but it's very unfortunate for me since I would like to preserve this header in the final mkv file that comes out after cutting.

I've read some man pages and tested extracting the tags of the uncut file (where the "encoding settings" header is still intact) with mkvextract, but unfortunately it doesn't show it - neither does mkvinfo. Only mediainfo shows the "encoding settings" tag in the uncut file.

Any ideas how I could extract this tag somehow from the uncut file and put it back into the cut file (preferrably with ffmpeg)?
Reply | Threaded
Open this post in threaded view
|

Re: Automatic encoding of .ts files gives an inexplicable delay after muxing

Francois Visagie
> -----Original Message-----
> From: [hidden email] [mailto:ffmpeg-user-
> [hidden email]] On Behalf Of marsupilami
> Sent: 30 October 2014 10:34
> To: [hidden email]
> Subject: Re: [FFmpeg-user] Automatic encoding of .ts files gives an
> inexplicable delay after muxing
>
> Now I've had some time to test this issue more extensively and you're
right,
> the header really is there. However after encoding I'm using mkvmerge to
> cut
> (split) the file so only the parts I want will be there in the final mkv.
> This all condenses down to one problem:
>
> mkvmerge (as well as ffmpeg) in cutting mode does not read all headers
that
> are included in the mkv file and includes them in the cut mkv file - so
the
> encoding settings header gets lost if I'm not cutting from the beginning
from
> the file but from somewhere in let's say the first quarter. It seems
somewhat
> logical that the two tools don't do that, but it's very unfortunate for me
since
> I would like to preserve this header in the final mkv file that comes out
after
> cutting.
>
> I've read some man pages and tested extracting the tags of the uncut file
> (where the "encoding settings" header is still intact) with mkvextract,
but
> unfortunately it doesn't show it - neither does mkvinfo. Only mediainfo
> shows the "encoding settings" tag in the uncut file.
>
> Any ideas how I could extract this tag somehow from the uncut file and put
it
> back into the cut file (preferrably with ffmpeg)?

Unfortunately you don't include previous discussions, but have you tried
ffprobe for that purpose?

>
>
> --
> View this message in context: http://ffmpeg-
> users.933282.n4.nabble.com/Automatic-encoding-of-ts-files-gives-an-
> inexplicable-delay-after-muxing-tp4667828p4667936.html
> Sent from the FFmpeg-users mailing list archive at Nabble.com.
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Automatic encoding of .ts files gives an inexplicable delay after muxing

marsupilami
Yes, I tried ffprobe as well, it doesn't show the tag. No program I tried so far shows it (tried mkvinfo, Media Player Classic, ffprobe, ffmpeg -i, mkvextract, mkvpropedit) except for mediainfo. I found a workaround though: parse the mediainfo output, generate a tags.xml file with a script and add it to the cut mkv file with mkvmerge --tracks 0:tags.xml. I feel dirty doing this, but I didn't find any other way. It's probably not the best option. When I find the time to do so, I'll dig around in the matroska specifications and/or the x264 source code to see how they accomplish this.