• Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login
RetroPie forum home
  • Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login
Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

[SCRIPT] Batch convert YUV 4:4:4 videos to YUV 4:2:0 in Retropie/Linux

Scheduled Pinned Locked Moved Help and Support
omxscriptvideoyuv
66 Posts 15 Posters 16.7k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C
    Clyde
    last edited by Clyde 19 Dec 2017, 14:26

    Hi,

    as many of us know, OMX player doesn't support YUV 4:4:4 (yet?), but scraped videos may be in this format. So, I wrote a script to batch convert only the yuv444p videos in my collection to yuv420p which is compatible with the OMX player.

    The script works in Retropie and current Ubuntu versions & variants. It should also work with any Linux distribution with bash and ffmpeg. Video conversion is very demanding, so you should do this on the fastest machine with Linux you have access to. It works fine on a Raspberry Pi (3b in my case), but you may have to be patient. :)

    The script requires the package ffmpeg which I presume to be pre-installed in Retropie since Selph's scraper should be using it for video conversion. If it's not installed, a quick sudo apt install ffmpeg will do that.

    mkdir -p converted    # create the folder "converted" if it doesn't exist
    for f in *.mp4        # process all videos in the current directory
      do
        echo "$(pwd)/$f"  # show the processed file's name
        c=$(ffprobe "$f" 2>&1 | grep -c yuv444p)  # (-c)ount no. of "444p"
    
        if [ "$c" -gt 0 ]                         # if 444p is present,
          then                                    # convert to 420p
            ffmpeg -i "$f" -y -pix_fmt yuv420p -strict experimental converted/"$f"
        fi
    done
    

    Just save the script into a text file (e.g. 444p-to-420p.sh), make it executable with the command chmod u+x 444p-to-420p.sh, and run it from within your videos directory. Hint: If you store it in a folder called bin in your home directory, it can be executed by only its name from any other folder without having to enter the script's full path.

    See my post below for step-by-step instructions using either RetroPie's command shell or an SSH network connection.

    After the conversion, you should test the videos in converted before finally moving them up one directory level to replace their 444p originals.

    Maybe someone finds this useful. Feel free to correct, improve, or expand it. If you do, please share your work with us.

    Cheers
    Clyde

    H T 2 Replies Last reply 11 Jan 2018, 16:13 Reply Quote 7
    • H
      hiulit @Clyde
      last edited by 11 Jan 2018, 16:13

      @clyde Hi there! I created a script inspired by yours https://retropie.org.uk/forum/topic/15764/retropie-convert-videos :)

      Cheers!

      My little contributions to the RetroPie project:

      • Shell-Script-Boilerplate
      • Fun-Facts-Splashscreens
      • Limit-Last-Played-Games
      C 1 Reply Last reply 13 Jan 2018, 10:20 Reply Quote 2
      • C
        Clyde @hiulit
        last edited by 13 Jan 2018, 10:20

        @hiulit Great, and thanks for the credits. :*)

        H 1 Reply Last reply 13 Jan 2018, 11:15 Reply Quote 1
        • H
          hiulit @Clyde
          last edited by 13 Jan 2018, 11:15

          @clyde Of course! After all, it was your idea :)

          My little contributions to the RetroPie project:

          • Shell-Script-Boilerplate
          • Fun-Facts-Splashscreens
          • Limit-Last-Played-Games
          1 Reply Last reply Reply Quote 0
          • C
            chigundo
            last edited by 19 Jan 2018, 02:12

            dumb question, where do I save the txt script file on the pi's SD in order to run it.

            M 1 Reply Last reply 19 Jan 2018, 05:23 Reply Quote 0
            • M
              mitu Global Moderator @chigundo
              last edited by mitu 19 Jan 2018, 05:23

              @chigundo

              Just save the script into a text file (e.g. 444p-to-420p.sh), make it executable with the command chmod u+x 444p-to-420p.sh, and run it from within your videos directory.

              You can save it in the pi user's home (/home/pi), but you need to execute it from the video folder(s) where your videos are.

              1 Reply Last reply Reply Quote 0
              • C
                Clyde
                last edited by Clyde 19 Jan 2018, 20:21

                @chigundo For example, let's say you want to convert your videos in /home/pi/Retropie/roms/mame-libretro/images and you saved the script in the text file /home/pi/script, then from within the user pi's home (where you'll be after quitting Emulation Station or after logging into Retropie via ssh), you'll run these commands in order:

                chmod u+x script   # make the script executable
                cd Retropie/roms/mame-libretro/images # change into the videos' folder
                mkdir converted    # create the folder for the converted videos
                sh /home/pi/script # start the script
                

                Everything behind # in a line is a comment and doesn't have to be entered. The chmod and mkdir commands are only needed once and should be omitted at any subsequent uses.

                In the example, I didn't give the file script a filename extension because that's not customary on Linux. You are free to call the file any way you like.

                FYI: To start the script, sh ../../../../script and sh ~/script would also work. The former uses a relative path four levels upwards from the images folder, the latter uses the shorthand symbol ~ for the current user's home directory.

                C 1 Reply Last reply 27 Jan 2018, 16:55 Reply Quote 0
                • C
                  Clyde @Clyde
                  last edited by 27 Jan 2018, 16:55

                  @clyde said in Here's a script to batch convert YUV 4:4:4 videos to YUV 4:2:0 in Retropie/Linux:

                  FYI: To start the script, sh ../../../../script and sh ~/script would also work. The former uses a relative path four levels upwards from the images folder, the latter uses the shorthand symbol ~ for the current user's home directory.

                  I forgot the easiest way: Create a directory named bin in your home directory and put the script there. $HOME/bin (or ~/bin) is part of the paths the Linux shell looks for console commands, so everything put there will be found from anywhere in the directory tree. For example, the starting line in my last post would just be script.

                  1 Reply Last reply Reply Quote 0
                  • T
                    thelostsoul @Clyde
                    last edited by 21 Mar 2018, 09:55

                    @clyde Thank you for this.
                    Until now, I had to test each video manually in Emulation station and then go back to pc, copy and recode each single one by VCL player and update videos. And I did not know what caused this problem. You really helped me a lot with this, plus I know the reason why those videos did not work.

                    📜 RE/SET: 100 SNES Games for your RetroPie, 🎁 Share your hidden gems and insider tips

                    C 1 Reply Last reply 21 Mar 2018, 12:39 Reply Quote 1
                    • C
                      Clyde @thelostsoul
                      last edited by 21 Mar 2018, 12:39

                      @thelostsoul My pleasure. :) Be sure to check out @hiulit's script, too. It has way more options than mine.

                      1 Reply Last reply Reply Quote 2
                      • C
                        Clyde
                        last edited by 21 Mar 2018, 12:56

                        Update: 1. The script now creates the target folder "converted" if it doesn't exists. 2. Added the information about the bin folder to the opening post.

                        T 1 Reply Last reply 21 Mar 2018, 13:07 Reply Quote 0
                        • T
                          thelostsoul @Clyde
                          last edited by 21 Mar 2018, 13:07

                          @clyde Funny, did you hack me? I did this update too first time creating it. :P But thanks anyway.

                          Just thinking about it, is it possible to integrate this script to ReteroPie sselph scraper? It could be an optional feature to execute it automatically after scraping.

                          📜 RE/SET: 100 SNES Games for your RetroPie, 🎁 Share your hidden gems and insider tips

                          C H 2 Replies Last reply 21 Mar 2018, 13:20 Reply Quote 0
                          • C
                            Clyde @thelostsoul
                            last edited by 21 Mar 2018, 13:20

                            @thelostsoul Interesting idea, I'll look into that later when I have more time.

                            1 Reply Last reply Reply Quote 0
                            • H
                              hiulit @thelostsoul
                              last edited by 21 Mar 2018, 14:27

                              @thelostsoul @Clyde There's already a convert function in Sselph Scrapper -convert_videos. But the script must be run via the terminal, something like this:

                              /opt/retropie/supplementary/scraper/scraper -convert_videos
                              

                              See the RetroPie documentation: https://github.com/retropie/retropie-setup/wiki/scraper#parameter-list

                              P.S. I don't know exactly what it does, it only says "Convert videos for the Raspberry Pi" and Handbrake must be installed.

                              My little contributions to the RetroPie project:

                              • Shell-Script-Boilerplate
                              • Fun-Facts-Splashscreens
                              • Limit-Last-Played-Games
                              C 1 Reply Last reply 21 Mar 2018, 17:45 Reply Quote 0
                              • C
                                Clyde @hiulit
                                last edited by 21 Mar 2018, 17:45

                                @hiulit It's a script, so we could inspect it for its function. Alas, my Raspberry isn't operational at this time, because my upright cabinet is in its last stages to completion, but currently dismantled.

                                1 Reply Last reply Reply Quote 1
                                • H
                                  hiulit
                                  last edited by hiulit 16 Apr 2019, 09:26

                                  In case anyone in this thread is interested, I released v2.0.0 of RetroPie Convert Videos.

                                  My little contributions to the RetroPie project:

                                  • Shell-Script-Boilerplate
                                  • Fun-Facts-Splashscreens
                                  • Limit-Last-Played-Games
                                  1 Reply Last reply Reply Quote 0
                                  • H
                                    hiulit
                                    last edited by 17 Apr 2019, 08:39

                                    Just released yet another version of RetroPie Convert Videos (v2.1.0).

                                    My little contributions to the RetroPie project:

                                    • Shell-Script-Boilerplate
                                    • Fun-Facts-Splashscreens
                                    • Limit-Last-Played-Games
                                    1 Reply Last reply Reply Quote 1
                                    • QuackwalksQ
                                      Quackwalks
                                      last edited by Quackwalks 17 Apr 2019, 12:59

                                      As I follow the instructions I get this. /home/pi/444p-to-420p.sh: 3 /home/pi/444p-to-420p.sh: Syntax error: word unexpected (expecting "do")

                                      For a layman like me this is quite the frustration. It expects the word "do" on line 3? Oh. Okay! It's like, the only word on line 3, so I don't know what more you expect, Mr. fussy computer pants. Please help. This is the last thing I have to do to get my retropie image perfect.

                                      C 1 Reply Last reply 18 Apr 2019, 11:26 Reply Quote 0
                                      • C
                                        Clyde @Quackwalks
                                        last edited by Clyde 18 Apr 2019, 11:26

                                        @Quackwalks Hm … it works on the Linux system on my Laptop (KDE Neon based on Ubuntu 18.04). I can test it on my Retropie system this evening.

                                        What system did you create and/or are you running the script on? What were the exact steps you took to create the file? Could you please post your script into a codeblock here? (Just to check if there were any copying errors.)

                                        edit: Maybe your system saved the wrong line endings. For example, Windows uses CR LF (0d 0a) while Unix-like systems like Linux only use LF (0a). See here how to remove any CR from the file. As a 99% Linux user, I don't have any experience in this, but It may be worth a try.

                                        1 Reply Last reply Reply Quote 0
                                        • QuackwalksQ
                                          Quackwalks
                                          last edited by Quackwalks 18 Apr 2019, 11:58

                                          mkdir -p converted                         # create the folder "converted" if it doesn't exist
                                          for f in *-video.mp4                       # process all videos
                                            do
                                              c=$(avprobe $f 2>&1 | grep -c yuv444p) # (-c)ount no. of "444p"
                                          
                                              if [ "$c" -gt 0 ]                      # if 444p is present,
                                                then				   # convert into 420p
                                                  avconv -i $f -y -pix_fmt yuv420p -strict experimental converted/$f
                                              fi
                                          done
                                          

                                          I highlighted the text from your code block then copy and pasted it into notepad++. Saved it with UTF-8 encoding as a .sh file. Used WinSCP to copy it into home/pi. On the raspberry pi 3b+ running retropie 4.4, I quit emulationstation and used the chmod command with no problem. Then entered cd home/pi/RetroPie/roms/fba/media/videos, then sh/home/pi/444p-to-420p.sh, which gives me the syntax error. The converted video folder was created just fine.
                                          The system I tried it for is fba. I used Skraper and the Screen Scraper database to scrape my roms, which left me with .mp4 files that had names identical to the roms (not having -video at the end of the file names). Don't go to any great trouble for me. I realized last night I had backup videos from a previous image. I used XML Scraper V2 back then, so last night used a bulk rename application to rename them without "-video" at the end. The funny thing is that I used this script about a year ago for the videos I had backed up, so it worked for me then. It's a real noodle scratcher for me.

                                          M 1 Reply Last reply 18 Apr 2019, 12:05 Reply Quote 0
                                          • First post
                                            Last post

                                          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.

                                            [[user:consent.lead]]
                                            [[user:consent.not_received]]