Fixing corrupted videos recorded with Google Pixel 3A + UBPorts OTA23
-
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.
-