Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gif file handling #158

Open
jjsarton opened this issue Sep 17, 2022 · 0 comments
Open

Gif file handling #158

jjsarton opened this issue Sep 17, 2022 · 0 comments

Comments

@jjsarton
Copy link

I finally reached to work with the animated.gif file. I had thought that ffmpeg will be used, this was not the case. After installing the gstreamer plugin, I was able to see the last image for the GIF file.

The plugin has, on my distribution, two errors. This is probably the same for other distributions.
The returned FPS has a value of 100 and shall be approximately 45.
The loop indication is not taken into account, so that the stream is closed after the last retrieved frame.

Within bacground.cc we don't take into account, that the last valid frame is reached.
Fixing the frame rate is not simple, I don't have a way to get the correct value.

I have write a little python script which shown what happen:

import cv2 as cv
import numpy as np
print("Opencv version:", cv.__version__)
info = cv.getBuildInformation()
video, parallel = info.index('Video'), info.index('Parallel')
print(info[video:parallel])

cap = cv.VideoCapture('../backgrounds/animated.gif')
#cap = cv.VideoCapture('../backgrounds/rotating_earth.webm')

fps = cap.get(cv.CAP_PROP_FPS)
# return 100 for the fif file, should be ~ 45 as per ffmpeg or 43.903 as
# calculated with the output from exiftool, see below

print("FPS:", fps)

cnt = cap.get(cv.CAP_PROP_FRAME_COUNT)
print("CNT:", cnt)
# 36 for animated.gif 916 for rotating_earth.webm

wait = int(1000/fps)
print("Waittime", wait, "ms");
nr=0
while cap.isOpened():
    ret, frame = cap.read()
    nr += 1
    # the Frame is empty (902), set the frame pos. to 0 (rotating_earth.webm)
    if np.shape(frame) == ():
        print("Set to frame Pos 0, empty frame at", nr)
        cap.set(cv.CAP_PROP_POS_FRAMES, 0)
        nr=0
        continue

    # if the check is not done the gif file is closed after reading
    # past the last frame. We set the frame pos to 0 before this happen.
    if nr == cnt:
        print("Set to frame Pos 0 frame", nr)
        cap.set(cv.CAP_PROP_POS_FRAMES, 0)
        nr=0

    cv.imshow('frame', frame)
    if cv.waitKey(wait) == ord('q'):
        break
cap.release()
cv.destroyAllWindows()```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant