This command will create an export
folder that contains a separate subfolder for each SWF file's exported data. In the next step, JPEXS will be used create sounds
and frames
folders for each video and extract sound and frame files into their respective folders.
$ for f in `basename --suffix=.swf *swf`; do \
mkdir export/$f; \
done
At the end of the process outlined below, the directory structure looks like this:
.
├── export
│ └──screencap1
│ ├──sounds
│ └── frames
│ └──screencap2
│ ├──sounds
│ └── frames
├── screencap1.swf
├── screencap1.mp4
├── screencap1.swf
└── screencap2.mp4
Use JPEXS Free Flash Compiler to extract the sounds
and frames
folders for each SWF file:
- Highlight the two folders, right click and choose "Export selection" as shown below.
- Select the corresponding folder for the exported files. JPEXS creates the
sounds
andframes
subfolders as part of the export process. - Repeat this for each of your SWF files.
This step is a bit tedious and could be automated if you were to write a Java program to do the exporting, using their library.
The shell script below will repeat the following actions for each of the SWF folders (which now contain sounds
and frames
subfolders):
- Rename the png files in the
frames
folder so that they have leading zeroes. (ie: 9.png becomes 0009.png). This makes it easier to sort the files. - Execute an
ffmpeg
command to convert the images (and sound) to a video file, which is placed in theexports
folder. Theffmpeg
command includes includes a filter to avoid "height not divisible by 2" errors for videos with odd height values. In this case, a single row of pixels is cropped from the bottom of the video to make the height an even value.
#!/bin/bash
# run this from the exports folder created above
for d in `ls -d *`
do
echo "Starting $d"
cd $d/frames
echo "Renaming png files"
ls | sort --numeric-sort | cat --number | while read n f; do mv --no-clobber $f `printf "%04d.png" $n`; done
cd ..
ffmpeg -i sounds/*.flv -pattern_type glob -framerate 10 -i 'frames/*.png' \
-c:v libx264 -pix_fmt yuv420p \
-vf "crop=floor(iw/2)*2:floor(ih/2)*2" \
../$d.mp4
cd ..
done
If your screen recordings are a weird size, as mine are, you can use FFmpeg to scale them with black bars on either side.
I used the following command to resize my relatively small videos (with a "portrait" orientation) to 720p resolution. The options after the filter keep the quality looking good while scaling up.
$ ffmpeg -i input.mp4 -vf "scale=-1:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1" -preset slow -crf 18 output.mp4
FYI, doing this for a directory of mp4 files could look like this:
$ mkdir scaledup
$ for f in `ls *mp4`; do \
ffmpeg -i $f -vf "scale=-1:720,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1" -preset slow -crf 18 scaledup/$f; \
done