sodcalculator

10 Tech How-To

Fix FFmpeg Permission Denied on Linux Playlists

Guide 10-20527 · Updated · Step by step

This guide solves the “Permission denied” error when FFmpeg tries to read playlist files (like M3U or M3U8) on Linux. You’ll learn why it happens and how to fix it with clear, step-by-step commands. No advanced Linux knowledge is needed, just a terminal and the ability to copy-paste.

What You’ll Need

  • A Linux system with FFmpeg installed (check with ffmpeg -version).
  • Terminal access with sudo privileges (you’ll need to enter your password for some commands).
  • The path to your playlist file (e.g., /home/user/videos/playlist.m3u).

Step-by-Step

  1. Identify the exact error. Run your FFmpeg command and note the full error message. It usually looks like: playlist.m3u: Permission denied or Failed to open resource: Permission denied. This tells you which file is causing the problem.
  2. Check the file permissions. Use ls -l /path/to/playlist.m3u to see the file’s permissions. The first column shows things like -rw-r--r--. If the owner doesn’t have read permission (no r in the first group), that’s the issue.
  3. Check the directory permissions. Even if the file is readable, FFmpeg needs execute (search) permission on every directory in the path. Check with ls -ld /path/to/directory. If any directory lacks r and x for your user, you’ll get a permission error.
  4. Fix permissions for your user. If you own the file, make it readable with: chmod +r /path/to/playlist.m3u. For directories, use: chmod +rx /path/to/directory. If you don’t own the file, use sudo chmod to change ownership or permissions.
  5. For playlists with remote URLs. If your playlist contains URLs (http:// or https://), the “Permission denied” might come from the network, not the file. Try downloading one of the referenced segments with wget URL to see if it’s reachable.
  6. Run FFmpeg as the correct user. If the playlist is owned by another user (like root), you can either change ownership with sudo chown yourusername:yourusername /path/to/playlist.m3u or run FFmpeg with sudo. Be careful with sudo—only use it if you trust the playlist content.
  7. Check for AppArmor or SELinux. Some Linux distributions have security modules that block FFmpeg from reading certain paths. Check if SELinux is enabled with getenforce. If it says Enforcing, you may need to adjust the policy or temporarily set it to Permissive with sudo setenforce 0 to test.
  8. Test with a simple file. Create a test playlist in your home directory with echo 'file /tmp/test.mp4' > test.m3u and try to read it with FFmpeg. If that works, the issue is with the original file’s location or permissions.

Common Mistakes

  • Only checking the file permissions, not the directory permissions. A file can be readable, but if a parent directory lacks execute permission, you still get “Permission denied”.
  • Using sudo to run FFmpeg but then the output files are owned by root, causing permission issues later.
  • Assuming the playlist file is the problem when it’s actually a referenced media file (like a .ts segment) that’s not readable.
  • Changing permissions on system directories like /etc or /var without understanding the consequences.

Tips

  • Use namei -l /path/to/playlist.m3u to see the permissions of every directory in the path in one go.
  • If you’re dealing with a downloaded playlist, check if the files are in a read-only location like a mounted ISO or a read-only filesystem.
  • For playlists with many files, consider copying them to a directory where you have full control, like ~/videos/.
  • Always quote paths with spaces: ffmpeg -i "/home/user/my playlist.m3u".

Troubleshooting

If the above steps don’t work, try these:

  • Check if the file is a symlink. Use ls -l and look for an arrow (->). If it is, the target file might have different permissions. Use readlink -f /path/to/playlist.m3u to get the real path.
  • Verify FFmpeg can read the file at all. Run ffmpeg -v error -i /path/to/playlist.m3u -f null - and see if it gives a more specific error.
  • Try a different user. If you have another user account, log in and try to read the file. If it works there, the problem is with your user’s group memberships.
  • Look at the playlist contents. Use cat /path/to/playlist.m3u to see if the paths inside are relative or absolute. If they’re relative, FFmpeg resolves them relative to the current working directory, not the playlist’s location. Use cd /path/to/playlist and then run FFmpeg.
  • Check for special characters. Playlist files with non-ASCII characters in the path can cause issues. Rename the file to something simple like playlist.m3u and try again.

Frequently Asked Questions

Why does FFmpeg say “Permission denied” even though I can read the file with cat?

Because FFmpeg might need to read the file as a different user (if running as a service) or the error might be about a file referenced inside the playlist, not the playlist itself.

Can I just use sudo to fix it?

Yes, but it’s a temporary workaround. Running FFmpeg with sudo can cause output files to be owned by root, and it’s not a good practice for security. Better to fix the permissions properly.

What does “Permission denied” mean when the playlist is on an NTFS or FAT drive?

Those filesystems often don’t support Linux permissions properly. You may need to mount the drive with the uid and gid options to give your user full access. For example: sudo mount -o uid=1000,gid=1000 /dev/sdb1 /mnt/usb.

Is it safe to change permissions on all files in a directory?

Generally yes, but be careful with system directories. For personal media files, chmod -R +r ~/videos is safe. For system directories, avoid recursive changes.

How do I check if SELinux is blocking FFmpeg?

Run sudo ausearch -m avc -ts recent to see SELinux denials. If you see entries related to ffmpeg, that’s the cause. You can then either adjust the SELinux policy or set the correct context with sudo chcon -t httpd_sys_content_t /path/to/file.

Why does it work when I copy the playlist to my home directory but not in its original location?

Because your home directory has the right permissions by default. The original location might be on a different filesystem or under a directory that restricts access.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →