0

l'm newbie at video processing .

  1. I would like to understand how to read the following ffmpeg instruction below

    import subprocess
    L=subprocess.call('ffmpeg -i %s -r 1 -s qvga -t 1 -f image2 %s' % (videoName,frameName), shell=True)
    
  2. Through this instruction , how can l adapt it to get all the frames of a given video ?

Thank you

  • 1
    First, read man ffmpeg, which list all the ffmpeg functionality. – waltinator Oct 25 '17 at 15:53
1

I would like to understand how to read the following ffmpeg instruction

Your ffmpeg command is semi-obfuscated by scripting so the actual command is not known, but here's an explanation of each option:

  • -i indicates the input.
  • -r 1 sets output frame rate to 1. This is not needed if you want to output a single image or if you want to output all images. In this example it is used to output one frame per second which would skip many frames.
  • -s qvga sets output width x height to "qvga" which is an alias for 320x240.
  • -t 1 sets the output duration to 1 second. This is not needed if you want to output a single image or if you want to output all images. It is often added by rookie users trying to output a single image but -frames:v 1 should be used instead.
  • -f image2 An often superfluous option used to set the output format or muxer. It is used if your output name is ambiguous (perhaps due to scripting). Otherwise, ffmpeg will automatically choose the proper muxer for image outputs.

how can l adapt it to get all the frames of a given video ?

The simplest, unscripted command to get all of the frames is:

ffmpeg -i input %04d.png

This will output 0001.png, 0002.png, 0003.png, etc. If you want more than a numerical sequence you can use something like output_%05d.png which would result in output_00001.png.

For more info see FFmpeg Documentation: Image Muxer.

  • Thanks a lot @LordNeckbeard. What about an alea of 224x224 ? – Joseph Oct 25 '17 at 17:20
  • @Joseph There are several methods: ffmpeg -i input -s 224x224 %04d.png or to preserve aspect ffmpeg -i input -vf scale=224:-1 %04d.png or to prevent it from upscaling see How to set maximum video width in ffmpeg?, or to fit it in a 244x244 box see Resizing videos with ffmpeg to fit into static sized player. – llogan Oct 25 '17 at 18:22
  • THANK YOU. Since we extract all the frames of a video. Is it supposed by default that 24 fps (frame per second) ? or it's up to ffmpeg to adapt the scale acording to the speed of video, it can more / less than 24fps ? – Joseph Oct 26 '17 at 8:59
  • @Joseph Input frame rate doesn't matter. As a gross simplification, if there are 500 frames in the video it will output ~500 frames. – llogan Oct 26 '17 at 16:42
1
import subprocess
L=subprocess.call('ffmpeg -i %s -r 1 -s qvga -t 1 -f image2 %s' % (videoName,frameName), shell=True)

Information:

  1. import subprocess: The subprocess module enables you to start new applications from your Python program.

  2. L=subprocess.call(...): Assign the output of the call() method to variable L.

  3. ffmpeg -i %s -r 1 -s qvga -t 1 -f image2 %s' % (videoName,frameName), shell=True: Command to run here ffmpeg

  4. -i %s: input file name gotten from videoName variable --> input file url

  5. -r 1: frame rate.

  6. -s qvga: frame size.

  7. -f image2: Force input or output file format

  8. -t 1: When used as an output option (before an output url), stop writing the output after its duration reaches duration.

  9. % (videoName,frameName): Python string formatting that will replace %s sequences in the previous string with the items in the tuple.

  10. shell=True: Make use of specific shell features like word splitting or parameter expansion

Usage:

#!/usr/bin/env python

import subprocess 
L=subprocess.call('ffmpeg -r 5 -i out.ogv fmprg_%04d.png', shell=True)
L()
  • Make executable: chmod u+x filename.sh,
  • Run with: ./filename.sh

Information:

fmprg_%04d.png: Creates images with 0000, 0001, 0002, 0004, ... between fmprg_ and .png.

Read:

man ffmpeg

https://pythonspot.com/en/tag/subprocess/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.