Skip to content

Instantly share code, notes, and snippets.

@rahji
Last active July 3, 2023 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahji/755330bfd36f361bbf7a3ec74f2ceef8 to your computer and use it in GitHub Desktop.
Save rahji/755330bfd36f361bbf7a3ec74f2ceef8 to your computer and use it in GitHub Desktop.
Turn SWF Screen Recordings from Jing into mp4s

Turning Jing SWF Screen Recordings into Video Files

Create a Folder Structure

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

Extract Audio and Frames

Use JPEXS Free Flash Compiler to extract the sounds and frames folders for each SWF file:

  1. Highlight the two folders, right click and choose "Export selection" as shown below.
  2. Select the corresponding folder for the exported files. JPEXS creates the sounds and frames subfolders as part of the export process.
  3. Repeat this for each of your SWF files.

Screenshot 2023-06-29 191651

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.

Convert with FFmpeg

The shell script below will repeat the following actions for each of the SWF folders (which now contain sounds and frames subfolders):

  1. 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.
  2. Execute an ffmpeg command to convert the images (and sound) to a video file, which is placed in the exports folder. The ffmpeg 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

Resizing with Black Bars

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment