0

I want to cut lengthy segments of a video file and then join them. But without re encoding precise cutting isn't possible as ffmpeg seeks to the key frame before my listed time stamp and cuts from that key frame or in some cases cuts from that key frame and use some kind of table to play video as intended. When I join such cut segments the joined file shows those unwanted sections due to some inability of concat fun i guess. this is how I am trying to concat those segments:

ffmpeg -f concat -i Cam01.txt -c copy Cam01.mp4

To solve this problem with lesser re encoding I thought to cut the video in two parts; first cut without re encoding from start to just before that key frame which will be faster and then in the second part cut with re encoding from that key frame to my desired frame, which will be few seconds and then join those two parts to have my segment.

Now I have two questions:

1: how can I get time stamp of a key frame before any time stamp?

2: Is there any problem in how i am joining segments so that in some cases it shows those unwanted parts in my joined file?

Or some way I could get time stamps of key frames in an entered range of time if getting to a key frame before any time stamp wont be possible.

0

for 1. you can use

 ffprobe -select_streams v -show_frames youfile.mp4

to get a list of frames, key frames will be marked with 'key_frame=1' and their time stamp so you could parse that to find your nearest key frame.

for 2. you are joining them just fine, i've had similar issues with fast seeking (-ss before -i) into streams produced using the concat muxer in the end I just calculated which segments to use outside of ffmpeg and then putting up with the slow seek (-ss after -i)

  • for getting a key frame, the command you mentioned results all frames and for a huge file it would take minutes to display all frames and then finding what I wanted will be a hectic thing, i want to have a specific result, any way I could get time stamp of a key frame just before my desired time stamp. – Saif Feb 25 '16 at 17:52
  • you can parse the output of ffprobe to find the stamp of the desired key frame – user3770489 Feb 26 '16 at 11:27
  • well thanks for the reply, can you demonstrate using a coding example that how can I parse its output? or either point me in the right direction on how to parse its output? – Saif Apr 7 '16 at 11:45
  • you could probably process the text output with something like awk or tell ffprobe to output json/xml which could be more manageable (eg. ffprobe -print_format json) – user3770489 Apr 28 '16 at 8:39

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.