Video preview fix / conversion (YUV444p to YUV420p)
-
This process will resolve the problem where RetroPie does not show certain video previews. RetroPie's OMX Player does not play videos with the yuv444p pixel format whereas yuv420p play OK. You can work around this by disabling OMX Player in RetroPie settings but I understand this is not ideal due to the alternative not using hardware acceleration?
There are already two threads on this forum by some very clever contributors who give a more automated and simpler way to fix this using the Pi.
My method uses Windows rather than Pi, plus this method is more hands on / interactive. If you would prefer a simpler automated way to fix this and are OK doing this on your Pi, please see these two threads instead:
- https://retropie.org.uk/forum/topic/15362/script-batch-convert-yuv-4-4-4-videos-to-yuv-4-2-0-in-retropie-linux
- https://retropie.org.uk/forum/topic/15764/script-retropie-convert-videos
This will identify which video files which do not use yuv420p (which will mostly be yuv444p), move them to a separate folder then create converted copies of them in yuv420p pixel format in another folder.
For this you will need Notepad++ and Windows versions of FFmpeg with FFprobe. The FFmpeg website has links to two websites that host Windows builds for these.
This has been tested thoroughly under Windows 10 Pro and Windows 10 Home. It has not been tested under other versions of Windows. Also, this uses the command prompt rather than PowerShell as I am more familiar with the good ol' command prompt.
This process is designed to be done on a system-by-system process, not all systems simultaneously.
I have tried to describe this process as simply as possible for those who aren't overly technical, so for those who are technically minded, please excuse me over explaining here - it will seem like I'm explaining the obvious to some.
First of all, make a folder on your Windows desktop named All. Then copy all videos from your first system on the Pi to \All.
Open a command prompt at \All and type:
DIR /B > All-dir.txt
This will create a list of all the video files copied to the \All folder by outputting the DIR command to a text file (All-dir.txt) within the \All folder.
Open All-dir.txt with Notepad++ and do the following:
- Delete line containing All-dir.txt.
- Delete blank line at the bottom.
- Make sure EOL format is set to Windows (CR LF) - check near bottom right corner.
(For editing gamelist.xml I use Unix (LF) but seeing as we're in Windows and I assume Windows (CR LF) is the default setting, let's use that here. This will have an effect on the RegEx syntax used in this process).
Position cursor at beginning and press CTRL + H. Make sure Regular expression is selected in Search Mode. Fill in the two text boxes with the following:
Find what:
(.*)
Replace with:
Echo "(\1)" >> Sort.txt\r\nffprobe -v error -hide_banner -of default=noprint_wrappers=0 -print_format flat -select_streams v:0 -show_entries stream=pix_fmt "(\1)" >> Sort.txt
Click Replace All. Close Notepad++ and click Yes when asked to save the file.
At the Windows desktop, copy your downloaded ffprobe.exe to \All.
At the command prompt, still in \All, type the following two commands:
REN All-dir.txt All.bat All
This renames the text file we created earlier (All-dir.txt), making it an executable batch file (All.bat), then runs it. Now FFprobe is identifying the pixel formats of the video files copied to \All and the output is being sent to a new text file named Sort.txt. This may take a short while.
Open Sort.txt with Notepad++, make sure the cursor is positioned at beginning and press CTRL + H. Fill in the two text boxes with the following:
Find what:
\Rstreams.stream.0.pix_fmt=
Replace with: (blank)
For clarification, the Replace with box should be empty, and not contain the text "(blank)".
Click Replace All.
This deletes the carriage return after each file name along with the surplus text so the pixel format info which has been output from ffprobe.exe is now on the same line as the file name.
Still within the Replace dialogue box:
Find what:
.*"yuv420p"\R
Replace with: (blank)
For clarification, the Replace with box should be empty, and not contain the text "(blank)".
Click Replace All.
This deletes all videos from the list which have yuv420p pixel format (these videos work OK so don't need converting). Now we have a list of all non-yuv420p videos which need converting. If the file is now blank, that indicates that FFprobe identified all the videos as being yuv420p pixel format.
Still within the Replace dialogue box:
Find what:
(.*) .*
Replace with:
Move (\1) 444
Click Replace All.
This creates the batch contents to move the yuv444p video files to a different folder.
Close Notepad++ and click Yes when asked to save the file.
At the command prompt, still in \All, type the following three commands:
MD 444 REN Sort.txt 444.bat 444
This makes a folder (or directory if you prefer) named 444, renames the edited Sort.txt file to a batch file (444.bat) then runs it. This batch files moves all non-yuv420p videos to the new folder 444 (\All\444).
Still at the command prompt, still in \All, type the following three commands:
CD 444 DIR /B > Make420p.txt MD 420
This changes focus to the newly created folder 444, creates a list of all the video files moved to the 444 folder by outputting the DIR command to a text file (Make420p.txt) within the 444 folder then creates a folder within 444 named 420 (\All\444\420).
At the Windows desktop, copy your downloaded ffmpeg.exe to \All\444.
Open Make420p.txt with Notepad++ and do the following:
- Delete line containing Make420p.txt.
- Delete blank line at the bottom.
Position the cursor at beginning and press CTRL + H. Fill in the two text boxes with the following:
Find what:
(.*)
Replace with:
ffmpeg -i "(\1)" -pix_fmt yuv420p -map_metadata -1 -c:a copy -preset veryslow -crf 25 ".\\420\\(\1)"
Click Replace All.
This creates a batch file to create converted copies of the yuv444p video files to yuv420p video files in the 420 folder.
Close Notepad++ and click Yes when asked to save the file.
At the command prompt, still in \All\444, type the following two commands:
REN Make420p.txt Make420p.bat Make420p
This renames the text file we created (Make420p.txt), making it an executable batch file (Make420p.bat), then runs it. Now FFmpeg is creating yuv420p copies in the 420 folder of the yuv444p videos in the 444 folder. Depending on how many files there are, this may take a while.
When the process is complete, simply copy the newly created video files within \All\444\420 to the respective folder on your Pi and overwrite the old files.
Here is an explanation of the command line options I used for FFmpeg:
- -i filename.mp4 Required. Input file to be converted.
- -pix_fmt yuv420p Pixel format to yuv420p (from yuv444p).
- -map_metadata -1 Remove unnecessary metadata from output file. If you want to keep the metadata, delete this part.
- -c:a copy Copy audio stream rather than re-encoding it. This results in a smaller output file.
- -preset veryslow Creates a smaller output file with none or negligible quality loss but takes a longer time. Delete this if you have limited time or patience.
- -crf 25 Constant Rate Factor of 25. Default is 23. Results in a smaller output file with no NOTICEABLE quality loss.
Through my experimenting, these were my findings of the different command line options with their resulting folder sizes:
My Arcade folder had 2,264 video files. Of these, 578 were of yuv444p pixel format taking up 860mb of space.
- ffmpeg -i input.mp4 -pix_fmt yuv420p -map_metadata -1 -c:a copy output.mp4 (this resulted in the 578 files being 1.08gb).
- ffmpeg -i input.mp4 -pix_fmt yuv420p -map_metadata -1 -c:a copy -preset veryslow output.mp4 (this resulted in the 578 files being 983mb).
- ffmpeg -i input.mp4 -pix_fmt yuv420p -map_metadata -1 -c:a copy -preset -crf 25 output.mp4 (this resulted in the 578 files being 968mb).
- ffmpeg -i input.mp4 -pix_fmt yuv420p -map_metadata -1 -c:a copy -preset veryslow -crf 25 output.mp4 (this resulted in the 578 files being 842mb).
-
-
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.