[FFmpeg-devel] [PATCH][RFC] variable frame sizes

Eric Buehl eric.buehl
Thu May 21 08:50:22 CEST 2009


On Wed, May 20, 2009 at 9:23 PM, Michael Niedermayer <michaelni at gmx.at>wrote:

> On Wed, May 20, 2009 at 12:17:22PM -0700, Eric Buehl wrote:
> > On Wed, May 20, 2009 at 6:12 AM, Michael Niedermayer <michaelni at gmx.at
> >wrote:
> >
> > > On Sat, May 16, 2009 at 11:07:58PM -0700, Eric Buehl wrote:
> > > > On Sat, May 16, 2009 at 9:40 PM, Eric Buehl <eric.buehl at gmail.com>
> > > wrote:
> > > >
> > > > > On Sat, May 16, 2009 at 2:40 AM, Michael Niedermayer <
> michaelni at gmx.at
> > > >wrote:
> > > > >
> > > > >> On Fri, May 15, 2009 at 09:47:00PM -0700, Eric Buehl wrote:
> > > > >> > On Fri, May 15, 2009 at 7:46 PM, Michael Niedermayer <
> > > michaelni at gmx.at
> > > > >> >wrote:
> > > > >> >
> > > > >> > > On Fri, May 15, 2009 at 04:44:14PM -0700, Eric Buehl wrote:
> > > > >> > > > On Fri, May 15, 2009 at 3:49 AM, Michael Niedermayer <
> > > > >> michaelni at gmx.at
> > > > >> > > >wrote:
> > > > >> > > >
> > > > >> > > > > On Thu, May 14, 2009 at 04:04:57PM -0700, Eric Buehl
> wrote:
> > > > >> > > > > > Hello,
> > > > >> > > > > >
> > > > >> > > > > > I submitted a bug a while back describing ffmpeg's
> failure
> > > to
> > > > >> account
> > > > >> > > for
> > > > >> > > > > > varying frame sizes in a single file.
> > > > >> > > > > > http://roundup.ffmpeg.org/roundup/ffmpeg/issue879  I
> have
> > > > >> confirmed
> > > > >> > > that
> > > > >> > > > > the
> > > > >> > > > > > sample referenced works as expected in mplayer so I do
> not
> > > > >> believe it
> > > > >> > > is
> > > > >> > > > > a
> > > > >> > > > > > problem with lavc/lavf.
> > > > >> > > > >
> > > > >> > > > > >  Attached is a patch that works for frames of
> > > > >> > > > > > varying height (possible if interlacing options are
> > > mis-used)
> > > > >> but it
> > > > >> > > does
> > > > >> > > > > > not account for changes in width.
> > > > >> > > > >
> > > > >> > > > > so its incomplete ...
> > > > >> > > > >
> > > > >> > > > > [...]
> > > > >> > > > >
> > > > >> > > > > >  ffmpeg.c |   20 ++++++++++++++++++++
> > > > >> > > > > >  1 file changed, 20 insertions(+)
> > > > >> > > > > > 726f5c891ba925ffb00806f43c935696105872ef
> > > > >> > > > >  dynamic_frame_height_adjust.patch
> > > > >> > > > > > Index: ffmpeg.c
> > > > >> > > > > >
> > > > >>
> ===================================================================
> > > > >> > > > > > --- ffmpeg.c  (revision 18831)
> > > > >> > > > > > +++ ffmpeg.c  (working copy)
> > > > >> > > > > > @@ -923,6 +923,26 @@
> > > > >> > > > > >      if (ost->video_resample) {
> > > > >> > > > > >          padding_src = NULL;
> > > > >> > > > > >          final_picture = &ost->pict_tmp;
> > > > >> > > > > > +     if(ost->resample_height != ist->st->codec->height)
> > > > >> > > > >
> > > > >> > > > > tabs and as this is under if (ost->video_resample)
> > > > >> > > > > i wonder if it works if thats false to begin with ...
> > > > >> > > > >
> > > > >> > > > >
> > > > >> > > > > > +        {
> > > > >> > > > >
> > > > >> > > > > inconsistant { placement
> > > > >> > > > >
> > > > >> > > > > [...]
> > > > >> > > > > --
> > > > >> > > > > Michael     GnuPG fingerprint:
> > > > >> 9FF2128B147EF6730BADF133611EC787040B0FAB
> > > > >> > > > >
> > > > >> > > > > Frequently ignored awnser#1 FFmpeg bugs should be sent to
> our
> > > > >> > > bugtracker.
> > > > >> > > > > User
> > > > >> > > > > questions about the command line tools should be sent to
> the
> > > > >> > > ffmpeg-user
> > > > >> > > > > ML.
> > > > >> > > > > And questions about how to use libav* should be sent to
> the
> > > > >> libav-user
> > > > >> > > ML.
> > > > >> > > > >
> > > > >> > > > > -----BEGIN PGP SIGNATURE-----
> > > > >> > > > > Version: GnuPG v1.4.9 (GNU/Linux)
> > > > >> > > > >
> > > > >> > > > >
> > > iD8DBQFKDUioYR7HhwQLD6sRAr9nAJ45hYRJiRqxjsz1xAAP+Svzqp+3EgCaA8pO
> > > > >> > > > > /DWK54Yie4eBCADbqVumAJM=
> > > > >> > > > > =R+EA
> > > > >> > > > > -----END PGP SIGNATURE-----
> > > > >> > > >
> > > > >> > > >
> > > > >> > > > > _______________________________________________
> > > > >> > > > > ffmpeg-devel mailing list
> > > > >> > > > > ffmpeg-devel at mplayerhq.hu
> > > > >> > > > > https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
> > > > >> > > > >
> > > > >> > > >
> > > > >> > > >
> > > > >> > > > Here is an updated patch.  I have add a more correct
> comparison
> > > > >> (which
> > > > >> > > > includes frame top/bottom bands) as well as formatting
> clean-up.
> > >  It
> > > > >> also
> > > > >> > > > checks for changes in width in the same fashion.
> > > > >> > >
> > > > >> > > i tried it with a 100x100 + 200x200 mpg concatenated, but it
> did
> > > not
> > > > >> work
> > > > >> > > just heavy artifacts
> > > > >> > >
> > > > >> > > [...]
> > > > >> > > --
> > > > >> > > Michael     GnuPG fingerprint:
> > > > >> 9FF2128B147EF6730BADF133611EC787040B0FAB
> > > > >> > >
> > > > >> > > Democracy is the form of government in which you can choose
> your
> > > > >> dictator
> > > > >> > >
> > > > >> > > -----BEGIN PGP SIGNATURE-----
> > > > >> > > Version: GnuPG v1.4.9 (GNU/Linux)
> > > > >> > >
> > > > >> > >
> iD8DBQFKDij0YR7HhwQLD6sRAuwRAJ4ycSjn8ajfMyHg7vXdC7fDg+U8lACeI5Pf
> > > > >> > > AeEgbvYibsIkk5TCybRYU9I=
> > > > >> > > =H+W4
> > > > >> > > -----END PGP SIGNATURE-----
> > > > >> > >
> > > > >> > > _______________________________________________
> > > > >> > > ffmpeg-devel mailing list
> > > > >> > > ffmpeg-devel at mplayerhq.hu
> > > > >> > > https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
> > > > >> > >
> > > > >> >
> > > > >> > I was not able to reproduce this as you describe with a 100x100
> mpg
> > > > >> catted
> > > > >> > with a 200x200 mpg.  Can you send me your test file and/or the
> steps
> > > to
> > > > >> > produce it?
> > > > >>
> > > > >> ./ffmpeg -i matrixbench_mpeg2.mpg -s 100x100 -t 1 m100100.mpg
> > > > >> ./ffmpeg -i matrixbench_mpeg2.mpg -s 200x200 -t 1 m200200.mpg
> > > > >> cat m100100.mpg m200200.mpg >m.mpg
> > > > >> ./ffmpeg -i m.mpg n.mpg
> > > > >>
> > > > >> [...]
> > > > >> --
> > > > >> Michael     GnuPG fingerprint:
> > > 9FF2128B147EF6730BADF133611EC787040B0FAB
> > > > >>
> > > > >> it is not once nor twice but times without number that the same
> ideas
> > > make
> > > > >> their appearance in the world. -- Aristotle
> > > > >>
> > > > >> -----BEGIN PGP SIGNATURE-----
> > > > >> Version: GnuPG v1.4.9 (GNU/Linux)
> > > > >>
> > > > >> iD8DBQFKDooGYR7HhwQLD6sRAkmKAKCHsxSw7rmBFAV+/aPZWNWd3tOOFACfeep/
> > > > >> M28rhl94MsvtPESLjNyDLgY=
> > > > >> =oNWX
> > > > >> -----END PGP SIGNATURE-----
> > > > >>
> > > > >> _______________________________________________
> > > > >> ffmpeg-devel mailing list
> > > > >> ffmpeg-devel at mplayerhq.hu
> > > > >> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
> > > > >>
> > > > >
> > > > >
> > > > > I understand now.  Correct, this does not touch the code path for
> the
> > > patch
> > > > > I have written because resampling is not explicitly requested by
> using
> > > the
> > > > > -s option.  However, the intent of this patch is only to ensure
> that
> > > when
> > > > > resamping is requested, the output meets the requested frame size.
>  The
> > > > > example you have given does not request resizing and I am not sure
> what
> > > the
> > > > > correct functionality should be in this case.  Is this suitable for
> > > > > integration as is?
> > > > >
> > > > > Eric
> > > > >
> > > > >
> > > > Here is another update to account for left and right banding.
> > >
> > > does the code also work if there are 2 or more video streams?
> > >
> > >
> > > [...]
> > > --
> > > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> > >
> > > Many that live deserve death. And some that die deserve life. Can you
> give
> > > it to them? Then do not be too eager to deal out death in judgement.
> For
> > > even the very wise cannot see all ends. -- Gandalf
> > >
> > > -----BEGIN PGP SIGNATURE-----
> > > Version: GnuPG v1.4.9 (GNU/Linux)
> > >
> > > iD8DBQFKFAGhYR7HhwQLD6sRAi6SAJ4pky6gV+7YpthNyOTcJzBuTx1UMwCePGCg
> > > r8M9k0WCo8cwWcexraZ0DQg=
> > > =NSvj
> > > -----END PGP SIGNATURE-----
> > >
> > > _______________________________________________
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel at mplayerhq.hu
> > > https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
> > >
> >
> >
> > Yes.
>
> and if they differ in size?
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> When the tyrant has disposed of foreign enemies by conquest or treaty, and
> there is nothing more to fear from them, then he is always stirring up
> some war or other, in order that the people may require a leader. -- Plato
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iD8DBQFKFNc1YR7HhwQLD6sRAnI2AJ49JPsBF64gY????????
> zfy53zP7kVGWE9u9fxUHucs=
> =AYNZ
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
>

This appears to expose another bug:

$ ffmpeg -i a.mov -s 200x200 b.mpg

$ ffmpeg -i a.mov -s 400x400 c.mpg

$ ffmpeg -i b.mpg d.mpg -newvideo -i c.mpg
FFmpeg version SVN-r18769, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --enable-pthreads --enable-libfaac --enable-libx264
--enable-decoders --enable-gpl --enable-libfaad --enable-nonfree
  libavutil     50. 3. 0 / 50. 3. 0
  libavcodec    52.28. 0 / 52.28. 0
  libavformat   52.32. 0 / 52.32. 0
  libavdevice   52. 2. 0 / 52. 2. 0
  libswscale     0. 7. 1 /  0. 7. 1
  built on May  7 2009 12:24:33, gcc: 4.3.2 20081105 (Red Hat 4.3.2-7)
Input #0, mpeg, from 'b.mpg':
  Duration: 00:00:12.05, start: 0.500000, bitrate: 236 kb/s
    Stream #0.0[0x1e0]: Video: mpeg1video, yuv420p, 200x200 [PAR 49:33 DAR
49:33], 104857 kb/s, 23.98 tbr, 90k tbn, 23.98 tbc
Input #1, mpeg, from 'c.mpg':
  Duration: 00:00:12.09, start: 0.500000, bitrate: 329 kb/s
    Stream #1.0[0x1e0]: Video: mpeg1video, yuv420p, 400x400 [PAR 49:33 DAR
49:33], 104857 kb/s, 23.98 tbr, 90k tbn, 23.98 tbc
Output #0, mpeg, to 'd.mpg':
    Stream #0.0: Video: mpeg1video, yuv420p, 200x200 [PAR 49:33 DAR 49:33],
q=2-31, 200 kb/s, 90k tbn, 23.98 tbc
    Stream #0.1: Video: mpeg1video, yuv420p, 200x200 [PAR 49:33 DAR 49:33],
q=2-31, 200 kb/s, 90k tbn, 23.98 tbc
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #1.0 -> #0.1


Notice that both output streams are now listed as 200x200 while no
resampling was requested.

So I tied again using something else to mux the video streams:

$ ffmpeg -i a.mov -s 200x200 b.mp4

$ ffmpeg -i a.mov -s 400x400 c.mp4

$ MP4Box -add b.mp4 -add c.mp4 d.mp4
Saving to d.mp4: 0.500 secs Interleaving

$ ffmpeg -i d.mp4 -s 500x500 e.mp4 -newvideo
FFmpeg version SVN-r18769, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --enable-pthreads --enable-libfaac --enable-libx264
--enable-decoders --enable-gpl --enable-libfaad --enable-nonfree
  libavutil     50. 3. 0 / 50. 3. 0
  libavcodec    52.28. 0 / 52.28. 0
  libavformat   52.32. 0 / 52.32. 0
  libavdevice   52. 2. 0 / 52. 2. 0
  libswscale     0. 7. 1 /  0. 7. 1
  built on May  7 2009 12:24:33, gcc: 4.3.2 20081105 (Red Hat 4.3.2-7)

Seems stream 0 codec frame rate differs from container frame rate: 2997.00
(2997/1) -> 23.98 (24000/1001)

Seems stream 1 codec frame rate differs from container frame rate: 2997.00
(2997/1) -> 23.98 (24000/1001)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'd.mp4':
  Duration: 00:00:12.13, start: 0.000000, bitrate: 541 kb/s
    Stream #0.0(eng): Video: mpeg4, yuv420p, 200x200 [PAR 16:9 DAR 16:9],
23.98 tbr, 23.98 tbn, 2997 tbc
    Stream #0.1(eng): Video: mpeg4, yuv420p, 400x400 [PAR 16:9 DAR 16:9],
23.98 tbr, 23.98 tbn, 2997 tbc
Output #0, mp4, to 'e.mp4':
    Stream #0.0(eng): Video: mpeg4, yuv420p, 500x500 [PAR 16:9 DAR 16:9],
q=2-31, 200 kb/s, 24k tbn, 23.98 tbc
    Stream #0.1(eng): Video: mpeg4, yuv420p, 500x500 [PAR 16:9 DAR 16:9],
q=2-31, 200 kb/s, 24k tbn, 23.98 tbc
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
frame=  291 fps=241 q=12.8 Lq=17.9 size=     894kB time=12.14 bitrate=
603.6kbits/s
video:888kB audio:0kB global headers:0kB muxing overhead 0.672864%


Both streams are upsampled to 500x500 with no problem; no valgrind errors.
This even works on the current version without my patch.



More information about the ffmpeg-devel mailing list