MartinEesmaa / VVCEasy

VVCEasy is that you don't have to compile or/and coding to encode VVC (known as Versatile Video Codec). Simple. Easy. Encode. Decode
https://martineesmaa.org/en/vvceasy
MIT License
145 stars 15 forks source link

I wrote about utilizing FFMPEG-VVENC to convert photos and videos in two batch files. #47

Closed jiangzemin-xudamin closed 4 weeks ago

jiangzemin-xudamin commented 1 month ago

Hi Martin, I'm going to write two batch files that I hope will help more people. Please help me to modify the commands if you have ideas for improvement.

First, the command about compressing photos:


cd /d %~dp0 
for %%a in (*.png *.jpg *.jpeg *.heif *.avif) do ( 
.\ffmpeg_vvceasy -i "%%~sa" -threads 32 -c:v libvvenc -preset 4 -b:v 0 -qp 35 -an -sn "output\%%~na.h266" 
) 
pause

Second, the command about compressing videos:


cd /d %~dp0 
for %%a in (*.mp4) do ( 
mp4box -add "%%~sa"#audio -new ".\output\%%~na.m4a" 
) 
::Extract audio streams from MP4 files to M4A files and manually drag the M4A files to "EZ CD Audio Converter" to batch process them separately
::, avoiding part of the video containing mono channels from being converted to dual channels.
for %%a in (*.mp4) do ( 
.\ffmpeg_vvceasy -i "%%~sa" -threads 32 -c:v libvvenc -preset 4 -b:v 0 -qp 35 -an -sn ".\output\%%~na.mp4"
)
::If I directly convert the MP4 file to a VVC file, it may cause the original 60 fps video to become 25 fps and slow down, which seems to be the bug!
for %%a in (.\output\*.mp4) do ( 
.\ffmpeg_vvceasy -i "%%~sa" -c:v copy ".\output\%%~na.vvc"
)
::The converted mp4 file can't drag the progress bar during playback, and you can only extract the video stream to a VVC file for normal use.
cd .\output\
del *.mp4
::Only vvc file is needed
for %%a in (*.vvc) do (
mp4box -add "%%a" -add "%%~na.m4a" -new "%%~na.mp4"
)
del *.m4a
del *.vvc
::After merging to MP4, clear unnecessary files
pause
jiangzemin-xudamin commented 1 month ago

I had a lot of trouble compressing the video, and I also tried to compress the audio stream with "exhale" (from https://www.mediafire.com/file/eq0ymgo2o72f09o/), but its " README.md" file says this:

Important: Due to the missing lower-rate coding tools, the audio quality at the lowest of exhale's bit-rate modes (18 kbit/s mono, 36 kbit/s stereo) doesn't reflect the full capabilities of the Extended HE-AAC standard. Therefore, use the lowest bit-rate modes only when required. Also, please don't attempt to modify exhale's source code or to configure the command-line encoder to produce lower bit-rates. Use only existing presets and input sampling rates of 32...48 kHz.

So, I had to give up it

jiangzemin-xudamin commented 1 month ago

Without those bugs, I wouldn't have to write such cumbersome commands, and if your modification of ffmpeg supports xHE-AAC directly, I could even solve it with just a "for" loop

jiangzemin-xudamin commented 1 month ago

The trial period for EZ CD Audio Converter, which I have installed on this computer, has expired. However, there are cracked versions available online, and although it is legally illegal to use pirated software, this has been the easiest way to get the Fraunhofer IIS xHE-AAC encoder.

MartinEesmaa commented 4 weeks ago

Hello, @jiangzemin-xudamin! Thank you for your additional more information to me!

Looks your two batch files are good, but I can improve by my explanations and also you can use assistant AI chatbot to help your codes by your explanation.

For your code line: for %%a in (*.png *.jpg *.jpeg *.heif *.avif) do (

You may need to add .jxl which is JPEG-XL format container. Also you can create and view help message to print in terminal, when user types yourcompress.bat -h and you can combine two batch script files into one by creating arguments and detect file container name

I had a lot of trouble compressing the video, and I also tried to compress the audio stream with "exhale" (from https://www.mediafire.com/file/eq0ymgo2o72f09o/), but its " README.md" So I had to give up it

Exhale encoder is okay, but this is only constrained variable bit-rate (CVBR) mode used to encode xHE-AAC by range from 1 to 9 and a to g. Also it accepts fully to encode mono/stereo, but 5.1 channels can encode and can't playback for xHE-AAC 5.1 only. xHE-AAC can be encoded/decoded via supported maximum stereo channels

Here's example how to encode xHE-AAC audio:

exhale 3 sample.wav sample.m4a

Pipe with FFmpeg stereo channels:

ffmpeg -i sample.mp4 -c copy -f wav -ac 2 - | exhale 3 sample.m4a

There's more information that can help you by wiki on Exhale GitLab: https://gitlab.com/ecodis/exhale/-/wikis/faq

Without those bugs, I wouldn't have to write such cumbersome commands, and if your modification of ffmpeg supports xHE-AAC directly, I could even solve it with just a "for" loop

For piping FFmpeg to Exhale encoder is supported, which exhale supports pipe. For encoding xHE-AAC content, FFmpeg & libfdk_aac doesn't have an official xHE-AAC encoder, however Mainconcept FFmpeg xHE-AAC encoder plug-in has available, but you can try demo via form or you can buy xHE-AAC license from MainConcept to get a copy.

Learn more: https://www.mainconcept.com/ffmpeg Source code of Mainconcept FFmpeg plugins: https://github.com/MainConcept/mc-ffmpeg-omx/tree/omx_6.0_public_3.0 Resource: https://www.mainconcept.com/hubfs/PDFs/Datasheets/FFmpeg_xHE-AAC_Encoder_DATASHEET.pdf?hsLang=en User Guide: https://www.mainconcept.com/hubfs/PDFs/User%20Guides/MainConcept_xHE-AAC_Encoder_Plug-In_for_FFmpeg_UserGuide.zip

The trial period for EZ CD Audio Converter, which I have installed on this computer, has expired. However, there are cracked versions available online, and although it is legally illegal to use pirated software, this has been the easiest way to get the Fraunhofer IIS xHE-AAC encoder.

Well it is trialware Poikosoft allows you to use EZ CD Audio Converter for 21 days or 3 weeks until it expires the user has to buy new license to continue. Well yeah...

Any questions or issues, feel free to let me know. :) Thank you! :)

Regards

jiangzemin-xudamin commented 4 weeks ago

Thank you, Martin. You are a good and helpful boy.

jiangzemin-xudamin commented 2 weeks ago
md output
for %%a in (*.png *.jpg *.jpeg *.heif *.avif *.jxl) do ( 
.\ffmpeg_vvceasy -i "%%~sa" -threads 32 -c:v libvvenc -preset 4 -vvenc-params mtprofile=0 -b:v 0 -qp 35 -an -sn ".\output\%%~na.h266" 
) 
for %%a in (*.webm *.mkv) do ( 
.\ffmpeg_vvceasy -i "%%~sa" -c copy "%%~na.mp4"
)
del *.webm
for %%a in (*.mp4) do ( 
.\ffmpeg_vvceasy -i "%%~sa" -vn -sn -c:a pcm_s32le -f wav - | .\exhale b ".\output\%%~na.m4a"
)
for %%a in (*.mp4) do ( 
.\ffmpeg_vvceasy -i "%%~sa" -threads 32 -c:v libvvenc -preset 4 -vvenc-params mtprofile=0 -b:v 0 -qp 35 -an -sn ".\output\%%~na.mp4"
)
::If I directly convert the MP4 file to a VVC file, it may cause the original 60 fps video to become 25 fps and slow down, which seems to be the bug!
for %%a in (.\output\*.mp4) do ( 
.\ffmpeg_vvceasy -i "%%~sa" -c:v copy ".\output\%%~na.vvc"
)
::The converted mp4 file can't drag the progress bar during playback, and you can only extract the video stream to a VVC file for normal use.
cd .\output\
del *.mp4
::Only vvc file is needed
for %%a in (*.vvc) do (
mp4box -add "%%a" -add "%%~na.m4a" -new "%%~na.mp4"
)
del *.m4a
del *.vvc
::After merging to MP4, clear unnecessary files
pause