Can this be done in Handbrake or FFMPEG

455 views Asked by At

Just wonder this could be done in Handbrake or FFMPEG. Any other transcoding software in Windows or MacOS would also be acceptable.

I have many family videos, shooted with DSLR/action cam/phone. And the files are really huge without transcoding them. There are something I would like to have,

  1. Metadata should be all captured. Using Handbrake would not be able to capture the information of the used device. Also, the capture date will become the transcoding date which is definitely unacceptable.

  2. I would like to transcode them into HEVC (H.265)

  3. I need to batch transcode them since there're a lot of videos.

If it's possible (not neccessary), I would also like to have the filename as "YYYYMMDD_HHMMSS".

I think both 1 and 3 are quite frequently asked questions. This thread will be quite useful to all people who are looking for the same answer as well. Thanks a lot!

3

There are 3 answers

2
Markus Schumann On

I'd say no.

Traditionally metadata handling in video is done fairly poorly - unlike still images. I have a similar issue and probably end up rolling my own. I assume you'd like to go to MP4 or MOV which has a number of different metadata styles: MP4, QuickTime, iTunes style, 3gpp, embedded ID3 (similar to MP3) etc. Since writing support of video metadata is done poorly - so is reading of video metadata. You could write more than one style into the file - hoping the tools that don't understand it will ignore the unknown metadata.

As of now I would transcode to MOV/H.265 and use Apple style metadata so that it works correctly on my iPhone/iPad/AppleTV and Mac.

Unfortunately - sometimes the answer is there is no answer but I'd love to be proven wrong.

0
AudioBubble On

You need to put your videos inside "inputs" folder in the FFmpeg directory. Then run this .bat file from the same directory that FFmpeg exists:

@echo off
mkdir inputs
mkdir outputs
set "InputFolder=%~dp0inputs"

:Begin
echo.
set /P fileformati=Insert the input format: 

echo.
set /P fileformato=Insert the output format: 

echo.
echo Press 1 to select CRF 16
echo Press 2 to select CRF 18
echo Press 3 to select CRF 20
echo Press 4 to select CRF 23
echo.

choice /c 1234 /M "Select: "
if %errorlevel% EQU 4 set crfnumber="23"
if %errorlevel% EQU 3 set crfnumber="20"
if %errorlevel% EQU 2 set crfnumber="18"
if %errorlevel% EQU 1 set crfnumber="16"

echo.
echo Press 1 to select the "YUV 4:2:0 planar 8-bits color format"
echo Press 2 to select the "YUV 4:2:0 planar 10-bits color format"
echo Press 3 to select the "YUV 4:2:0 planar 12-bits color format"
echo Press 4 to select the "YUV 4:2:2 planar 8-bits color format"
echo Press 5 to select the "YUV 4:2:2 planar 10-bits color format"
echo Press 6 to select the "YUV 4:2:2 planar 12-bits color format"
echo Press 7 to select the "YUV 4:4:4 planar 8-bits color format"
echo Press 8 to select the "YUV 4:4:4 planar 10-bits color format"
echo Press 9 to select the "YUV 4:4:4 planar 12-bits color format"
echo.

choice /c 123456789 /M "Select: "
if %errorlevel% EQU 9 set colorformat="yuv444p12le"
if %errorlevel% EQU 8 set colorformat="yuv444p10le"
if %errorlevel% EQU 7 set colorformat="yuv444p"
if %errorlevel% EQU 6 set colorformat="yuv422p12le"
if %errorlevel% EQU 5 set colorformat="yuv422p10le"
if %errorlevel% EQU 4 set colorformat="yuv422p"
if %errorlevel% EQU 3 set colorformat="yuv420p12le"
if %errorlevel% EQU 2 set colorformat="yuv420p10le"
if %errorlevel% EQU 1 set colorformat="yuv420p"

for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
set "fullstamp=%YYYY%%MM%%DD%_%HH%%Min%%Sec%"
echo fullstamp: "%fullstamp%"

for /R "%InputFolder%" %%i in (*.%fileformati%) do (ffmpeg -n -i "%%~dpni.%fileformati%" -c:v libx265 -preset:v slow -crf %crfnumber% -vf format=%colorformat% -c:a copy -movflags use_metadata_tags -map_metadata 0 "outputs\%fullstamp% - %%~ni.%fileformato%")

timeout /t 10
0
Max Vilimpoc On

tl;dr - watch the video explainer:

https://youtu.be/ZiGeVvNGn9c

I came up with two different ways to batch transcode a folder full of video files using ffmpeg. As far as I know, ffmpeg will copy over all metadata without modification.

Pure Python Way

https://github.com/nuket/Shrinkr#shrinkr-batch-transcode-python-edition

SCons Way

https://github.com/nuket/Shrinkr#shrinkr-batch-transcode-scons-edition

One uses pure Python, the other uses SCons build scripts. Transcoding video can be conceptually similar to compiling software, so, I gave this a shot.

Both ways will let you run the batch repeatedly and will not repeat work, already-transcoded files won't be done again unless the source files change.

Of the two ways, I prefer the SCons method, because it leverages the SCons build system to check for changes to the input / output files. The one downside to SCons is that for some reason it takes a while to start running, but once it figures out what it needs to do, it will execute all of the ffmpeg calls quickly.

To get started, all you need to do is:

  1. pip3 install scons
  2. git checkout https://github.com/nuket/Shrinkr
  3. Copy ShrinkrArchive to the folder with all the videos. (Rename the file if you want.)
  4. Edit this line to set the ffmpeg parameters you want.
  5. Edit this line to gather up all the files you want (i.e. *.mp4 or *.mkv).
  6. Open up a command-line prompt in that folder.
  7. Run scons -f ShrinkrArchive.

You'll need a copy of ffmpeg somewhere in your system PATH, and of course, a working copy of Python 3.x.

Otherwise, it's pretty easy to use. I've been using it to transcode screencasts to more highly-compressed versions, before kicking them out to cold storage and getting file size savings between 66 - 75%. (Screencasts are usually low-entropy.)

@Takin - to your request:

If it's possible (not neccessary), I would also like to have the filename as "YYYYMMDD_HHMMSS".

You can do this as well in an the ShrinkrArchive file (which is just an SCons build script), you'd have to add a file stat call to the file name emitter and change this line, which determines what to call the output file.

This is an exercise left up to the reader, however.

Anyways, hope this helps anyone who needs to transcode a bunch of files and doesn't want to use a GUI to do it.

If anyone has questions, feel free to open up a new topic here or on GitHub.