m1gin

#ffmpeg #ffprobe #ubuntu #cutvideos #keyframes

Get Info about each frame in a video:

  • ffprobe  SiretulKuran3-dBz1I8rHl1g.mkv  -select_streams v:0 -show_frames
  • ffprobe -i SiretulKuran3-dBz1I8rHl1g.mkv -v quiet -select_streams v -show_entries frame 

Show only selected entries:

  • ffprobe -i SiretulKuran3-dBz1I8rHl1g.mkv -v quiet -select_streams v -show_entries frame=pkt_pts_time,pict_type,key_frame

Output info in different formats:

  • ffprobe -i SiretulKuran3-dBz1I8rHl1g.mkv -v quiet -select_streams v -show_entries frame=pkt_pts_time,pict_type,key_frame  -of csv
  • ffprobe -i SiretulKuran3-dBz1I8rHl1g.mkv -v quiet -select_streams v -show_entries frame=pkt_pts_time,pict_type,key_frame  -of compact

-of values: csv, compact, json, xml, ini, flat

Filter only keyframes

  • ffprobe -i SiretulKuran3-dBz1I8rHl1g.mkv -v quiet -select_streams v -show_entries frame=pkt_pts_time,pict_type,key_frame | grep -B 2 'pict_type=I'

Get info from 83 second, read 11 frames:

  • ffprobe  -i SiretulKuran3-dBz1I8rHl1g.mkv   -select_streams v -show_entries frame  -read_intervals 83%+#11
  • ffprobe -i SiretulKuran3-dBz1I8rHl1g.mkv  -select_streams v -show_entries frame -read_intervals 1:23%+#11

Get nearest 2 keyframes between 100 to 200 second.

  • ffprobe -i SiretulKuran3-dBz1I8rHl1g.mkv -v quiet -select_streams v -show_entries frame=pkt_pts_time,pict_type -of compact -read_intervals 100%200 | grep -m 2 'pict_type=I'

Output:

frame|pkt_pts_time=98.800000|pict_type=I
frame|pkt_pts_time=101.760000|pict_type=I

  • ffprobe -i SiretulKuran3-dBz1I8rHl1g.mkv -v quiet -select_streams v -show_entries frame=pkt_pts_time,pict_type -of default=noprint_wrappers=1:nokey=1 -read_intervals 100 | grep -m 2 -B 1 'I' | grep -P '\d+'

Output:

98.800000
101.760000

Get nearest keyframes (faster):

  • ffprobe -hide_banner -v error -show_packets -select_streams v -show_entries packet=pts_time,flags -of csv -read_intervals 40%50  video.mkv
  • ffprobe -hide_banner -v error -show_packets -select_streams v -show_entries packet=pts_time,flags -of csv -read_intervals 44%+#300  video.mkv

Output:

packet,46.087000,K_
packet,46.207000,__

 

Get video resolution:

  • ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 SiretulKuran3-dBz1I8rHl1g.mkv

Output: 

1920x1080

Get Codec Name:

  • ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of csv=s=-:p=0 SiretulKuran3-dBz1I8rHl1g.mkv 

Output:

vp9

Get frame rate of a video (fps):

  • ffprobe -v 0 -of csv=p=0 -select_streams 0 -show_entries stream=r_frame_rate  SiretulKuran3-dBz1I8rHl1g.mkv

Output:

25/1

Get audio sample rate:

  • ffprobe  -v error -select_streams a:0 -show_entries stream=sample_rate -of csv=s=x:p=0 eb115.mp4

Output:

48000

 

More ffprobe tips: 
https://trac.ffmpeg.org/wiki/FFprobeTips

 

Create video from an image and an audio file:

  • ffmpeg -loop 1 -i /test/back.png -i test.mp3 -r 25 -c:a copy -shortest test.avi

 

Unseekable video in VLC. But it's smaller video size...
Since Youtube already re-processing videos, It is OK to be uploaded on youtube.

  • sec=1117; png="/media/data/Belgelerim/PROJE/ENLEM ve BOYLAM/[ALTYAPI]/video/eb121/eb.png"; ffmpeg -f concat -safe 0 -i <( echo "file '$png'"; echo "duration 0.5";  echo "file '$png'"; echo "duration $sec"; echo "file '$png'"; echo "duration 0.5"; ) -i "/media/data/SES/DİNLETİ/mbirgin/Enlem_ve_Boylam/Enlem_ve_Boylam_121_Eylul_2018.mp3" -c:a copy -map 0:v -map 1:a -shortest  eb121.avi
     

Seekable with 10 seconds steps:
The video duration is not accurate... It may be longer as long as the step. (in this example 10 seconds)

  • ffmpeg -f concat -safe 0 -i <(for c in {0..1111}; do echo "file '/media/data/Belgelerim/PROJE/ENLEM ve BOYLAM/[ALTYAPI]/video/eb121/eb.png'"; echo "duration 10"; done) -i "/media/data/SES/DİNLETİ/mbirgin/Enlem_ve_Boylam/Enlem_ve_Boylam_121_Eylul_2018.mp3" -c:a copy -map 0:v -map 1:a   -shortest eb121.avi 

 

Add to: