Various ramblings-on, mostly about Red5

05 Dec 09 Fun with FFMPEG

Since I’ve seen nothing which addresses the processing delays that I noticed in ffmpeg when generating thumbnail images, I figured I should share some important optimizations. I used to specify this command line when generating the images from a movie source (f4v in this case):

ffmpeg -y -i mymovie.f4v -an -ss 00:05:00 -t 00:00:00.01 -sameq -r 1 -vframes 1 -deinterlace -f mjpeg mythumbnail.jpg

This will take about one minute to generate the image of the video frame which is five seconds into the clip. This seems really extreme and is even worse when you try to increase the start location; for instance 45 seconds in, takes about an hour.
So, I knew there had to be a better way and I monkeyed around with the options:

ffmpeg -y -ss 00:05:00 -i mymovie.f4v -an -t 00:00:00.01 -sameq -r 1 -vframes 1 -deinterlace -f mjpeg mythumbnail.jpg

There is only one change between these lines, the placement of the “ss” option. This change causes the command to complete in less than a second, no matter what our start time is. Quite an increase in processing for something so simple! I hope this helps a few of you out there.

Tags: , , ,

Reader's Comments

  1. |

    This seems to be a bug in ffmpeg. Conventionally, the order of command line switches should never have any effect of the result. Did you report the bug to the ffmpeg team?

  2. |

    Hi Paul, I have a big problem with ur custom object methods. Everything is working fine but when I’m sending an serialized array, it works but I got nothing in my datagrid, (results works, I can see them with toString() ) I think I cant access to private properties ( in my remoteclass / as3 class ) for my colums with datafield.

    What can I do ?

    Thank u !

  3. |

    @Jonas, why not ask your question somewhere it’s relevant, rather than on this blog post about FFMPEG? Sorry if I seem insensitive, but come on!

    Try asking there!

  4. |

    Awesome :) thx for the tricks !

  5. |

    you saved my day!, thx for the trick.

  6. |

    putting the -ss after is more accurate.

    ffmpeg -ss 00:01:30 -i -c:v copy -c:a copy -t 00:01:30.500
    Note that we’ve again just copied the contents instead of re-encoding because we used the copy codec. Also, see how the -ss option is before the actual input? This will first seek to the point in the file, and then start to encode and cut. This is especially useful when you’re actually not just copying content, but encoding it, because it’ll speed up your conversion (although it’s less accurate). If you want to be more accurate, you’ll have to tell FFmpeg to encode the whole video and just discard the output until the position indicated by -ss:
    ffmpeg -i -ss 00:01:30 -c:v copy -c:a copy -t 5

    I think the reason putting it after is more accurate is to do with keyframes.

    There is a difference between before or after that is mentioned in ffmpeg documentation
    When used as an input option (before -i), seeks in this input file to position.

    When used as an output option (before an output filename), decodes but discards input until the timestamps reach position

Leave a Comment

Fatal error: Call to undefined function akismet_counter() in C:\xampp\htdocs\paulgregoireblog\wp-content\themes\googlechrome\footer.php on line 9