Search code examples
videoffmpegvideo-capturemkv

Extract frame from secondary videostream FFMpeg


I work with FFMpeg and process some .mkv videos that can have more than one videostream. How I can extract frame from other videostream (not from primary)? I want to extract one frame from each videostream using FFMPeg. Any ideas?


Solution

  • Example input file layout:

    • video #0:0
    • video #0:1
    • video #0:2
    • audio #0:3
    • audio #0:4

    Example: Output screenshot from video #0:2

    From 30 second timestamp (-ss 30).

    Absolute map

    ffmpeg -ss 30 -i input.mkv -map 0:2 -frames:v 1 output.jpg
    

    Relative map

    Same result as above with this particular input. 0:v:1 is translated as "from input #0 choose video stream #1". Note that ffmpeg starts counting from 0, so video stream #1 is actually the 2nd video stream.

    ffmpeg -ss 30 -i input.mkv -map 0:v:1 -frames:v 1 output.jpg
    

    I prefer using this method because you can be lazy and not have to know the actual stream map numbers.

    Example: Output a screenshot from each video stream

    ffmpeg -ss 30 -i input.mkv -map 0:v:0 -frames:v 1 output0.jpg -map 0:v:1 -frames:v 1 output1.jpg -map 0:v:2 -frames:v 1 output2.jpg
    

    Also see