[FFmpeg-trac] #2806(avfilter:open): Overlay filter with "shortest=1" drops last frame (was: Overlay filter with “shortest=1” drops last frame)

FFmpeg trac at avcodec.org
Thu Aug 29 18:31:13 CEST 2013


#2806: Overlay filter with "shortest=1" drops last frame
------------------------------------+------------------------------------
             Reporter:  hansmi      |                    Owner:
                 Type:  defect      |                   Status:  open
             Priority:  normal      |                Component:  avfilter
              Version:  git-master  |               Resolution:
             Keywords:              |               Blocked By:
             Blocking:              |  Reproduced by developer:  1
Analyzed by developer:  0           |
------------------------------------+------------------------------------
Changes (by richardpl):

 * status:  new => open
 * component:  undetermined => avfilter
 * version:  unspecified => git-master
 * reproduced:  0 => 1


Old description:

> Summary of the bug:
> Encoding a video using “overlay=shortest=1” in the filter chain will lead
> to the last frame being dropped.
>
> Using FFmpeg 1.2.1 installed using MacPorts:
> {{{
> $ ffmpeg
> ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
>   built on Jun 12 2013 13:46:11 with Apple clang version 4.1
> (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
>   configuration: --prefix=/opt/local --enable-swscale --enable-avfilter
> --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-
> libtheora --enable-libschroedinger --enable-libopenjpeg --enable-
> libmodplug --enable-libvpx --enable-libspeex --enable-libass --enable-
> libbluray --enable-gnutls --enable-libfreetype
> --mandir=/opt/local/share/man --enable-shared --enable-pthreads
> --cc=/usr/bin/clang --arch=x86_64 --enable-yasm --enable-gpl --enable-
> postproc --enable-libx264 --enable-libxvid
>   libavutil      52. 18.100 / 52. 18.100
>   libavcodec     54. 92.100 / 54. 92.100
>   libavformat    54. 63.104 / 54. 63.104
>   libavdevice    54.  3.103 / 54.  3.103
>   libavfilter     3. 42.103 /  3. 42.103
>   libswscale      2.  2.100 /  2.  2.100
>   libswresample   0. 17.102 /  0. 17.102
>   libpostproc    52.  2.100 / 52.  2.100
> […]
> }}}
>
> How to reproduce:
> {{{
> # Generate 30 input frames (requires ImageMagick)
> $ for i in {0..30}; do \
>   convert -alpha on -background none -fill red \
>     -pointsize 30  -size 200x200 -gravity center \
>     label:$i png32:frame_$(printf '%03d' $i).png; \
> done
>
> # Encode without overlay filter (you have to adjust the
> # font path if not testing on Mac OS X)
> $ ffmpeg -an \
> -f image2 -i 'frame_%03d.png' \
> -filter_complex "[0:v]
> drawtext=fontfile=/Library/Fonts/Arial.ttf:x=5:y=5:text='frame %{n}'
> [out]" \
> -map '[out]' \
> -vcodec mpeg4 -b:v 600k -flags +aic+mv4 \
> working.mp4
>
> # Encode with “overlay=shortest=1” (needed to stop encoding
> # when running out of input frames; adjust the font path
> # again)
> $ ffmpeg -an \
> -f image2 -i 'frame_%03d.png' \
> -f lavfi -i 'color=c=white:size=200x200' \
> -filter_complex "[1:v][0:v] overlay=shortest=1,
> drawtext=fontfile=/Library/Fonts/Arial.ttf:x=5:y=5:text='frame %{n}'
> [out]" \
> -map '[out]' \
> -vcodec mpeg4 -b:v 600k -flags +aic+mv4 \
> missingframe.mp4
> }}}
>
> Notice how the second version is missing a frame:
> {{{
> $ ffprobe -show_streams -loglevel quiet working.mp4 | grep -w nb_frames
> nb_frames=31
>
> $ ffprobe -show_streams -loglevel quiet missingframe.mp4 | grep -w
> nb_frames
> nb_frames=30
> }}}
>
> This can be confirmed by looking at the video. The frame number is
> encoded at the top left and is also reflected by the number encoded in
> the original PNG files.

New description:

 Summary of the bug:
 Encoding a video using "overlay=shortest=1" in the filter chain will lead
 to the last frame being dropped.

 Using FFmpeg 1.2.1 installed using MacPorts:
 {{{
 $ ffmpeg
 ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
   built on Jun 12 2013 13:46:11 with Apple clang version 4.1
 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
   configuration: --prefix=/opt/local --enable-swscale --enable-avfilter
 --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libtheora
 --enable-libschroedinger --enable-libopenjpeg --enable-libmodplug
 --enable-libvpx --enable-libspeex --enable-libass --enable-libbluray
 --enable-gnutls --enable-libfreetype --mandir=/opt/local/share/man
 --enable-shared --enable-pthreads --cc=/usr/bin/clang --arch=x86_64
 --enable-yasm --enable-gpl --enable-postproc --enable-libx264 --enable-
 libxvid
   libavutil      52. 18.100 / 52. 18.100
   libavcodec     54. 92.100 / 54. 92.100
   libavformat    54. 63.104 / 54. 63.104
   libavdevice    54.  3.103 / 54.  3.103
   libavfilter     3. 42.103 /  3. 42.103
   libswscale      2.  2.100 /  2.  2.100
   libswresample   0. 17.102 /  0. 17.102
   libpostproc    52.  2.100 / 52.  2.100
 [...]
 }}}

 How to reproduce:
 {{{
 # Generate 30 input frames (requires ImageMagick)
 $ for i in {0..30}; do \
   convert -alpha on -background none -fill red \
     -pointsize 30  -size 200x200 -gravity center \
     label:$i png32:frame_$(printf '%03d' $i).png; \
 done

 # Encode without overlay filter (you have to adjust the
 # font path if not testing on Mac OS X)
 $ ffmpeg -an \
 -f image2 -i 'frame_%03d.png' \
 -filter_complex "[0:v]
 drawtext=fontfile=/Library/Fonts/Arial.ttf:x=5:y=5:text='frame %{n}'
 [out]" \
 -map '[out]' \
 -vcodec mpeg4 -b:v 600k -flags +aic+mv4 \
 working.mp4

 # Encode with "overlay=shortest=1" (needed to stop encoding
 # when running out of input frames; adjust the font path
 # again)
 $ ffmpeg -an \
 -f image2 -i 'frame_%03d.png' \
 -f lavfi -i 'color=c=white:size=200x200' \
 -filter_complex "[1:v][0:v] overlay=shortest=1,
 drawtext=fontfile=/Library/Fonts/Arial.ttf:x=5:y=5:text='frame %{n}'
 [out]" \
 -map '[out]' \
 -vcodec mpeg4 -b:v 600k -flags +aic+mv4 \
 missingframe.mp4
 }}}

 Notice how the second version is missing a frame:
 {{{
 $ ffprobe -show_streams -loglevel quiet working.mp4 | grep -w nb_frames
 nb_frames=31

 $ ffprobe -show_streams -loglevel quiet missingframe.mp4 | grep -w
 nb_frames
 nb_frames=30
 }}}

 This can be confirmed by looking at the video. The frame number is encoded
 at the top left and is also reflected by the number encoded in the
 original PNG files.

--

Comment:

 ffmpeg -f lavfi -i color=black:hd720 -i in.png -lavfi overlay=shortest=1
 out.png

-- 
Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/2806#comment:3>
FFmpeg <http://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list