In my previous post I detailed the Handbrake settings that I am using to convert YouTube (and other) videos to play on my Play Station Portable (PSP).
Creating thumbnails for these PSP videos is a “nice to have” – but it is time consuming if it is not automated.
PSP thumbnails are simple to understand – they are jpeg files (160 x 120 pixels) that have had their extension changed to .thm. Videos and thumbnails must share the same filename on the PSP. So for a video called my_video.mp4 we would create a thumbnail called my_video.thm.
After looking at a lot of blogs and the VLC documentation I came up with a command line script that created a single jpeg thumbnail for each mp4 file in the current working directory:
for %i in (*.mp4) do if NOT exist "%~ni_*.jpg" start /WAIT "" "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" --rate=2.0 --video-filter=scene --start-time=280 --stop-time=281 --scene-format=jpg --scene-replace --scene-ratio=18 --scene-width=160 --scene-height=120 --scene-path="%CD%" --scene-prefix="%~ni" "%CD%\%i" vlc://quit
The above command line is modified from this post. It can be broken down as follows:
for %i in (*.mp4): filters the media to process (in my case .mp4 files)
do if NOT exist “%~ni_*.jpg”: creates a jpeg snapshot (if it does not already exist)
start /WAIT “”: is required to only process one video at a time
“C:\Program Files (x86)\VideoLAN\VLC\vlc.exe”: This is the path to vlc.exe on Windows 8 x64.
–rate=2.0: sets the playback speed. I set this to 2.0 so that vlc plays the specified video segments at twice the normal speed.
–video-filter=scene: the scene video filter sends video to picture files
–start-time=280: the stream will start at this position (in seconds)
–stop-time=281: the stream will stop at this position (in seconds)
–scene-format=jpg: specifies the screenshot format
–scene-replace: always writes to the same output file. This is used so that I can obtain a single screenshot that only needs the extension to be renamed.
–scene-ratio=18: the ratio of images to record. Initially this was set to 24 (1 image every 24 frames) – however with a start and stop time interval of one second I found that some of the screenshots that vlc output were black screens. I lowered this value until I could consistently generate screenshots from multiple .mp4 files. Your mileage may vary.
–scene-width=160: output image width
–scene-height=120: output image height
–scene-path=”%CD%”: output image directory – %CD% specifies current working directory
–scene-prefix=”%~ni” “%CD%\%i”: output image name – in this case the same name as the .mp4 video and the same working directory
vlc://quit: Quit vlc
The above script works when it is pasted into a command prompt window – but it required me to navigate to the drive and directory that contained my videos – and I still needed to change the extension of the screenshots produced to .thm. So the next step was to modify the script so that it would run in a batch file.
for %%i in (*.mp4) do if NOT exist "%%~ni_*.jpg" start /WAIT "" "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" --rate=2.0 --video-filter=scene --start-time=280 --stop-time=281 --scene-format=jpg --scene-replace --scene-ratio=18 --scene-width=160 --scene-height=120 --scene-path="D:\PSP" --scene-prefix="%%~ni" "D:\PSP\%%i" vlc://quit
ren *.jpg *.thm
The differences made between the first and second scripts are as follows:
d: changes drive from c: to d:
cd PSP: changes directory to PSP
single percentage signs % are all changed to double percentage signs %% to allow the script to run in a batch file
–scene-path=”D:\PSP: the output image directory is changes to D:\PSP
–scene-prefix=”%%~ni” “D:\PSP\%%i”: the output image name also specifies the D:\PSP directory
ren *.jpg *.thm: renames all jpeg files in D:\PSP to .thm files
Many thanks to ComCBoVudLaBa on the VLC forum for providing a script with supporting comments that does all of the heavy lifting required. After some experimentation and tweaking I ended up with a batch file that completely automated the creation of PSP thumbnails from .mp4 videos!
On Ubuntu the hostname is stored in both the /etc/hosts and /etc/hostname files. There are several ways that we can change the hostname in these files.
1. Manually Edit the hostname
We can manually edit these files using a basic text editor like nano:
sudo nano /etc/hosts
sudo nano /etc/hostname
In /etc/hostname simply overwrite the existing hostname with a new one. In /etc/hosts you will find the hostname on the line beginning 127.0.0.1 – overwrite only the hostname with the new one, and then reboot.
2. Use sed to change the hostname
Another way to achieve the same goal is to use the sed command to replace the existing hostname with a new one.
For example, my Ubuntu Server has the default hostname of ‘ubuntu’.
Use the hostname command to check what your hostname is.
With sed we can look for our hostname (in /etc/hosts and /etc/hostname) and then replace it with the desired new-hostname:
sudo sed -i 's/ubuntu/new-hostname/g' /etc/hosts
sudo sed -i 's/ubuntu/new-hostname/g' /etc/hostname
3. Write a Bash Script
It’s always handy to have a script to do things – so here is a quick bash script that I put together that uses sed to change the hostname and then reboot:
#Assign existing hostname to $hostn
#Display existing hostname
echo "Existing hostname is $hostn"
#Ask for new hostname $newhost
echo "Enter new hostname: "
#change hostname in /etc/hosts & /etc/hostname
sudo sed -i "s/$hostn/$newhost/g" /etc/hosts
sudo sed -i "s/$hostn/$newhost/g" /etc/hostname
#display new hostname
echo "Your new hostname is $newhost"
#Press a key to reboot
read -s -n 1 -p "Press any key to reboot"