Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#2185 closed defect (wontfix)

Select filter cannot seek to a point in the video

Reported by: evilsoup Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords: select
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

As per the documentation, using a line like:

filter:v 'select=gte(t\,12)'

...should output video starting at the 12th second, akin to using -ss 12 as an output option.

However, when used in the following command, on a 30-second clip of Big Buck Bunny (so I would expect to end up with an 18-second clip, starting at a point 12 seconds into the input:

 ffmpeg -y -i test_BBB.mp4 -filter:v 'select=gte(t\,12)' -c:v libx264 -preset veryfast -an test_BBB-t12c.mp4

...but instead, it gives me a 30-second clip (the same length as the input), but with the first frame that should be displayed (the frame at 12 seconds into the video) being displayed all throughout the first twelve seconds - and then the video proceeds as would be expected.

Obviously, the example I'm using here is a trivial usage of select, where -ss would be a better option; but this behaviour also affects complex filtergraphs.

The aselect audio filter doesn't suffer from the same problem, it behaves exactly as would be expected.

It reports no errors, but for the record here's the terminal output of my command above:

ffmpeg version git-2012-12-18-b7e085a Copyright (c) 2000-2012 the FFmpeg developers
  built on Dec 20 2012 11:44:19 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libfaac --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-x11grab --enable-libx264 --enable-nonfree --enable-version3 --enable-libass
  libavutil      52. 12.100 / 52. 12.100
  libavcodec     54. 80.100 / 54. 80.100
  libavformat    54. 49.102 / 54. 49.102
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 28.100 /  3. 28.100
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_BBB.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : Big Buck Bunny
    artist          : Blender Foundation
    composer        : Blender Foundation
    date            : 2008
    encoder         : Lavf54.49.102
  Duration: 00:00:30.02, start: 0.000000, bitrate: 858 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 320x180 [SAR 1:1 DAR 16:9], 694 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 160 kb/s
    Metadata:
      handler_name    : SoundHandler
[libx264 @ 0x9f5e7a0] using SAR=1/1
[libx264 @ 0x9f5e7a0] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64 SlowCTZ SlowAtom
[libx264 @ 0x9f5e7a0] profile High, level 1.2
[libx264 @ 0x9f5e7a0] 264 - core 129 r2 1cffe9f - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 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=1 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'test_BBB-t12c.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : Big Buck Bunny
    artist          : Blender Foundation
    composer        : Blender Foundation
    date            : 2008
    encoder         : Lavf54.49.102
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 320x180 [SAR 1:1 DAR 16:9], q=-1--1, 12288 tbn, 24 tbc
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> libx264)
Press [q] to stop, [?] for help
frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=   0.0kbits/s    
frame=  290 fps=202 q=28.0 size=      37kB time=00:00:11.29 bitrate=  27.2kbits/s dup=288 drop=0    
frame=  348 fps=179 q=28.0 size=      87kB time=00:00:13.70 bitrate=  52.0kbits/s dup=288 drop=0    
frame=  397 fps=161 q=28.0 size=     151kB time=00:00:15.75 bitrate=  78.4kbits/s dup=288 drop=0    
frame=  466 fps=157 q=28.0 size=     178kB time=00:00:18.62 bitrate=  78.5kbits/s dup=288 drop=0    
frame=  529 fps=153 q=28.0 size=     210kB time=00:00:21.25 bitrate=  80.8kbits/s dup=288 drop=0    
frame=  593 fps=149 q=28.0 size=     249kB time=00:00:23.91 bitrate=  85.2kbits/s dup=288 drop=0    
frame=  636 fps=142 q=28.0 size=     298kB time=00:00:25.70 bitrate=  94.9kbits/s dup=288 drop=0    
frame=  685 fps=137 q=28.0 size=     350kB time=00:00:27.75 bitrate= 103.2kbits/s dup=288 drop=0    
frame=  720 fps=131 q=28.0 Lsize=     414kB time=00:00:29.91 bitrate= 113.3kbits/s dup=288 drop=0    
video:406kB audio:0kB subtitle:0 global headers:0kB muxing overhead 1.971170%
[libx264 @ 0x9f5e7a0] frame I:4     Avg QP:21.22  size: 15216
[libx264 @ 0x9f5e7a0] frame P:341   Avg QP:25.16  size:   982
[libx264 @ 0x9f5e7a0] frame B:375   Avg QP:29.70  size:    51
[libx264 @ 0x9f5e7a0] consecutive B-frames: 28.2%  3.3% 11.2% 57.2%
[libx264 @ 0x9f5e7a0] mb I  I16..4:  4.2%  5.9% 89.9%
[libx264 @ 0x9f5e7a0] mb P  I16..4:  0.2%  0.3%  0.2%  P16..4: 33.6%  7.2%  5.1%  0.0%  0.0%    skip:53.5%
[libx264 @ 0x9f5e7a0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  1.5%  0.6%  0.1%  direct: 0.5%  skip:97.1%  L0:27.4% L1:41.2% BI:31.5%
[libx264 @ 0x9f5e7a0] 8x8 transform intra:19.0% inter:25.0%
[libx264 @ 0x9f5e7a0] coded y,uvDC,uvAC intra: 73.4% 85.2% 65.9% inter: 10.2% 5.4% 1.1%
[libx264 @ 0x9f5e7a0] i16 v,h,dc,p: 22% 43% 24% 11%
[libx264 @ 0x9f5e7a0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 48% 28%  1%  1%  2%  1%  2%  3%
[libx264 @ 0x9f5e7a0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 17% 16%  6%  8%  7%  9%  7% 10%
[libx264 @ 0x9f5e7a0] i8c dc,h,v,p: 49% 24% 15% 11%
[libx264 @ 0x9f5e7a0] Weighted P-Frames: Y:1.5% UV:0.0%
[libx264 @ 0x9f5e7a0] kb/s:110.62

Attachments (2)

test_BBB.mp4 (2.5 MB ) - added by evilsoup 11 years ago.
test_BBB-t12c.mp4 (413.8 KB ) - added by evilsoup 11 years ago.
The output

Change History (9)

by evilsoup, 11 years ago

Attachment: test_BBB.mp4 added

by evilsoup, 11 years ago

Attachment: test_BBB-t12c.mp4 added

The output

comment:1 by Carl Eugen Hoyos, 11 years ago

Keywords: video filter removed

in reply to:  description ; comment:2 by Stefano Sabatini, 11 years ago

Replying to evilsoup:

As per the documentation, using a line like:

filter:v 'select=gte(t\,12)'

...should output video starting at the 12th second, akin to using -ss 12 as an output option.

However, when used in the following command, on a 30-second clip of Big Buck Bunny (so I would expect to end up with an 18-second clip, starting at a point 12 seconds into the input:

 ffmpeg -y -i test_BBB.mp4 -filter:v 'select=gte(t\,12)' -c:v libx264 -preset veryfast -an test_BBB-t12c.mp4

...but instead, it gives me a 30-second clip (the same length as the input), but with the first frame that should be displayed (the frame at 12 seconds into the video) being displayed all throughout the first twelve seconds - and then the video proceeds as would be expected.

[...]

I suspect this issue is not related at all with select, but depends either on ffmpeg or on the mp4 muxer. Try to play with the -copyts and -vsync options and report if that fixes the problem.

in reply to:  2 comment:3 by evilsoup, 11 years ago

Replying to saste:

I suspect this issue is not related at all with select, but depends either on ffmpeg or on the mp4 muxer. Try to play with the -copyts and -vsync options and report if that fixes the problem.

Actually, I've found that using the setpts filter solved this issue - it seems that select doesn't reset the timestamp on the video.

filter:v 'select=gte(t\,14),setpts=PTS-STARTPTS'

However, based on your comment I've tested it using an MKV output... and it played fine in ffplay (even without using setpts)! So I think that you are right - this is an issue with the MP4 container. However, ffplay starts playing with the timestamp starting at 14.00; and I just tested, and not using setpts caused issues with a complex filtergraph (involving concat), so I'll stick to appending setpts whenever I use select (and asetpts for each aselect).

I don't know if this is the intended behaviour or what, but it really seems like a bug.

comment:4 by Elon Musk, 11 years ago

Resolution: invalid
Status: newclosed

As name says select filter select something, it should not modify anything it selects.

in reply to:  4 ; comment:5 by evilsoup, 11 years ago

Resolution: invalid
Status: closedreopened

Replying to richardpl:

As name says select filter select something, it should not modify anything it selects.

The documentation says:

Select frames to pass in output.

...which would lead me to believe that 'select these frames --> send to the encoder' should work. So either the documentation is misleading, or the select filter doesn't work as it should. Or I'm just being dense, but in that case I would appreciate an explanation of what the select filter is for, if not for uses like this.

comment:6 by Elon Musk, 11 years ago

Resolution: wontfix
Status: reopenedclosed

Please do not make your own interpretation out of documentation. Select filter can not and should not seek in video because it is filter. It filters its input. Select filter filters its input by selecting frames by some parameters. If you need to modify timestamps for some other reason you use additional filter.

If you think documentation is misleading please help to improve it by saying what should be changed.

Last edited 11 years ago by Elon Musk (previous) (diff)

in reply to:  5 comment:7 by Cigaes, 11 years ago

What you are missing is that frames are not just images, they have additional information, and in particular a timestamp. The select filter selects frames, but it does not change them. If you use it to remove five minutes of video, the timestamps will still show the five minutes gap, and the muxer will take it into consideration while maintaining A-V sync, and a player should take it into account too. This is the expected behaviour.

Note: See TracTickets for help on using tickets.