5

I took my old NV-GS500 Panasonic camcorder; in order to finally turn all our recordings into digital media.

So far, things worked easily:

  • On Ubuntu 16.04; I just had to connect the device and my laptop; via the DV/firewire cable
  • Just using the standard settings (I didnt select any output format; just went for "single" unlimited file) ... kino created a capture.dv file for me
  • That created a ~8 GB file for 40 minutes of video ... ok with me
  • I then used a little script that reads does ffmpeg -i infile -pix_fmt yuv420p -crf 23 outfile to turn that dv file into an mp4

But alas, the quality of the mp4 isn't that convincing. Especially on rapid movements, lots of pixelish stuff.

Thus, I want to improve the whole thing. And as now discovered that kino is actually "dead"; I am wondering what combination of tools gives me good quality; as easily as possible.

Update: the full command for ffmpeg is already given above, here is the output I am receiving when running that:

>  ffmpeg -i capture001.dv -pix_fmt yuv420p -crf 23 test.mp4

ffmpeg version 2.8.10-0ubuntu0.16.04.1 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv --enable-version3 --disable-doc --disable-programs --disable-avdevice --disable-avfilter --disable-avformat --disable-avresample --disable-postproc --disable-swscale --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libvo_aacenc --enable-libvo_amrwbenc
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
[dv @ 0x2566420] Detected timecode is invalid
[dv @ 0x2566420] Estimating duration from bitrate, this may be inaccurate
Input #0, dv, from 'capture001.dv':
  Duration: 00:39:45.36, start: 0.000000, bitrate: 28800 kb/s
    Stream #0:0: Video: dvvideo, yuv420p, 720x576 [SAR 64:45 DAR 16:9], 28800 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Stream #0:1: Audio: pcm_s16le, 32000 Hz, stereo, s16, 1024 kb/s
    Stream #0:2: Audio: pcm_s16le, 32000 Hz, stereo, s16, 1024 kb/s
[libx264 @ 0x256dea0] using SAR=64/45
[libx264 @ 0x256dea0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x256dea0] profile High, level 3.0
[libx264 @ 0x256dea0] 264 - core 148 r2643 5c65704 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'test.mp4':
  Metadata:
    encoder         : Lavf56.40.101
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=-1--1, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.60.100 libx264
    Stream #0:1: Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 32000 Hz, stereo, s16, 128 kb/s
    Metadata:
      encoder         : Lavc56.60.100 libvo_aacenc
Stream mapping:
  Stream #0:0 -> #0:0 (dvvideo (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (pcm_s16le (native) -> aac (libvo_aacenc))
Press [q] to stop, [?] for help
frame= 1449 fps=112 q=-1.0 Lsize=   10373kB time=00:00:57.93 bitrate=1466.7kbits/s    
video:9424kB audio:906kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.411332%
[libx264 @ 0x256dea0] frame I:29    Avg QP:22.01  size: 23022
[libx264 @ 0x256dea0] frame P:826   Avg QP:24.37  size:  8655
[libx264 @ 0x256dea0] frame B:594   Avg QP:25.43  size:  3086
[libx264 @ 0x256dea0] consecutive B-frames: 29.4% 42.9% 14.7% 13.0%
[libx264 @ 0x256dea0] mb I  I16..4: 21.0% 76.6%  2.3%
[libx264 @ 0x256dea0] mb P  I16..4:  1.7%  5.9%  0.5%  P16..4: 46.9%  9.4%  6.7%  0.0%  0.0%    skip:28.9%
[libx264 @ 0x256dea0] mb B  I16..4:  0.0%  0.1%  0.0%  B16..8: 48.5%  2.5%  0.6%  direct: 3.3%  skip:44.8%  L0:46.0% L1:50.8% BI: 3.2%
[libx264 @ 0x256dea0] 8x8 transform intra:73.6% inter:82.2%
[libx264 @ 0x256dea0] coded y,uvDC,uvAC intra: 66.2% 56.2% 6.0% inter: 19.5% 23.4% 0.1%
[libx264 @ 0x256dea0] i16 v,h,dc,p: 14% 39% 12% 35%
[libx264 @ 0x256dea0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 16% 33%  5%  5%  6%  6%  5%  7%
[libx264 @ 0x256dea0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu:  9% 60% 14%  3%  3%  3%  3%  2%  2%
[libx264 @ 0x256dea0] i8c dc,h,v,p: 56% 20% 21%  3%
[libx264 @ 0x256dea0] Weighted P-Frames: Y:14.9% UV:1.5%
[libx264 @ 0x256dea0] ref P L0: 62.5% 14.1% 15.9%  6.8%  0.7%
[libx264 @ 0x256dea0] ref B L0: 81.5% 17.0%  1.5%
[libx264 @ 0x256dea0] ref B L1: 94.9%  5.1%
[libx264 @ 0x256dea0] kb/s:1331.94
Exiting normally, received signal 2.

(interrupted after a few seconds with ctrl-c)

  • Could you paste-bin the full FFmpeg command and also the complete terminal output? My suspicion is that your FFmpeg usage could be tightened up and a better result obtained... – andrew.46 Jan 1 '17 at 1:58
  • @andrew.46 The ffmpeg command is already in the question; and I added sample console output for that. – GhostCat Jan 1 '17 at 8:09
  • Thanks for that! Looks ok although I suspect a modern FFmpeg can cope without the -pix_fmt yuv420p, this was selected automagically on my own system. Try deinterlacing, although I am not convinced this is the answer. Add the following: -vf yadif=0:-1:0 (these are yadif defaults). If this makes an appreciable difference might be worth adding in mcdeint as well. Otherwise, not for the first time, I am completely wrong :) – andrew.46 Jan 1 '17 at 9:10
  • @andrew.46 Adding -vf yadif ... helps; but how do I make use of that mcdint? – GhostCat Jan 2 '17 at 13:16
  • Try something like: -vf yadif=1:-1:0,mcdeint=2:1:10 This will be very slow unfortunately, – andrew.46 Jan 2 '17 at 19:37
10

It is well worth running a deinterlacing video filter during your video encode and this may very well lessen some of the odd screen effects that you are seeing in your output video. A second thought, unrelated to motion artefact but well worth adding in, is the use of a de-noising filter.

1. Deinterlacing:

For FFmpeg the best and fastest choice is yadif which in the usual quirky geek fashion simply stands for 'Yet Another DeInterlacing Filter'!

yadif can be used with no options or you can specify an option for each of 3 fields:

  1. mode: The basic interlacing mode to adopt
  2. parity: The picture field parity assumed for the input interlaced video
  3. deint: Specify which frames to deinterlace

The safe defaults can be specified on the FFmpeg command line as:

-vf yadif=0:-1:0

If you wish to alter these all of the deeper detail is contained here:

FFmpeg Filter Documentation: yadif
https://ffmpeg.org/ffmpeg-filters.html#yadif-1

A further deinterlacing filter called mcdeint (motion-compensation deinterlacing) can also be applied but you may find this painfully slow. A typical command line for use of this filter would be:

-vf yadif=1:-1:0,mcdeint=2:1:10

And again the fine detail of the mcdeint options can be seen in the FFmpeg documentation:

FFmpeg Filter Documentation: mcdeint
https://ffmpeg.org/ffmpeg-filters.html#mcdeint

2. Denoising:

A final though that may well be worth some experimentation is the use of a denoising filter, although this should not effect motion artefact it is still a well worth addition. Under FFmpeg there are a few choices but one well worth looking at is nlmeans (denoise frames using Non-Local Means algorithm). You will need the very latest FFmpeg for this one.

To use this in the easiest command line try the following:

-vf yadif=0:-1:0,nlmeans

There is a hit with nlmeans in terms of encoding time, not as severe a penalty as is seen with mcdeint but still a consideration...

If you have an older copy of FFmpeg with no access to this newest filter there is an older denoise filter that can safely be used with trust in the sane defaults:

-vf yadif=0:-1:0,hqdn3d

I note on my own system that hqdn3d is very, very much faster than the newer nlmeans. Better? Well I suspect that is a debate for another forum :)

And hopefully a combination of any of these thoughts will solve your problem...

References:

  • Lots of stuff ... will digest your input tomorrow I hope. – GhostCat Jan 2 '17 at 20:35
  • No worries, I have had a lot of fun putting this answer together :). – andrew.46 Jan 2 '17 at 20:56
  • There are also the bwdif, nnedi, and w3fdif deinterlacing filters. I haven't compared them yet. – llogan Jan 3 '17 at 4:15
  • @LordNeckbeard I was wondering when you would be drawn out :) – andrew.46 Jan 3 '17 at 4:16
  • I almost answered but New Years induced laziness convinced me not to, but it was a good thing since your answer is more detailed and explanatory than what I had in mind. The mode is worth experimenting with in yadif: for my last batch of vids mode 1 looked much better for that particular content. I wish nlmeans was around when I was dealing with lots of VHS stuff. – llogan Jan 3 '17 at 4:22
3

You can quickly and easily achieve very good quality using Handbrake app. Install it with:

sudo apt-get install handbrake

I suggest you encode to x264, it's currently most commonly used coded and you can have quite small file while preserving good quality. For private archive I recommend setting up Constant RF (rate factor) to between 16 and 18 (lower = higher quality and larger size).

enter image description here

If your video is noisy (it's probably is), there's also very neat denoise filter:

enter image description here

You might also need to deinterlance your source. As for audio... 320 kbps MP3 or AAC should give great results for personal archive. Everything can be set in Handbrake's GUI.

  • handbrake is my best for compressing video, concerning the RF I put it in 24. – Bilal Jan 2 '17 at 21:51
  • Thanks for your answer. I gave it a try ... but then turned back to using kino and running ffmpeg myself. Simple reason: kino did immediately recognize my camera; handbrake didn't; just asked me to select some device ... probably just an easy thing; but as said - the other worked out of the box. Still: great answer! – GhostCat Jan 3 '17 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.