UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Fixing corrupted videos recorded with Google Pixel 3A + UBPorts OTA23

    Scheduled Pinned Locked Moved Support
    1 Posts 1 Posters 78 Views 1 Watching
    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.
      • P Offline
        ptrkrysik
        last edited by ptrkrysik

        I was looking for a solution how to fix videos corrupted during recording with Google Pixel 3A + UBPorts OTA23 (16.04). There was an issue described for example here:

        Re: Video recording not working on Google Pixel 3a XL

        which resulted with videos that had absurdly wrong FPS. I had videos that were 3 minutes long but appeared as 15 hours long. Sound was ok, but the video part was viewable about one hour later.

        As the phone was used as daily driver (and still is but currently with Focal) I had some important videos recorded with it that I was very motivated to repair. I didn't find anything on the internet so here is a bash script that I created with help of chatgpt, that does the job (I wouldn't know about existence of MP4Box without chatgpt, obtaining a good result was much easier with that program than with ffmpeg):

        #!/bin/bash
        # Target FPS setting
        FPS=29.97
        
        # Create a directory for the fixed files
        mkdir -p fixed
        
        # Loop through all .mp4 files in the current directory
        for file in *.mp4; do
            echo "Processing: $file"
        
            # Base name without extension
            base="${file%.*}"
        
            # Demux (extract) video and audio streams
            MP4Box -raw 1 "$file" -out "${base}_track1.h264"
            MP4Box -raw 2 "$file" -out "${base}_track2.aac"
        
            # Re-mux into a new MP4 with corrected FPS
            MP4Box -add "${base}_track1.h264:fps=$FPS" -add "${base}_track2.aac" -new "fixed/${base}_fixed.mp4"
        
            # Clean up temporary files
            rm -f "${base}_track1.h264" "${base}_track2.aac"
        
            echo "Done: ${base}_fixed.mp4"
        done
        
        echo "All files have been processed and saved in the 'fixed/' directory."
        

        The synchronization of voice and picture is not ideal but for short videos it's ok.

        1 Reply Last reply Reply Quote 0
        • P ptrkrysik referenced this topic
        • P ptrkrysik marked this topic as a regular topic
        • First post
          Last post