Skip to content

Instantly share code, notes, and snippets.

@jackersson
Last active March 11, 2019 09:40
Show Gist options
  • Save jackersson/29881d5e1a9265d7d8732f6aaf566cd5 to your computer and use it in GitHub Desktop.
Save jackersson/29881d5e1a9265d7d8732f6aaf566cd5 to your computer and use it in GitHub Desktop.
# Converts video from MPEG to MP4 so it can be opened by VLC or other media player
# And concats if needed
# Run in folder with videos ./mpeg_2_mp4.sh
# chmod u+x ./mpeg_2_mp4.sh
ALL_VIDEOS_FILE="all.txt"
STATUS_FILE="status.txt"
OUTPUT_FOLDER="$PWD/output"
# Remove previous directory if needed
# rm -rf $OUTPUT_FOLDER
if [ ! -d "$OUTPUT_FOLDER" ]; then
mkdir -p $OUTPUT_FOLDER
fi
echo $OUTPUT_FOLDER
if [ -f $ALL_VIDEOS_FILE ] ; then
rm $ALL_VIDEOS_FILE
fi
if [ -f $STATUS_FILE ] ; then
rm $STATUS_FILE
fi
# find videos with format *.
find $PWD -maxdepth 1 -type f -name "*.mp4" > $ALL_VIDEOS_FILE
while read video_file; do
# echo -e "$video_file" >> $STATUS_FILE
# output filename
filename=$OUTPUT_FOLDER/$(basename -- "$video_file")
echo -e "$filename" >> $STATUS_FILE
echo -e "$filename"
# demux -> mux video
gst-launch-1.0 filesrc location=$video_file ! mpegpsdemux ! h264parse ! mp4mux ! filesink location=$filename sync=False -e
done < $ALL_VIDEOS_FILE
# Uncomment next to concat all videos
# cd $OUTPUT_FOLDER
# ffmpeg -f concat -safe 0 -i <(for f in ./*.mp4; do echo "file '$PWD/$f'"; done) -c copy all.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment