I have a script I wrote a long time ago that does something similar, except that I copy the audio and subtitle streams always. I found a couple things:
If the source is from Blu-Ray and audio is LPCM, then you have to convert it since MKV does not support LPCM
I had to handle the stream mapping differently if the source is from DVD and has a stream called dvd_nav_packet in it
Here is the code I used if you are interested (${vidinp} is the input video file of course):
ffprobe "${vidinp}" -show_streams -v quiet | while read line; do
if [[ $line = *"pcm_bluray" ]]; then
islpcm="true"
fi
if [[ $islpcm = "true" && $line = *"sample_fmt"* ]]; then
audio="-c:a:$(( audcnt - 1 )) pcm_${line#*=}be"
break
fi
done
if [[ $vobfmt = *"dvd_nav_packet" ]]; then
outmap="-c:a copy"
else
outmap="-map 0 -c copy"
fi
Yes, I pull out the main video, main audio, and english subtitle tracks from the disk and then then move the resulting M2TS or VOB to the server and then let the script encode it into MKV with HEVC video and copy the audio and subs where possible.
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
Apologies for the late reply @syluccy - I’ve been working my butt off.
I’ve just read your other thread:
You’re absolutely right. That’s probably what caused the issue. I kinda new about it, but completely forgot to test it.
On that note: Well done for fixing it up! That’s awesome!
Do you mind if I grab your logic, so I can test/integrate it into my script? That may solve a lot of issues I’ve had with naming. Efficiency in code would be awesome