FIx video-to-image examples not working with H264 videos #90
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I tried
video-to-xxx.go
examples with H264/MP4 videos then I encountered several errors.This PR includes fixes to work with H264 videos.
I used my own VJ loops and other H264 videos downloaded from beeple.
Retry decoding if err is EAGAIN 034ff4f
When I run
video-to-image.go
with H264 file, it threw an error:Resource temporarily unavailable
onpacket.Frames()
.The error message came from ffmpeg's
EAGAIN
, it means we should retryavcodec_receive_frame
until it succeeds.I added retry code to video-to-*.go files.
It uses
goto
for simplicity, but if you don't like it I'll rewrite them withfor
loop.Set encoder's timebase in video-to-jpeg-p.go aebce39
go run examples/video-to-jpeg-p.go foo.mp4
throws an error:[jpeg2000 @ 0x880dc00] The encoder timebase is not set.
I set the codec context's timebase to
srcVideoStream.TimeBase.AVR()
.Scale frames in video-to-mjpeg.go a557b34
go run examples/video-to-mjpeg.go foo.mp4
throws an error:[mjpeg @ 0xc001200] Invalid pts (0) <= last (0)
I noticed
video-to-mjpeg.go
was not converting frames with sws, so I addedswsCtx.Scale(frame, dstFrame)
before encoding.It works, but I'm not sure this is the right decision... 😅
Use CLI args instead of flags, like other examples 62f2394
video-to-jpeg-p.go
takes input video from CLI flag while other examples takes input from CLI args.It's confusing, so I fixed it.
BTW gmf is the best repo for video editing in go, thanks @3d0c ! 💪