0

I am using ffmpeg to scan video files for scene changes and save the results to a text file. The code I am using below works but I want to simplify the results and just output the frames number where the scene changes occur and the not all the data that this code produces. Any suggestions?

ffprobe -show_frames -of compact=p=0 -f lavfi "movie=input.mov,select=gt(scene\,.02)" > results.txt

Outputs all this:

media_type=video    stream_index=0  key_frame=1 pkt_pts=31031   pkt_pts_time=1.292958   pkt_dts=31031   pkt_dts_time=1.292958   best_effort_timestamp=31031 best_effort_timestamp_time=1.292958 pkt_duration=N/A    pkt_duration_time=N/A   pkt_pos=82320   pkt_size=629760 width=640   height=328  pix_fmt=rgb24   sample_aspect_ratio=1:1 pict_type=I coded_picture_number=0  display_picture_number=0    interlaced_frame=0  top_field_first=0   repeat_pict=0   tag:lavfi.scene_score=0.025551  
JulianJ
  • 1,259
  • 3
  • 22
  • 52
  • Possible duplicate of [Using FFMPEG: How to do a Scene Change Detection? with timecode?](https://stackoverflow.com/questions/35675529/using-ffmpeg-how-to-do-a-scene-change-detection-with-timecode) – Legolas Dec 29 '18 at 05:44

2 Answers2

1

To get just the frame index numbers which meet the scene change criteria, use

 ffprobe -select_streams v -show_entries frame=pkt_pts -of compact=p=0:nk=1 \
         -f lavfi "movie=abc.mov,setpts=N+1,select=gt(scene\,.02)" > log.txt

The log file will simply contain the frame index numbers, one per line e.g.

135
136
137
141
143
145 

The setpts starts numbering from 1.

Gyan
  • 85,394
  • 9
  • 169
  • 201
1

You can simply use the command:

ffmpeg inputvideo.mp4 -filter_complex "select='gt(scene,0.3)',metadata=print:file=time.txt" -vsync vfr img%03d.png

This will save just the relevant information in the time.txt file like below:

frame:0    pts:108859  pts_time:1.20954
lavfi.scene_score=0.436456
frame:1    pts:285285  pts_time:3.16983
lavfi.scene_score=0.444537
frame:2    pts:487987  pts_time:5.42208
lavfi.scene_score=0.494256
frame:3    pts:904654  pts_time:10.0517
lavfi.scene_score=0.462327
frame:4    pts:2533781 pts_time:28.1531
lavfi.scene_score=0.460413
frame:5    pts:2668916 pts_time:29.6546
lavfi.scene_score=0.432326

Also, choose your threshold value (here 0.3) appropriately for your use case to get correct outputs

Legolas
  • 653
  • 1
  • 9
  • 17
  • Instead of copying and pasting the same answer to multiple questions, consider flagging the questions as duplicates. – llogan Dec 28 '18 at 18:27