Skip to content

Need a easy filter sample. e.g. Create a thumbnail image every X seconds of the video #338

Closed

Description

@swordry

In FFmpeg wiki: https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video
we use cmd:
fmpeg -i input.flv -ss 00:00:14.435 -vframes 1 out.png
We get one picture in Specified time
ffmpeg -i input.flv -vf fps=1 out%d.png
then get lots of images. One picture per second.

How to use PyAV to achived the same goal ? Does anybody make a demo? Thanks.

BTW: by use cmd:
ffmpeg -i input.flv-r 1 -y -f image2 -s 240*320 pc%3d.jpg
use '-r' arg seems to be the same purpose, Which method is more efficient ?

Activity

  1. jb-alvarado commented on Sep 3, 2018

    @jb-alvarado

    I think you can do it more simple:

    import av
    
    count = 0
    container = av.open('test_clips/test.mp4', 'r')
    
    for packet in container.demux():
        if packet.stream.type == 'video':
            for frame in packet.decode():
                if count % 25 == 0:
                    frame.to_image().save('%04d.png' % count)
                count += 1
  2. nishant-ever commented on May 9, 2019

    @nishant-ever

    @jb-alvarado unless I'm misreading the code, it seems to select every frame divisible by 25 yielding frames 0, 25, 50, .... But it doesn't give a frame rate of 1 fps. Do you know if we can achieve this using the fps filter especially when the input video can have any frame rate? Thanks!

  3. jb-alvarado commented on May 10, 2019

    @jb-alvarado

    When you want to have images as output you can use two methods:

    1. before you use the modulo operator you read the fps from input file and use this as a modulo.
    2. you use the fps filter, this one drops all other frames

    When you want a video output the second method is better, but you have to look here in the issues and examples for a proper way to use filters in PyAV. My knowledge about PyAV is not so deep.

    Here I have try one time to change the fps, but as I remember there was some issues, and of course the queue and pipe to ffplay is not necessary.

  4. nishant-ever commented on May 10, 2019

    @nishant-ever

    Thanks @jb-alvarado for a quick response. Unfortunately there are no examples for using filters. I've also asked a question in the Gitter channel for the project. Your solution here does give me some ideas but my problem is a little more complicated since I'm doing filtering on a video stream as opposed to a file on the disk. I'll see if I can come up with something. Thanks again!

  5. locked and limited conversation to collaborators on Mar 25, 2022
  6. converted this issue into a discussion #934 on Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions