VideoHelp Forum
+ Reply to Thread
Results 1 to 10 of 10
Thread
  1. Member
    Join Date
    Jul 2014
    Location
    Denmark
    Search Comp PM
    I'm working on some new features for FFQueue, but I've come to a problem I cannot solve. It involves using the trim and concat filters to cut away parts of a file (video/audio). For testing I use a transport stream from my HD-recorder and it contains a mix of movie and commercials - commercials are in stereo, movie is in 6ch surround. I can cut pieces of either commercials or movie without problems. But if the cuts overlap the switch between movie and commercial ffmpeg hurls out a large number of "Non-monotonous DTS..." errors and eventually aborts the encoding:

    Code:
    ffmpeg version N-74751-gb54e03c Copyright (c) 2000-2015 the FFmpeg developers
      built with gcc 4.9.3 (GCC)
      configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --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-lzma --enable-decklink --enable-zlib
      libavutil      54. 31.100 / 54. 31.100
      libavcodec     56. 59.100 / 56. 59.100
      libavformat    56. 40.101 / 56. 40.101
      libavdevice    56.  4.100 / 56.  4.100
      libavfilter     5. 40.100 /  5. 40.100
      libswscale      3.  1.101 /  3.  1.101
      libswresample   1.  2.101 /  1.  2.101
      libpostproc    53.  3.100 / 53.  3.100
    Input #0, mpegts, from 'test.ts':
      Duration: 00:02:00.66, start: 1.400000, bitrate: 9970 kb/s
      Program 1 
        Metadata:
          service_name    : Service01
          service_provider: FFmpeg
        Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
        Stream #0:1[0x101](dan): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 384 kb/s
    File 'test.mp4' already exists. Overwrite ? [y/N] [libx264 @ 0000000003e75020] using SAR=1/1
    [libx264 @ 0000000003e75020] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
    [libx264 @ 0000000003e75020] profile High, level 3.1
    [libx264 @ 0000000003e75020] 264 - core 148 r2597 e86f3a1 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: 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=-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=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=20.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    Output #0, mp4, to 'test.mp4':
      Metadata:
        encoder         : Lavf56.40.101
        Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
        Metadata:
          encoder         : Lavc56.59.100 libx264
        Stream #0:1: Audio: ac3 ([165][0][0][0] / 0x00A5), 48000 Hz, stereo, fltp, 128 kb/s (default)
        Metadata:
          encoder         : Lavc56.59.100 ac3
    Stream mapping:
      Stream #0:0 (h264) -> scale
      Stream #0:1 (ac3) -> asplit
      concat -> Stream #0:0 (libx264)
      concat -> Stream #0:1 (ac3)
    Press [q] to stop, [?] for help
    frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A    
    frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A    
    frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A    
    frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A    
    frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A    
    frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A    
    frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A    
    frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A    
    frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A    
    frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A    
    frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A    
    frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A    
    frame=   46 fps=7.0 q=0.0 size=       0kB time=00:00:02.20 bitrate=   0.2kbits/s    
    frame=   72 fps= 10 q=25.0 size=     309kB time=00:00:03.25 bitrate= 776.2kbits/s    
    frame=  102 fps= 13 q=25.0 size=     585kB time=00:00:04.44 bitrate=1079.2kbits/s    
    frame=  125 fps= 15 q=25.0 size=     889kB time=00:00:04.98 bitrate=1460.8kbits/s    
    frame=  125 fps= 15 q=25.0 size=     889kB time=00:00:04.98 bitrate=1460.8kbits/s    
    frame=  145 fps= 16 q=25.0 size=    1083kB time=00:00:06.17 bitrate=1437.6kbits/s    
    frame=  174 fps= 18 q=25.0 size=    1380kB time=00:00:07.25 bitrate=1557.3kbits/s    
    frame=  212 fps= 21 q=25.0 size=    1614kB time=00:00:08.85 bitrate=1492.9kbits/s    
    frame=  243 fps= 23 q=25.0 size=    1803kB time=00:00:10.10 bitrate=1461.7kbits/s    
    Input stream #0:1 frame changed from rate:48000 fmt:fltp ch:2 chl:stereo to rate:48000 fmt:fltp ch:6 chl:5.1(side)
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505088, current: -256; changing to 505089. This may result in incorrect timestamps in the output file.
    ...
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505151, current: 96512; changing to 505152. This may result in incorrect timestamps in the output file.
    frame=  255 fps= 23 q=25.0 size=    1864kB time=00:00:10.55 bitrate=1446.4kbits/s dup=0 drop=50    
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505152, current: 98048; changing to 505153. This may result in incorrect timestamps in the output file.
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505153, current: 99584; changing to 505154. This may result in incorrect timestamps in the output file.
    ...
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505225, current: 210176; changing to 505226. This may result in incorrect timestamps in the output file.
    frame=  255 fps= 22 q=25.0 size=    1864kB time=00:00:10.55 bitrate=1446.2kbits/s dup=0 drop=119    
    frame=  255 fps= 21 q=25.0 size=    1864kB time=00:00:10.55 bitrate=1446.2kbits/s dup=0 drop=119    
    frame=  255 fps= 20 q=25.0 size=    1864kB time=00:00:10.55 bitrate=1446.2kbits/s dup=0 drop=119    
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505226, current: 211712; changing to 505227. This may result in incorrect timestamps in the output file.
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505227, current: 213248; changing to 505228. This may result in incorrect timestamps in the output file.
    ...
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505285, current: 302336; changing to 505286. This may result in incorrect timestamps in the output file.
    frame=  255 fps= 19 q=25.0 size=    1864kB time=00:00:10.55 bitrate=1446.0kbits/s dup=0 drop=157    
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505286, current: 303872; changing to 505287. This may result in incorrect timestamps in the output file.
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505287, current: 305408; changing to 505288. This may result in incorrect timestamps in the output file.
    ...
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505381, current: 449792; changing to 505382. This may result in incorrect timestamps in the output file.
    frame=  255 fps= 19 q=25.0 size=    1864kB time=00:00:10.56 bitrate=1445.7kbits/s dup=0 drop=244    
    frame=  255 fps= 18 q=25.0 size=    1864kB time=00:00:10.56 bitrate=1445.7kbits/s dup=0 drop=244    
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505382, current: 451328; changing to 505383. This may result in incorrect timestamps in the output file.
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505383, current: 452864; changing to 505384. This may result in incorrect timestamps in the output file.
    ...
    [mp4 @ 00000000049109e0] Non-monotonous DTS in output stream 0:1; previous: 505417, current: 505088; changing to 505418. This may result in incorrect timestamps in the output file.
    frame=  276 fps= 19 q=25.0 size=    1963kB time=00:00:10.97 bitrate=1466.0kbits/s dup=0 drop=253    
    frame=  309 fps= 20 q=25.0 size=    2094kB time=00:00:12.28 bitrate=1396.8kbits/s dup=0 drop=253    
    frame=  333 fps= 21 q=25.0 size=    2521kB time=00:00:13.24 bitrate=1559.5kbits/s dup=0 drop=253    
    frame=  356 fps= 22 q=25.0 size=    2763kB time=00:00:14.17 bitrate=1597.5kbits/s dup=0 drop=253    
    frame=  372 fps= 21 q=-1.0 Lsize=    3713kB time=00:00:14.80 bitrate=2055.1kbits/s dup=0 drop=253    
    video:3312kB audio:390kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.283109%
    [libx264 @ 0000000003e75020] frame I:5     Avg QP:15.45  size: 45853
    [libx264 @ 0000000003e75020] frame P:127   Avg QP:19.91  size: 17251
    [libx264 @ 0000000003e75020] frame B:240   Avg QP:21.92  size:  4044
    [libx264 @ 0000000003e75020] consecutive B-frames:  7.5% 15.1% 12.9% 64.5%
    [libx264 @ 0000000003e75020] mb I  I16..4: 14.6% 70.3% 15.1%
    [libx264 @ 0000000003e75020] mb P  I16..4:  3.4% 10.4%  1.7%  P16..4: 40.4% 15.0%  6.9%  0.0%  0.0%    skip:22.3%
    [libx264 @ 0000000003e75020] mb B  I16..4:  0.2%  0.5%  0.1%  B16..8: 34.6%  3.2%  0.5%  direct: 1.5%  skip:59.6%  L0:40.8% L1:55.2% BI: 4.1%
    [libx264 @ 0000000003e75020] 8x8 transform intra:67.3% inter:85.6%
    [libx264 @ 0000000003e75020] coded y,uvDC,uvAC intra: 54.5% 64.2% 29.2% inter: 15.1% 18.2% 0.9%
    [libx264 @ 0000000003e75020] i16 v,h,dc,p: 26% 46%  3% 25%
    [libx264 @ 0000000003e75020] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 18% 16%  5%  7%  9%  6%  9%  5%
    [libx264 @ 0000000003e75020] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 26% 11%  5%  7%  7%  5%  6%  3%
    [libx264 @ 0000000003e75020] i8c dc,h,v,p: 51% 25% 19%  6%
    [libx264 @ 0000000003e75020] Weighted P-Frames: Y:1.6% UV:1.6%
    [libx264 @ 0000000003e75020] ref P L0: 57.5% 11.9% 20.4% 10.2%  0.0%
    [libx264 @ 0000000003e75020] ref B L0: 86.0% 11.0%  3.0%
    [libx264 @ 0000000003e75020] ref B L1: 96.2%  3.8%
    [libx264 @ 0000000003e75020] kb/s:1822.88
    The test file is 2 minutes long, first minute are commercials, second minute is movie. This command works:

    Code:
    ffmpeg -i "test.ts" -map 0:0 -map 0:1 -filter_complex "[0:0]scale=1280:-1:flags=lanczos[FID1];[FID1]split=4[FID2][FID3][FID4][FID5];[FID2]trim=5:10,setpts=PTS-STARTPTS[FID6];[FID3]trim=15:20,setpts=PTS-STARTPTS[FID7];[FID4]trim=25:30,setpts=PTS-STARTPTS[FID8];[FID5]trim=35:40,setpts=PTS-STARTPTS[FID9];[FID6][FID7][FID8][FID9]concat=n=4:v=1:a=0;[0:1]asplit=4[FID10][FID11][FID12][FID13];[FID10]atrim=5:10,asetpts=PTS-STARTPTS[FID14];[FID11]atrim=15:20,asetpts=PTS-STARTPTS[FID15];[FID12]atrim=25:30,asetpts=PTS-STARTPTS[FID16];[FID13]atrim=35:40,asetpts=PTS-STARTPTS[FID17];[FID14][FID15][FID16][FID17]concat=n=4:v=0:a=1" -c:v libx264 -crf 20 -crf_max 35 -c:a ac3 -b:a 128k "test_ok_1.mp4"
    This command works:

    Code:
    ffmpeg -i "test.ts" -map 0:0 -map 0:1 -filter_complex "[0:0]scale=1280:-1:flags=lanczos[FID1];[FID1]split=4[FID2][FID3][FID4][FID5];[FID2]trim=65:70,setpts=PTS-STARTPTS[FID6];[FID3]trim=75:80,setpts=PTS-STARTPTS[FID7];[FID4]trim=85:90,setpts=PTS-STARTPTS[FID8];[FID5]trim=95:100,setpts=PTS-STARTPTS[FID9];[FID6][FID7][FID8][FID9]concat=n=4:v=1:a=0;[0:1]asplit=4[FID10][FID11][FID12][FID13];[FID10]atrim=65:70,asetpts=PTS-STARTPTS[FID14];[FID11]atrim=75:80,asetpts=PTS-STARTPTS[FID15];[FID12]atrim=85:90,asetpts=PTS-STARTPTS[FID16];[FID13]atrim=95:100,asetpts=PTS-STARTPTS[FID17];[FID14][FID15][FID16][FID17]concat=n=4:v=0:a=1" -c:v libx264 -crf 20 -crf_max 35 -c:a ac3 -b:a 128k "test_ok_2.mp4"
    This command fails:

    Code:
    ffmpeg -i "test.ts" -map 0:0 -map 0:1 -filter_complex "[0:0]scale=1280:-1:flags=lanczos[FID1];[FID1]split=4[FID2][FID3][FID4][FID5];[FID2]trim=45:50,setpts=PTS-STARTPTS[FID6];[FID3]trim=55:65,setpts=PTS-STARTPTS[FID7];[FID4]trim=75:80,setpts=PTS-STARTPTS[FID8];[FID5]trim=85:90,setpts=PTS-STARTPTS[FID9];[FID6][FID7][FID8][FID9]concat=n=4:v=1:a=0;[0:1]asplit=4[FID10][FID11][FID12][FID13];[FID10]atrim=45:50,asetpts=PTS-STARTPTS[FID14];[FID11]atrim=55:65,asetpts=PTS-STARTPTS[FID15];[FID12]atrim=75:80,asetpts=PTS-STARTPTS[FID16];[FID13]atrim=85:90,asetpts=PTS-STARTPTS[FID17];[FID14][FID15][FID16][FID17]concat=n=4:v=0:a=1" -c:v libx264 -crf 20 -crf_max 35 -c:a ac3 -b:a 128k "test_error.mp4"
    I've tried to fix the issue using any combination of "-copyts -copytb [0|1] -fflags +igndts+genpts (before and after -i)" and I've tried to insert "setpts=PTS-STARTPTS / asetpts=PTS-STARTPTS" at the beginning of the filter chain - but with no success.

    Is this a bug in ffmpeg (using latest zeranoe build) or is there a magic trick to get about this?

    Attachment contains test.ts, test.bat and ffmpeg_results.txt.
    I'm the developer behind FFQueue. My posts might reflect this! ;-)
    Quote Quote  
  2. Member
    Join Date
    Jul 2014
    Location
    Denmark
    Search Comp PM
    Sorry, forgot attachment
    Image Attached Files
    I'm the developer behind FFQueue. My posts might reflect this! ;-)
    Quote Quote  
  3. commercials are in stereo, movie is in 6ch surround.
    afaik that isn't a bug, but more a missing feature, like most tools ffmpeg can't deal with files where the audio stream changes the channel count.
    -> your best hope is to report this to the ffmpeg mailing list or bug tracker and hope that someone things this is worth spending time on.
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  4. Member
    Join Date
    Jul 2014
    Location
    Denmark
    Search Comp PM
    Originally Posted by Selur View Post
    afaik that isn't a bug, but more a missing feature, like most tools ffmpeg can't deal with files where the audio stream changes the channel count.
    -> your best hope is to report this to the ffmpeg mailing list or bug tracker and hope that someone things this is worth spending time on.
    Thanks for your reply! I've tried to homogenize the audio with by resampling it with a "aresample=flags=res: och=2" filter before performing the trim & concat but it did no change. Omitting the trim & concat with command:

    Code:
    ffmpeg.exe -ss 0:0:50 -i "test.ts" -map 0:0 -map 0:1 -filter_complex "[0:0]scale=1280:-1:flags=lanczos" -c:v libx264 -crf 20 -crf_max 35 -c:a ac3 -b:a 128k -t 0:0:20 "test.mp4"
    Produces no errors even though it processes two different audio streams. The output from ffmpeg suggests that the error is related to bad DTS (Decoder Time Stamps) and even if ffmpeg is told to ignore DTS and create new ones they cause problems. Weird..
    I'm the developer behind FFQueue. My posts might reflect this! ;-)
    Quote Quote  
  5. Did you look at the resulting stream and it's channel count?
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  6. Member
    Join Date
    Jul 2014
    Location
    Denmark
    Search Comp PM
    Originally Posted by Selur View Post
    Did you look at the resulting stream and it's channel count?
    Yep, converted to stereo! Adding "-ac 6" to the command will turn 2ch into 6ch and keep 6ch as it is. But it does nothing when added to the trim & concat commands.
    I'm the developer behind FFQueue. My posts might reflect this! ;-)
    Quote Quote  
  7. problem is that won't save the 5.1 signal, that would upmix the stereo channels of the 5.1 signal to 5.1
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  8. Member
    Join Date
    Jul 2014
    Location
    Denmark
    Search Comp PM
    You're probably right. For now I'll just suggest that users do not perform trims that overlap different audio layouts because it seems to be the cause of the issue. Just dumb to encode an hour of movie and then have the whole thing wrecked by one frame of bad audio - there should be a opt out for this!
    I'm the developer behind FFQueue. My posts might reflect this! ;-)
    Quote Quote  
  9. Just dumb to encode an hour of movie and then have the whole thing wrecked by one frame of bad audio - there should be a opt out for this!
    You could analyse your file beforehand to make sure you don't have such a file.
    Also be warned it's always a bad idea to feed such streams to ffmpeg, since it might do unexpected things. (for example drop all but the two side speakers of a 5.1 stream, crash when your first few frames have mono audio and later you get 5.1 audio,....)
    Just wondering: What to you use to set the cutting points? Are you aiming for frame accurate cutting?

    Cu Selur

    Ps.: Also cutting might cause problems if the video is vfr. (cutting normally doesn't crash, but the output can be async )
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  10. Member
    Join Date
    Jul 2014
    Location
    Denmark
    Search Comp PM
    Selur: As mentioned it's a new feature for FFQueue. There will be a GUI for setting the (time based) cuts and it works quite nice, actually! I've never had issues with ffmpeg and multichannel audio - but it seems ffmpeg can't handle changes in the audio stream layout. It almost seems like ffmpeg does not recognize the change in layout and continues to process the multichannel audio as if it was stereo. This obviously has to fail, lesson learned
    I'm the developer behind FFQueue. My posts might reflect this! ;-)
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!