Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in 
CSDb User Forums

Forums > CSDb Entries > Release id #172720 : Capture Tester V1.1
2018-12-19 12:32

Registered: Aug 2015
Posts: 13
Release id #172720 : Capture Tester V1.1

capture of "Capture Tester": https://www.youtube.com/watch?v=43pENaKP3G8
capture of "noop-tro-2018": https://www.youtube.com/watch?v=RiL0ipbCr24

(Note: The captures feature the vertical stripes VIC2 hardware interference bug because when I made them I did not know about the "LumaFix64" project.)

equipment used:
* PAL C64
* s-video+rca cable from retrokabel.de (cable has a builtin resistor on the chroma line)
* cheap LogiLink AV-Grabber USB (id from lsusb: Fushicai USBTV007 Video Grabber [EasyCAP])
* arch gnu/linux PC

the problem:
The "EasyCAP" grabber only records 720x576@25fps PAL and there is no option to change resolution or framerate. The C64 outputs approximately 288lines@50fps. In the captured unprocessed video, two C64 frames are placed in a single EasyCAPed frame, one frame on every odd line, another frame on every even line.

Googleing about that problem, the suggested solution is to de-interlace the captured frames to get the original 50fps back. To test any de-interlacing for correctness (no temporal blurring and correct image sequence and frame numbers in the result) I wrote the Capture Tester program.

My problem was that the presented de-interlacing solutions online used scripts for a software called avisynth and I could not find any way to make those scripts work under gnu/linux (all the required software to do that easily appeared to be abandoned).

So I cobbled up a capture solution using ffmpeg,ffplay(for preview during capture),v4l2ctrl,vapoursynth(for de-interlacing and resizing) and avidemux(for cutting):
It consists of two bash scripts, a vapoursynth script and a settings file to configure the capture stick.

script "capture.sh":

echo "delete previous capture..."
rm ./out/c64_capture.mp4

echo "starting capture..."
ffmpeg -f v4l2 -i /dev/video0 -f pulse -i default -c:v libx264 -framerate 25 -preset ultrafast -c:a aac -f tee -map 0:v -map 1:a "./out/c64_capture.mp4|[f=nut]pipe:" | ffplay pipe: &

# load improved settings (only has an effect if ffmpeg is already reading from /dev/video0 otherwise it always reverts to default settings)
echo "loading improved stick settings..."
# wait a bit to make sure ffmpeg and ffplay are already running
sleep 1
# (loading the settings shows error messages on console but the settings are changed as evident by looking at the captured video)
v4l2ctrl -d /dev/video0 -l stick_settings &

FFMPEGPID=`ps T | grep ffmpeg | awk '{ print $1 }'`
FFPLAYPID=`ps T | grep ffplay | awk '{ print $1 }'`

read -p "...................press any key to stop..................." -n1 -s

sleep 1

file "stick_settings" (initially generated with "v4l2ctrl -d /dev/video0 -s stick_settings" then edited):
9963776:                     Brightness:500
9963777:                       Contrast:500
9963778:                     Saturation:750
9963779:                            Hue:0
9963803:                      Sharpness:128

vapoursynth script "vapoursynth_c64.vpy":
import vapoursynth as vs
core = vs.get_core()
clip = core.ffms2.Source(source="./out/c64_capture.mp4")
clip = core.std.SeparateFields(clip=clip, tff=1) # also interleaves after separation
clip = core.std.Crop(clip=clip, left=12, right=24, top=4, bottom=4)
# scale up high for fine control over jitter removal
clip = core.resize.Spline36(clip=clip, width=2160, height=1728)
# get rid of line jitter between frames, by panning the odds
evens = core.std.SelectEvery(clip=clip, cycle=2, offsets=0)
odds = core.std.SelectEvery(clip=clip, cycle=2, offsets=1)
odds = core.std.AddBorders(clip=odds, bottom=2)
odds = core.std.Crop(clip=odds, top=2)
# put frames back together
clip = core.std.Interleave((odds,evens))
# cut off jitter
clip = core.std.Crop(clip=clip, bottom=2)
# resize to 1080p
clip = core.resize.Spline36(clip=clip, width=1350, height=1080, format=vs.YUV420P16)

script "transcode.sh":
echo "extract audio..."
ffmpeg -i ./out/c64_capture.mp4 -c:a copy ./out/c64_capture_audio.aac
echo "transcode video..."
vspipe --y4m vapoursynth_c64.vpy - | ffmpeg -i pipe: -c:v libx264 -preset ultrafast -c:a aac ./out/c64_capture_video.mp4
echo "merge video and audio"
ffmpeg -i ./out/c64_capture_video.mp4 -i ./out/c64_capture_audio.aac -c:v copy -c:a copy ./out/c64_capture_deinterlaced.mp4
echo "remove intermediate files..."
rm ./out/c64_capture_audio.aac
rm ./out/c64_capture_video.mp4
echo "done"

To capture a C64 video, I first run the capture script (which captures via ffmpeg and opens an ffplay window for preview(not deinterlaced yet) and loads better than default settings file for the capture stick). And afterwards de-interlace and resize with the transcode script. Then I cut using avidemux.

Two specific questions I have:
1) Is there a way I can get vapoursynth to de-interlace and preview in realtime? (e.g. for playing games in a window without recording) All my attempts at reading directly from /dev/video0 in the vapoursynth script failed, also tried pipe-ing through a fifo pipe.
2) How can I get a sharper output? (seems a bit blurry, wondering if "LumaFix64" would help with that, the "sharpness" control in the stick_settings seems to only have little effect)

Apart from those two question all thoughts and improvement suggestions are welcome.
... 2 posts hidden. Click here to view all posts....
2018-12-19 17:24

Registered: Jan 2018
Posts: 123
Looks quite good for a very cheap grabber, glad you could de-interlace it. Cool it's also working on Linux. I'll try to dig around some to see if it's possible to do it realtime.
2018-12-19 18:37

Registered: Aug 2015
Posts: 13

I dug a bit more in the ffmpeg/ffplay docs and found that it's possible to apply videofilter in realtime:

So to live-view deinterlaced C64 PAL signal, it is sufficient to just enter:
ffplay -f v4l2 -i /dev/video0 -vf setfield=prog,separatefields,fps=50,crop=686:278:12:4,scale=1350:1080:sws_flags= spline

With that it should be possible to skip the vapoursynth transcoding step entirely and do the deinterlacing during the initial ffmpeg capture.

EDIT: Yup, works. Here's the new capture script, which does the transcoding and deinterlaced preview in realtime:
EDIT2: Adjusted -vf once more to find the perfect crop setting for my stick:


echo "delete previous capture..."
rm ./out/c64_capture.mp4

# select s-video input on stick
v4l2-ctl -d /dev/video0 -i 1

echo "starting capture..."
ffmpeg -f v4l2 -i /dev/video0 -f pulse -i default -vf setfield=prog,separatefields,fps=50,crop=686:278:12:4,scale=1350:1080:sws_flags= spline -c:v libx264 -framerate 50 -preset ultrafast -c:a aac -f tee -map 0:v -map 1:a "./out/c64_capture.mp4|[f=nut]pipe:" | ffplay pipe: &

# load improved settings (only has an effect if ffmpeg is already reading from /dev/video0 otherwise it always reverts to default settings)
echo "loading improved stick settings..."
# wait a bit to make sure ffmpeg and ffplay are already running
sleep 1
# (loading the settings shows error messages on console but the settings are changed as evident by looking at the captured video)
v4l2ctrl -d /dev/video0 -l stick_settings &

FFMPEGPID=`ps T | grep ffmpeg | awk '{ print $1 }'`
FFPLAYPID=`ps T | grep ffplay | awk '{ print $1 }'`
read -p "...................press any key to stop..................." -n1 -s
#echo ".................ffmpegpid: $FFMPEGPID"
#echo ".................ffplaypid: $FFPLAYPID"
sleep 1
2018-12-19 23:00

Registered: Sep 2003
Posts: 418
Note to the 2nd question:

LumaFix64 does definitely not make the output any sharper. Unfortunately it acts as a really small low pass filter as a side effect.

This filtering is most noticeable for black+white hires chessboard dithered pictures where the overall brightness for such an area is much lower than without it.

For sharper picture there are rumours that removing the modulator helps:
2018-12-20 06:07

Registered: Apr 2002
Posts: 4345
I dont know I like those vertical lines, whatching the test cap they instantly reminded me that this is what I saw back in the days on a CRT. Lumafix is an artifical fix that fixes something that was always there.
2018-12-20 12:32

Registered: Aug 2015
Posts: 13
Thanks soci, that's good to know. For the moment I do not wish to remove the modulator entirely though because despite transcoding the signal back to the original 50fps, things still don't look as buttery smooth as on my CRT TV because my PC screens can only do refresh rates of 60Hz and 75Hz. Maybe I could put in a switch, so the modulator could be turned off and on again when needed.

Oswald... I could have sworn that I never noticed those stripes on any of my CRTs but I just double checked and now that I know they're there, I can see them on my current CRT as well. :D
2018-12-20 13:06

Registered: Apr 2002
Posts: 4345
0xDB, well as a coder I noticed them, they helped to find where the border is on unicolor screens :) there's even slight lines on character row boundaries, but more subtle.
2018-12-20 19:19

Registered: Aug 2015
Posts: 13
I will still try to get rid of them to get a cleaner picture and I don't mind if that makes my C64 not "true" to the original feeling. :)

On another note, when I tried to run my script today I got errors about the crop settings being invalid. Yesterday it worked but yesterday I also experimented with a tool called "tvtime" before ffmpeg/ffplay and digging into the v4l2-ctl docs I found that I need to set the signal standard as well as that isn't detected automatically (tvtime must have configured that for me so it just worked yesterday).

So before running ffplay or ffmpeg, in addition to selecting the s-video input, the standard has to be set as well, like this:
# set s-video input
v4l2-ctl -d /dev/video0 -i 1
# set pal standard
v4l2-ctl -d /dev/video0 -s pal

I also looked up configuration for the X-server again and via https://fs-uae.net/50hz-display-modes-on-linux-with-nvidia-driv.. and https://arachnoid.com/modelines/ I found a modeline which allowed me to force my main screen to a 50Hz refresh rate:
Modeline "1920x1200_50.00" 158.08 1920 2032 2240 2560 1200 1201 1204 1235 -HSync +Vsync

The output still is not as smooth as on the CRT connected via the HF-modulator (and the image on the CRT feels crisper as well :P ).
2018-12-21 10:47

Registered: Aug 2010
Posts: 46
0xDB: Nice write-up. :) I ordered a LogiLink VG0001A 2 days ago just to try it out as well with my C64. My last experience around 5.5 years ago was with a Terratec Grabby and it didn't really do interference-free captures with anything else than a DVD-player, so I sent it back. It had waves of colors at the top of the screen, like this:

2019-01-02 10:16

Registered: Aug 2015
Posts: 13
Thx encore, I hope it works for you as well.

I've installed a LumaFix64 in the meantime and while I found I could not fully eliminate all the vertical stripes with it (just a somewhat balanced state between dark and bright stripes that almost but not quite cancel each other out... spent at least 4h playing with the regulators), I get a slightly sharper picture by not using the spline algorithm for scaling and instead (who'da thunk it :P) use simple nearest neighbor scaling.

Overall, image quality still looks worse than on CRT TV.
2019-01-05 13:10

Registered: Aug 2015
Posts: 13
Trying to optimize some more, I decided to try drawing a grid (poorly emulating the grill in a CRT) over the source image, like this:
ffplay -f v4l2 -i $VID -vf 'setfield=prog,separatefields,fps=50,crop=680:270:16:4,scale=1360:1080:sws_flags =neighbor,drawgrid=0:0:4:4:0x303030:1:1'

The pixels do not seem to be perfectly aligned... there is ghost image which disturbs the color information of the individual pixels, best seen in the white square which should be 8x8 pixels but it appears as 7x8 with the 8th column being almost black and a ghost pixel column to the left of it, bleeding into the border. Perhaps chroma information is not interpreted correctly.

Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Users Online
Guests online: 22
Top Demos
1 Uncensored  (9.7)
2 Unboxed  (9.7)
3 Comaland 100%  (9.7)
4 Edge of Disgrace  (9.7)
5 Coma Light 13  (9.6)
6 The Shores of Reflec..  (9.6)
7 Wonderland XII  (9.6)
8 Lunatico  (9.6)
9 C=Bit 18  (9.6)
10 Incoherent Nightmare  (9.5)
Top onefile Demos
1 Smile to the Sky  (9.7)
2 Daah, Those Acid Pil..  (9.5)
3 FMX Music Demo  (9.5)
4 Arok 20 Invitation  (9.5)
5 Pandemoniac Part 2 o..  (9.5)
6 Dawnfall V1.1  (9.4)
7 Crystal Gazer  (9.4)
8 Merry Xmas 2017  (9.4)
9 Rewind  (9.4)
10 Party Horse  (9.4)
Top Groups
1 PriorArt  (9.8)
2 Oxyron  (9.4)
3 Performers  (9.4)
4 Booze Design  (9.4)
5 Censor Design  (9.3)
Top Graphicians
1 Mirage  (9.8)
2 Razorback  (9.8)
3 Archmage  (9.7)
4 jamon  (9.7)
5 Veto  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2019
Page generated in: 0.079 sec.