Is it possible for this to be automated?

Hi Everyone…

Probably in WAY over my head here but, I’d like to try anyway.

This command below:

ffmpeg -i videos.mp4 -c:v copy -c:a pcm_s16be convvideos.mov

takes a single .mp4 video file and converts just the audio to .pcm

and it does it rather hastily if I might add. This is used for video file conversion for use inside of Resolve.

You need to from terminal, be inside the directory of the source file and it creates the converted file inside the same directory.

My question is a multiple one, A: can this be automated and B: could it be used for multiple files writing them in numerical succession and C: could it then write a file to another drive instead of the same source drive?

Are there any examples that I might be able to follow? Also, please do remember that I am a noob…

Thank you kindly.
Regards C.

You could use a Bash script similar to this (untested):

#!/bin/bash
OUTDIR='/mnt/extdrive/';

for i in *.mp4; do
  ffmpeg -i "$i" -c:v copy -c:a pcm_s16be "${OUTDIR}${i}.mov"
done

Save to /usr/local/bin/convert_audio.sh and

$ chmod +x convert_audio.sh

to make the script executable.

If you then go to a directory and type convert_audio.sh, it would convert all the mp4 files in the directory and save them to OUTDIR with the original names and the added extension .mov.

OUTDIR can be replaced by the path to a secondary drive, if you know the location of the drive or you can mount the drive yourself to /mnt/extdrive/.

1 Like

Hi Oliver, @litemotiv

Thank you, I will try that tomorrow and revert back, thank you for the reply.

Regards C

Hi @litemotiv

As I said I would I am posting a reply back.

Unfortunately, as I am using the free version of resolve there is no easy way to really do this easily as the video most certainly has to be re encoded for the freeware version of Resolve.

That being said, the script can still be used it just has to be modified slightly to make use of the DNxHD codec.

I am just waiting for a file that needs to be encoded to see what the size is going to be. Once done and when I am satisfied I will edit this post with the relevant info as to how to do this in terminal and for batch converting.

For now this is all.

Regards, C

EDIT

Please make sure you understand HOW this code works before using it.

This file will take how many ever .mp4 files you have on your drive or inside the folder that you run the bash from and it will convert them to:

.mp4 with pcm16 audio for use with:
DaVinci Resolve STUDIO

or

DNxHD .mov for for use with:
Davinci Resolve FREE

You can change the Bit rate setting but along with this YOU MUST set the correct pixel format

The ffmpeg encoder can not do higher than 1440p
All bit rates and pixel formats are listed at the bottom for quick lookup. (2024 ytd)

I run Nobara 40 (GNOME) and have built this bash on that system I do not know on what other distro’s this will run.

Bash File For
Batch video convertor…

This bash must be run from within the terminal and the folder or root directory in which the .mp4 videos are that you want converted.

Please make sure to set a valid path for the OUTDIR command for the videos to be rendered to…

Please make sure that you have the ffmpeg encoder installed and active on your distro before creating or running this bash.

From terminal, Navigate to your:

cd /usr/local/bin

Inside that folder run:

sudo nano -e

Enter your password when prompted
Make sure to UNCOMMENT, (remove the #) from the line you want active for your version of Resolve.

COPY THE TEXT BELOW TO YOUR EDITOR AND PASTE IT IN THERE

# Save inside as: /usr/local/bin/file_name_of_your_liking.sh
 

# From terminal, navigate to the source folder / directory where the videos   
# are that you want to convert, and then run: The_file_name_you_created.sh 
# 
#!/bin/bash

#Remember to cofigure the OUTDIR below
OUTDIR='/home/cgpc/Store/';


# !!!! FOR DAVINCI RESOLVE STUDIO!!!!!
# Uncomment the line below for the paid version of DaVinci Resolve

# for i in *.mp4; do ffmpeg -i "$i" -c:v copy -c:a pcm_s16be "${OUTDIR}${i}.mov";done

# This will not alter your video file but will re-code your audio to 16bit PCM (It is really relly fast)


# !!!!!! FOR DAVICNI RESOLVE FREE

# You can set the size of the file by the quality you want, Available quality is quantified in Mbps 
# eg. (-b:v 36M) is = to 36Mbps 
# ALSO,please note the PIXEL FORMAT this will also need to be set in accordance
# eg. (-pix_fmt yuv422p) Both of these will render for 1080p60

# Make sure that the above are in order and your videos will be encoded in a batch format
# Please note that these files for the free version will be bigger by an order of magnitude 
# eg. Using a source file of 4.9GB with the current 36M bitrate upon being converted was 64.6GB



# Uncomment the line below for the Free version of DaVinci Resolve

# for i in *.mp4; do ffmpeg -i "$i" -c:v dnxhd -b:v 36M -pix_fmt yuv422p -c:a pcm_s16be "${OUTDIR}${i}.mov";done



# Video Parameters Valid For DNxHD profiles:
# Frame size: 1920x1080p; bitrate: 175Mbps; pixel format: yuv422p10
# Frame size: 1920x1080p; bitrate: 185Mbps; pixel format: yuv422p10
# Frame size: 1920x1080p; bitrate: 365Mbps; pixel format: yuv422p10
# Frame size: 1920x1080p; bitrate: 440Mbps; pixel format: yuv422p10
# Frame size: 1920x1080p; bitrate: 115Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 120Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 145Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 240Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 290Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 175Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 185Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 220Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 365Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 440Mbps; pixel format: yuv422p
# Frame size: 1920x1080i; bitrate: 220Mbps; pixel format: yuv422p10
# Frame size: 1920x1080i; bitrate: 120Mbps; pixel format: yuv422p
# Frame size: 1920x1080i; bitrate: 145Mbps; pixel format: yuv422p
# Frame size: 1920x1080i; bitrate: 185Mbps; pixel format: yuv422p
# Frame size: 1920x1080i; bitrate: 220Mbps; pixel format: yuv422p
# Frame size: 1440x1080i; bitrate: 120Mbps; pixel format: yuv422p
# Frame size: 1440x1080i; bitrate: 145Mbps; pixel format: yuv422p
# Frame size: 1280x720p;  bitrate: 90Mbps; pixel format: yuv422p10
# Frame size: 1280x720p;  bitrate: 180Mbps; pixel format: yuv422p10
# Frame size: 1280x720p;  bitrate: 220Mbps; pixel format: yuv422p10
# Frame size: 1280x720p;  bitrate: 90Mbps; pixel format: yuv422p
# Frame size: 1280x720p;  bitrate: 110Mbps; pixel format: yuv422p
# Frame size: 1280x720p;  bitrate: 180Mbps; pixel format: yuv422p
# Frame size: 1280x720p;  bitrate: 220Mbps; pixel format: yuv422p
# Frame size: 1280x720p;  bitrate: 60Mbps; pixel format: yuv422p
# Frame size: 1280x720p;  bitrate: 75Mbps; pixel format: yuv422p
# Frame size: 1280x720p;  bitrate: 120Mbps; pixel format: yuv422p
# Frame size: 1280x720p;  bitrate: 145Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 36Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 45Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 75Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 90Mbps; pixel format: yuv422p
# Frame size: 1920x1080p; bitrate: 350Mbps; pixel format: yuv444p10, gbrp10
# Frame size: 1920x1080p; bitrate: 390Mbps; pixel format: yuv444p10, gbrp10
# Frame size: 1920x1080p; bitrate: 440Mbps; pixel format: yuv444p10, gbrp10
# Frame size: 1920x1080p; bitrate: 730Mbps; pixel format: yuv444p10, gbrp10
# Frame size: 1920x1080p; bitrate: 880Mbps; pixel format: yuv444p10, gbrp10
# Frame size: 960x720p;   bitrate: 42Mbps; pixel format: yuv422p
# Frame size: 960x720p;   bitrate: 60Mbps; pixel format: yuv422p
# Frame size: 960x720p;   bitrate: 75Mbps; pixel format: yuv422p
# Frame size: 960x720p;   bitrate: 115Mbps; pixel format: yuv422p
# Frame size: 1440x1080p; bitrate: 63Mbps; pixel format: yuv422p
# Frame size: 1440x1080p; bitrate: 84Mbps; pixel format: yuv422p
# Frame size: 1440x1080p; bitrate: 100Mbps; pixel format: yuv422p
# Frame size: 1440x1080p; bitrate: 110Mbps; pixel format: yuv422p
# Frame size: 1440x1080i; bitrate: 80Mbps; pixel format: yuv422p
# Frame size: 1440x1080i; bitrate: 90Mbps; pixel format: yuv422p
# Frame size: 1440x1080i; bitrate: 100Mbps; pixel format: yuv422p
# Frame size: 1440x1080i; bitrate: 110Mbps; pixel format: yuv422p

Once done, write (ctrl+O), name eg.(conv_audio.sh) and exit (ctrl+X) the bash file.

A few todo’s:
This part of the code needs to be changed to where you want your extracted videos to be put:

OUTDIR=‘/where/your/render_disk_is_located/’;

eg.OUTDIR=‘/home/cgpc/Store/’;

The bash file you created, will need to be made executable.

Do this by running the following command from within the /usr/local/bin location:

sudo chmod +x conv_audio.sh

Enter in your password if prompted and press enter.

This is similar to processing pipelines used in remote sensing where you may have 1000’s of files and multiple steps (and needed to plan carefully to have adequate mass storage space). We had lots of example scripts that could be hacked to meet the needs of the current project, New users found Linux Command helpful in undrstanding the scripts and making required changes.

Hi @gnwiii

Yes, thank you George,I have done quite a bit of digging, but examples are always good, it helps to explain what I read.

From @litemotiv 's example I was able to make a relatively good assessment of what I needed to do.

I will update my answer tomorrow once I am back home. Inside that will be an Edit: section and under that a whole tutorial for anyone that might also need this info.

Thank you for your input, it is appreciated.
I do however sometimes just require a nudge in the right direction and @litemotiv 's code was the nudge I needed.

Regards C