Use FFMpeg to get middle frame of a video?

后端 未结 4 1208
耶瑟儿~
耶瑟儿~ 2020-12-08 23:51

I\'m wondering how to use FFMpeg to grap the middle frame of a video. I\'ve already written the C# to grab a frame at a certain time (ie pull one frame at second 3). But I\'

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 00:28

    With simple shell scripting you can use ffprobe to get a machine readable duration output, bc to calculate the half point, and ffmpeg to make the frame:

    input=input.mp4; ffmpeg -ss "$(bc -l <<< "$(ffprobe -loglevel error -of csv=p=0 -show_entries format=duration "$input")*0.5")" -i "$input" -frames:v 1 half.png
    

    This eliminates any need for PHP, echo, awk, tr, grep, sed, etc.

提交回复
热议问题