mpv-player / mpv-player/mpv

mpv crashes on exit if using AMF decoder

Open
#17,206 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

down-upstream:ffmpeg
Dominant language
C
Stars
37k
Forks
3.5k
Avg merge
1d 10h
Merged PRs (30d)
22

Description

mpv Information
mpv v0.40.0-495-g122abdfec Copyright © 2000-2025 mpv/MPlayer/mplayer2 projects
 built on Dec 16 2025 00:07:26
libplacebo version: v7.358.0 (v7.351.0-100-g3fc2736-dirty)
FFmpeg version: N-122178-g7ee5c907e
FFmpeg library versions:
   libavcodec      62.23.101
   libavdevice     62.2.100
   libavfilter     11.10.101
   libavformat     62.8.100
   libavutil       60.20.100
   libswresample   6.2.100
   libswscale      9.3.100
Other Information
- Windows version: Microsoft Windows [Version 10.0.26200.7462]
- GPU model, driver and version: Rdeon RX Vega (Driver version 25.8.1)
- Source of mpv: https://github.com/shinchiro/mpv-winbuild-cmake/releases/download/20251217/mpv-x86_64-v3-20251217-git-122abdf.7z
- Latest known working version: not sure
- Issue started after the following happened: not sure
Reproduction Steps

(1) Run mpv.com -vd h264_amf https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4 in command prompt (cmd.exe)
(2) Press 'q'
(3) Run echo %ERRORLEVEL%

Expected Behavior

mpv exits without crash. (ERRORLEVEL is 0)

Actual Behavior

The result would be -1073741819 (0xc0000005).

Log File

amf-crash.log.zip

mpv.exe.58628.dmp.zip

Sample Files

No response

I carefully read all instruction and confirm that I did the following:
  • I tested with the latest mpv version to validate that the issue is not already fixed.
  • I provided all required information including system and mpv version.
  • I produced the log file with the exact same set of files, parameters, and conditions used in "Reproduction Steps", with the addition of --log-file=output.txt.
  • I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
  • I attached the full, untruncated log file.
  • I attached the backtrace in the case of a crash.
The cause

I tracked the issue down and found that the cause is that mpv calls av_buffer_unref() after dlclose() for amfrtdrv64.dll.
So this is not a bug of AMD driver.

The code path to dlclose() is as follows.

Called function			From where
avcodec_free_context()	[video/decode/vd_lavc.c:uninit_avctx()]
  |
  v
ff_codec_close()		[libavcodec/options.c:avcodec_free_context()]
  |
  v
amf_decode_close()		[libavcodec/avcodec.c:ff_codec_close():ffcodec(avctx->codec)->close(avctx)]
  |
  v
av_buffer_unref()		[libavcodec/amfdec.c:amf_decode_close()]
  |
  v
buffer_replace()		[libavutil/buffer.c:av_buffer_unref()]
  |
  v
hwdevice_ctx_free()		[libavutil/buffer.c:buffer_replace():b->free(b->opaque, b->data)]
  |
  v
amf_device_uninit()		[libavutil/hwcontext.c:hwdevice_ctx_free():ctxi->hw_type->device_uninit(ctx)]
  |
  v
dlclose()				[libavutil/hwcontext_amf.c:amf_device_uninit()]

After dlclose(), at vo_thread() exit,

uninit()				[video/out/vo.c:vo_thread():vo->driver->uninit()]
  |
  v
(inside libplacebo.dll)
  |
  v
mp_image_destructor()	[(inside libplacebo.dll)]
  |
  v
av_buffer_unref()		[video/mp_image.c:mp_image_destructor()]
  |
  v
buffer_replace()		[libavutil/buffer.c:av_buffer_unref()]
  |
  v
amf_free_amfsurface()	[libavutil/buffer.c:buffer_replace():b->free(b->opaque, b->data)]
  |
  v
Release()				[libavutil/hwcontext_amf.c:amf_free_amfsurface()]

Here, Release() points inside amfrtdrv64.dll. Then crash.

My conclusion is:
mpv calls FFmpeg API's in a way that FFmpeg does not expect.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with video/decode/vd_lavc.c:uninit_avctx(), then trace the shutdown path through video/out/vo.c:vo_thread() and the FFmpeg AMF paths named in the report. Reproduce with the provided mpv.com command and inspect whether teardown ordering leaves libplacebo surfaces referencing amfrtdrv64.dll; done means quitting no longer returns 0xc0000005 and ERRORLEVEL is 0.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
backend, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.