Skip to content

Commit

Permalink
Ignore editlist when decoding mp4/mov videos
Browse files Browse the repository at this point in the history
Closes ppy/osu#13696.

The editlist would cause storyboard videos to not play back the same
way stable (and most other video players) plays them back.
  • Loading branch information
bdach committed Jun 14, 2024
1 parent 980b4cd commit 30cc44d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions osu.Framework/Graphics/Video/FFmpegFuncs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public unsafe class FFmpegFuncs
{
#region Delegates

public delegate int AvDictSetDelegate(AVDictionary** pm, [MarshalAs(UnmanagedType.LPUTF8Str)] string key, [MarshalAs(UnmanagedType.LPUTF8Str)] string value, int flags);

public delegate void AvDictFreeDelegate(AVDictionary** m);

public delegate AVFrame* AvFrameAllocDelegate();

public delegate void AvFrameFreeDelegate(AVFrame** frame);
Expand Down Expand Up @@ -89,6 +93,8 @@ public unsafe class FFmpegFuncs

#endregion

public AvDictSetDelegate av_dict_set;
public AvDictFreeDelegate av_dict_free;
public AvFrameAllocDelegate av_frame_alloc;
public AvFrameFreeDelegate av_frame_free;
public AvFrameUnrefDelegate av_frame_unref;
Expand Down
9 changes: 8 additions & 1 deletion osu.Framework/Graphics/Video/VideoDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,12 @@ private void prepareDecoding()
formatContext->pb = ioContext;
formatContext->flags |= FFmpegFuncs.AVFMT_FLAG_GENPTS; // required for most HW decoders as they only read `pts`

int openInputResult = ffmpeg.avformat_open_input(&fcPtr, "pipe:", null, null);
AVDictionary* options = null;
// see https://github.com/ppy/osu/issues/13696 for reasoning
ffmpeg.av_dict_set(&options, "ignore_editlist", "1", 0);
int openInputResult = ffmpeg.avformat_open_input(&fcPtr, "pipe:", null, &options);
ffmpeg.av_dict_free(&options);

inputOpened = openInputResult >= 0;
if (!inputOpened)
throw new InvalidOperationException($"Error opening file or stream: {getErrorMessage(openInputResult)}");
Expand Down Expand Up @@ -842,6 +847,8 @@ protected virtual FFmpegFuncs CreateFuncs()

return new FFmpegFuncs
{
av_dict_set = FFmpeg.AutoGen.ffmpeg.av_dict_set,
av_dict_free = FFmpeg.AutoGen.ffmpeg.av_dict_free,
av_frame_alloc = FFmpeg.AutoGen.ffmpeg.av_frame_alloc,
av_frame_free = FFmpeg.AutoGen.ffmpeg.av_frame_free,
av_frame_unref = FFmpeg.AutoGen.ffmpeg.av_frame_unref,
Expand Down

0 comments on commit 30cc44d

Please sign in to comment.