I want to convert any files in a large media collection that are not encoded with H264. In order to do that I need a tool to list all the files, I need to convert. There are a lot of files to go through. The search needs to be recursive as files are stored in the following format /media/tv shows/show name/season 01/filename.extension
Here is what I have come up with so far. Note that this is a rough approximation of what you should do.
First, find all of your video files and output them to a file to be read, you can skip this part and just pipe the results to the next step.
find path/to/videos/directory -name \*.mp4 >> /tmp/videoList.txt
This finds all
.mp4 files in all the subfolders of your media directory and puts them in a file.
Next, you can use a tool as shown in this example to probe what encoding each video file uses. In this case we are looking for h264.
while read p; do mediainfo $p | grep -v h264 | grep .mp4 | \ cut -f2 -d: >> /tmp/h264List.txt done </tmp/videoList.txt
This example creates a file ,
/tmp/h264List.txt, that has all the files that use h264 encoding. From here you can do a compare and find all of the non-h264 video files.
sort /tmp/videoFiles.txt /tmp/h264List.txt | uniq -u >> /tmp/nonh264List.txt
At this point you should have a file that has all of the non-h264 video files in the directories you searched in. All together it could look something like this:
Note that this is a rough example!
#!/bin/bash find /home/user/videos/tvshows -name \*.mp4 >> /tmp/videoList.txt while read p; do mediainfo $p | grep -v h264 | grep .mp4 | \ cut -f2 -d: >> /tmp/h264List.txt done </tmp/videoList.txt sort /tmp/videoList.txt /tmp/h264List.txt | uniq -u >> /tmp/nonh264List.txt #Optional Cleanup, only if necessary mv /tmp/nonh264List.txt /home/user/needToEncode.txt rm /tmp/*.txt
Then from here you can do a similar loop through the
needToEncode.txt file to run your desired
ffmpeg encoding. You will need to change any paths to wherever your media is kept and the file extensions and encoding to whatever you are looking for.
Please be sure to read through all links I have provided before attempting anything. This script may not be the most optimized or work exactly as you desire but I was able to use it to find all the video files, sort them, and save the output to a file.