It’s been a few months without an update. I’ve made some great strides in the logic and options.
What’s New?
New Option “vbitrate” - You can now use “auto” which will set a default of 1 Byte per pixel, or you can override the logic with a specific number like you would in ffmpeg (using the standard options of K, M or G eg. “10M”)
New Option “hw” - Now you can choose either “cpu” or “vaapi”, meaning you can now use the script even if you don’t have hardware acceleration available
New Option “overwrite” - Instead of deleting your original files, you can now choose to create a backup instead. The original file will be renamed *.bak. If you are satisfied that this script is capable of carrying out the tasks you want it to, you can choose “yes” to replace the original file
New Logic “bitrate” - Using the height and width of input video, the bitrate is calculated per pixel using a simple height x width formula. This can be overridden as listed above
New parameters - x265 parameters have been added and can be manually tweaked if needed
New Logic “transcode” - using the “hw” option, the logic determines how to use the output, either with vaapi or cpu transcoding
New Logic for file moves - when encoding the file, the output is to the $tempdir using the original file name (making it easier to find if needed). It is then moved after transcoding is complete, taking into account the “overwrite” parameter
Removed Logic h264 - The script no longer outputs in h264 as this codec is already easily accessible via other tools, so is wasted effort in this script
Removed Option - No longer extracts to RGB, difference was negligible, and added extra transcoding time
Currently, the script is capable of:
Accepting almost any format supported by FFMPEG
Automatically determining the input video and audio codec
Making automatic choices for output, based on the input
Altering its output method to best suit the input combination of video and audio streams
Outputting to an MKV or MP4 container
HEVC Video encoding
Transcoding to AAC Audio
Detect and convert Rext profile videos
AAC & AC3 Audio Passthrough
Parsing intire libraries, including those without escaped characters
Replacing the file(s) after transcode, or creating backups
Re-mapping audio of *.ogv files during transcoding
Adjusting FPS during transcode
Adjusting Preset and CRF
Manually selecting Audio Sample Rate during transcode of non AAC or AC3 audio
Preliminary QuickSync transcoding support for hevc
Adding more options and better logic has been difficult for me (non programmer that I am), but I’m slowly getting better at it. The more I work on it, the more I understand how to do it better. I’ll continue to work on it as I have the time. I’ve been enjoying seeing the progress
To save the amount of processing time you’re expending there, there is a much faster way if you only wish to change the container. Using this, you can now add your desired conversion parameters if you want more than only a container change.
#!/bin/tcsh
foreach i (*.avi *.m4v *.mpg *.mp4)
ffmpeg -i "$i" -c:v copy -c:a copy "${i:r}.mkv"
end
@ChuckPa said:
To save the amount of processing time you’re expending there, there is a much faster way if you only wish to change the container. Using this, you can now add your desired conversion parameters if you want more than only a container change.
Yup, that’d work. I just wanted it expanded so it kept in line with all the other options. That way you can still encode/transcode either video or audio with just a minor adjustment to the script. It’s just more logically laid out. You’re free to shorten it for your own use of course
@ChuckPa said:
tcsh runs in linux and bsd. I’m running fedora (redhat) https://www.freebsd.org/cgi/man.cgi?tcsh(1)
@peva said:
How does this script deal with multiple audio tracks and multiple subtitles?
it’s not the script which deals with this. The script simply runs ffmpeg for each of the files it finds. The -c copy option for ffmpeg copies all audio, video, and subtitles, as they are. This is where you are free to make any changes and perform actual conversions if you wish.
@peva said:
How does this script deal with multiple audio tracks and multiple subtitles?
Like ChuckPa said, it assumes that there is only a single video track, and then converts all audio contained in the file to AAC to match the h264 of the MKV container. I chose h264 and AAC as they are the most compatible with my devices, but you can adjust it to any codec that suits you.
You could use libxvid and mp3 if you want use and AVI container
@sremick said:
Might need to try this on FreeBSD. Thanks
Awesome, let me know how you go! I’m not sure avconv is available on BSD, but you could rather easily adjust the script to use ffmpeg (avconv is a fork of ffmpeg. it contains more up to date codec support and the latest bug fixes)
@ChuckPa said:
To show what ffmpeg can do, give this a read. It’s an absolutely amazing tool.
It truly is. I used to use ffmpeg, once avconv was supported by most of my apps, I switched. But the differences are negligible. Almost any script that can run on ffmpeg, can be converted to avconv and vice versa.
@ntrevena said:
It truly is. I used to use ffmpeg, once avconv was supported by most of my apps, I switched. But the differences are negligible. Almost any script that can run on ffmpeg, can be converted to avconv and vice versa.
avconv and ffmpeg are forks of the same base. I forget the reasons for the fork but I’m sure you can find it out.
To all: Remember, the -c copy refers to the copy codec which simply takes input “AS-IS” and copies to the ouput. The output file handler puts it new container format. The long form of this command, which makes the next step(s) more obvious is:
This expressly specifies “video copy, audio copy, and subtitle copy”
With this as the long form, it’s now easy to see how the video, audio, and subtitle tracks can be manipulated. To aid with files which have multiple tracks of audio/video/subtitles, the -map option allows for appropriate selection.
Enjoy
edit: I think substituting the ffmpeg command with avconv will do the same operation without altering any of the command line parameters
@ChuckPa said:
avconv and ffmpeg are forks of the same base. I forget the reasons for the fork but I’m sure you can find it out.
Yup. If I remember rightly, Canonical threw their weight behind libav. The team behind libav were originally core developers of ffmpeg. From what I recall, the devs who left to start libav, had a disagreement with the other devs about the future of ffmpeg. Some believed features were more important, others that the API and stability was the future. Those behind the API and stability, were those who left to start libav.
There is a small issue here, it doesn’t take into account the incompatibilities between codec and container. For example, if you choose an input file of h264 mp4, and an output of 3gp, then it would corrupt the output file. The input codec has to be transcoded to h263. for it to work with the 3gp container. Does that make sense?
@ChuckPa said:
To aid with files which have multiple tracks of audio/video/subtitles, the -map option allows for appropriate selection.
Very cool, didn’t think about subtitles. I’ll add that in the next iteration of the script.
@ChuckPa said:
edit: I think substituting the ffmpeg command with avconv will do the same operation without altering any of the command line parameters
Should do, though avconv can be a little particular. Test and see!