#!/bin/sh ## ## SCRIPT: 00_ffmpeg_CONVERTmovie_to_h264-aac-mp4.sh ## ## PURPOSE: Convert a movie file (such as '.mpg', '.avi', '.wmv') to ## a '.mp4' movie file --- with 'h264' video stream and ## 'aac' audio stream. ## ## REFERENCE1: ## ## https://www.streamingmedia.com/Articles/ReadArticle.aspx?ArticleID=133179 ## (2019 Jul) ## Here's the basic FFmpeg command line structure: ## ## ffmpeg -i input.mp4 output.mp4 ## ## FFmpeg can input most container formats natively, including MP4, ## .ts, MOV, AVI, Y4M, MKV, and many others. ## ## Note that unless you identify an audio or video codec via switches, ## FFmpeg will use the default codecs for each container format ## as well as reasonable encoding parameters. ## ## ** For the MP4 extension, if you input a 1080p file, FFmpeg will encode ## ** using the H.264 video codec at about 9 to 10 Mbps, the AAC audio codec ## ** at around 130 Kbps, a keyframe interval of 250 frames, the High profile, ## ** and the medium x264 preset. ## ## *** All of these are customizable, of course, but if all you're trying to do ## *** is to create a video file you can play from a hard drive, ## *** the command above will suffice. ## ## REFERENCE2: (in case the simple command above does not work) ## ## https://duduf.com/easily-transcode-any-media-to-any-format-using-ffmpeg/ ## (2017 Oct) ## ## An excerpt: ## ## If you need to change some parameters of the video, you can input ## a new size, change the framerate, change the audio sampling... ## ## ffmpeg -i "example video.mov" \ ## -vcodec h264 -b:v 10485760 \ ## -s 1998x1080 \ ## -r 24 -acodec aac -b:a 327680 -ar 96000 \ ## "transcoded video.mp4" ## ## The size is changed to a standard 2K Flat DCP of 1998 pixels width by 1080 pixels ## height with the -s option, the framerate to 24fps with the -r option, and ## the sound is resampled to 96KHz thanks to the -ar option. ## ## METHOD OF USE: ## 1) Put this script in the directory of to-be-converted movie files ## that you want to convert to 'filename_h264-aac.mp4'. ## 2) Edit this script to set the input & output filenames. ## 3) Run the script in a terminal window positioned at the directory ## that holds this script and the movie files. ## ## DEVELOPED WITH: ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 ## ## Script started: 2021jul15 ## ffmpeg -i \ input_40sec_640x480_mpeg1-mp2.mpg \ output_40sec_640x480_h264-aac.mp4 # 00_temp.mp4 # totem 00_temp.mp4 # ffplay 00_temp.mp4 exit