Created
January 23, 2023 18:22
-
-
Save mikesparr/d73392ddaefc0dd2cc885544ffac1335 to your computer and use it in GitHub Desktop.
Experiment fixing missing file duration metadata using ffmpeg for Google Cloud Platform (GCP) Transcoder API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
##################################################################### | |
# REFERENCES | |
# - https://cloud.google.com/transcoder/docs/transcode-video#create-job-from-preset-python | |
# - https://ffmpeg.org/ffmpeg.html#Stream-copy | |
##################################################################### | |
export PROJECT_ID=$(gcloud config get-value project) | |
export PROJECT_USER=$(gcloud config get-value core/account) # set current user | |
export PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format="value(projectNumber)") | |
export IDNS=${PROJECT_ID}.svc.id.goog # workflow identity domain | |
export GCP_REGION="us-central1" # CHANGEME (OPT) | |
export GCP_ZONE="us-central1-a" # CHANGEME (OPT) | |
export NETWORK_NAME="default" | |
# enable apis | |
gcloud services enable compute.googleapis.com \ | |
storage.googleapis.com | |
# configure gcloud sdk | |
gcloud config set compute/region $GCP_REGION | |
gcloud config set compute/zone $GCP_ZONE | |
# pull file | |
export PROB_FILE_NAME="prob-file.mpg" | |
export REF_FILE_NAME="ref-file.mpeg" | |
export NEW_FILE_NAME1="copied-file-1.mpg" | |
export PROB_FILE_URL="https://storage.googleapis.com/lumen5-prod-video/shutterstock997294tprEe9.mpg" | |
export REF_FILE_URL="https://filesamples.com/samples/video/mpeg/sample_640x360.mpeg" | |
# pull reference file | |
curl -o $REF_FILE_NAME $REF_FILE_URL | |
# pull problem file | |
curl -o $PROB_FILE_NAME $PROB_FILE_URL | |
# install local tooling and test | |
brew install ffmpeg | |
# test ref file (13.279933) | |
ffprobe -v error -select_streams v:0 \ | |
-show_entries stream=duration \ | |
-of default=noprint_wrappers=1:nokey=1 $REF_FILE_NAME | |
# test prob file (N/A) | |
ffprobe -v error -select_streams v:0 \ | |
-show_entries stream=duration \ | |
-of default=noprint_wrappers=1:nokey=1 $PROB_FILE_NAME | |
# copy file (using ffmpeg) | |
ffmpeg -i $PROB_FILE_NAME -vcodec copy -acodec copy $NEW_FILE_NAME1 | |
# test copied file (3.291667) | |
ffprobe -v error -select_streams v:0 \ | |
-show_entries stream=duration \ | |
-of default=noprint_wrappers=1:nokey=1 $NEW_FILE_NAME1 | |
# (optional) test against transcoder API |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Overview
A customer had some Google Cloud Platform (GCP) Transcoder API errors on certain files. It was discovered that these files were missing the video duration in the metadata.
Experiment
ffprobe
toolffmpeg
copy feature and retryResult
Cleanup
Be sure if you create any resources on the cloud, to delete them or the GCP project to avoid unnecessary charges.