[FFmpeg-user] Reordering frames in corrupt GoPro videos

Vincent Deconinck vdeconinck at gmail.com
Sun Jul 21 01:11:57 EEST 2024


On Sat, Jul 20, 2024 at 9:55 PM Mark Filipak <markfilipak.imdb at gmail.com>
wrote:

> I don't know of any tool where you can simply pick up a frame and move it
> while you're watching a stream. You might be able to use shuffleframes for
> uniform runs, but when the pattern changes you're stuck with making
> intermediate shuffleframes until the uniformity returns. That would require
> you to make splits based on frame numbers and it could get really ugly.
>

Hi Mark,

Thanks again for your insightful help.

Well, fortunately (if I dare say so), once the camera starts mangling a
video, it is always the same pattern that gets repeated. But I often leave
the camera recording for periods between half an hour and 2 hours and the
GoPro splits videos in chunks of around 4GB (which is about 11 minutes with
my settings). In other words, I have 5 or 7 files to which I should apply
the same shuffling pattern, but the split between video files is not always
on a 5-frame boundary, so I need to start reshuffling after 0..4 frames
depending on the file.

Hence my quest to drop a few frames before applying the shuffling, ideally
without reencoding.

As the 2-pass (seek + shuffle) worked, I tried to achieve it without
reencoding by piping the video between two ffmpeg processes, like so:
ffmpeg -i in_bad_frame_order.mp4 -ss 0.04 -t 5 -f rawvideo -vcodec rawvideo
-video_size 3840x2160 -r 30 -pix_fmt rgb24 pipe: | ffmpeg -y -f rawvideo
-vcodec rawvideo -video_size 3840x2160 -r 30 -pix_fmt rgb24 -i pipe: -vf
"shuffleframes=1 0 3 4 2" out.mp4

It seems to work on a small excerpt, but it is quite slow (memory issue
maybe) - and of course I'm losing the audio, which must then be extracted,
trimmed and remuxed separately.

Do you think there is a way to make ss and shuffleframes play along nicely ?

Or, back to my initial idea, editing the frames PTS so that they play in
the right order, without any reencoding at all (see the setpts formula in
my original question) ?

Kind regards,

Vincent


More information about the ffmpeg-user mailing list