简体   繁体   中英

FFmpeg create video from images, insert images as frame from timestamp?

So I'm trying to extract every frame of a video, then use ffprobe to see when each frame is played within a video, then be able to stitch that video back together using those extracted images and ffprobe output.

Right now, I have this batch file:

for %%a in (*.mp4) do (
    mkdir "%%~na_images" > NUL
    ffmpeg.exe -hide_banner -i "%%a"  -t 100 "%%~na_images\image-%%d.png"
    ffprobe.exe "%%a" -hide_banner -show_entries frame=coded_picture_number,best_effort_timestamp_time -of csv > "%%~na_frames.txt"
)

First, a directory is made for the images. Then ffmpeg extracts all the frames of the video to individual PNG files, which are numbered appropriately. Lastly, ffprobe sees when each frame is first shown within that video (IE: frame 1 is shown at 0 seconds, but at say 60fps then frame 2 is played at 0.016667 seconds in the video). The output looks like this:

frame,0.000000,0
frame,0.000000
frame,0.017000,1
frame,0.023220

Where the first number (IE 0.17000 is the time the second frame appears) and the 2nd number is the frame number. Now my problem is using ffmpeg to take each frame and place it in the proper time within the video. I can do this using another language (probably Python), but my best guess is to make a loop to iterate through the ffprobe output file, get the frame time and image number, place that frame at the points that it appears, then move on to the next frame and time placement. Looking at the frame data I used as an example above, it 'd be something like this:

for line in lines:
    mySplit = line.split(',')
    # Get image number 0 and insert at time 0.000000

This is the part that I'm not sure how to do in a coding sense. I can read in and parse the lines of the ffprobe output text file, but I have no idea how to insert the frames at certain points in a video using ffmpeg or similar solutions.

You need to tell the system there is more than 1 token. ie

for /f "tokens=1-4 delims=," %%a in ...

Here you tell it that you want to grab tokens 1 to 4 and delimeter is ,

So for an example of a file containing 1,100,1000,10000 it will assign the %%a to the first token (being 1 , and %%b to the second (being 100 ) etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM