Showing posts with label dvd. Show all posts
Showing posts with label dvd. Show all posts

Tuesday, October 26, 2021

slowing video and audio

If possible, concatenate the entire video project MP4, and then do a final pass for speed and color changes.

concatenation method

To complete by simple concatenation of clips, with hard cuts, a list of clips in a TXT file and the "concat" filter will do the trick without rendering.

$ ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4

Put the text file in the directory with the clips or do absolute paths to them. The file is simple; each video is one line and takes the syntax:

$ nano mylist.txt
# comment line(s)
file video1.mp4
file '/home/foo/some-other-video.mp4'

Obviously, transitions which fade or dissolve require rendering; either way, starting with a synced final video, with a consistent clock (tbr), makes everything after easier.

concat codec

If using ffmpeg, then mpeg2video is the fastest lib, but also creates the largest files. Bitrate is the number one file-size determiner and what libx264 can do at 3M, takes 5M in mpeg2video. Videos with a mostly static image, like a logo, may only require 165K video encoding. A 165K example w/125K audio, 6.5MB for about 5 minutes.

biggest problems

If I'm going to change the speed of the video, and I only need the audio to stay synced, without a change in pitch, then it's trivial. But if I want the audio to drop or rise in pitch and still stay synced, the video typically must be split apart and the audio processed in, eg. sox. That said...

  • video artifacts: sometimes revealed. Interlace lines or tearing. ffmpeg yadif filter
  • playback: will recoding still playback on the original device? For ffmpeg, mpeg2video is the most reliable.
  • complexity and time investment: speed ramps, portions, complex filters -- all difficult with linux software
  • audio pitch: easiest is to change speed without changing audio sound. Pitch is more complicated. sox changes pitch when slowing, apts and atempo do not. Which will you need?

verify the streams in containers

We need this step to sort which streams our nav packets, video, and audio, reside on. In Linux, ffmpeg is nearly unavoidable, so assuming its use. Solciting ffmpeg information results in two numbers, the file number input, and the stream number. For example, ffmpeg -i result "0:0", means first file, first stream, "0:1", means first file, second stream, and so forth. MP4 files can contain multiple streams. Examining an AVI will only result in a single audio and video stream, per file.

deinterlace and tear solutions

Deinterlacing is the horizontal lines problem, tearing is the chunks of stuff. There are extremely good, but extremely slow deinterlace filters, but for me, the low-CPU filter yadif is typically fine. For tearing, I increase the bitrate to at least 4M. Here's a way to do both. For simplicity, not showing audio here.

$ ffmpeg -i input.mp4 -f dvd -vf "setpts=1.8*PTS,yadif" -b 4M -an sloweroutput.mp4

Although multiple filters, I didn't need 'filter complex' because only one input.

single command slowing

The decision point here is about audio pitch -- do you want the pitch to change when changing the audio? If no pitch change, either asetpts or atempo work fine. I like atempo. If need to recode, the basic mpeg2video video codec is the fastest, lightest lib going.

  • pitch change: So far, I can't do it. To get it right with a pitch change, I have to split-out audio and video, use sox on the audio, and recombine. I can never get ffmpeg filter, "atempo", to accmplish the pitch change. Eg. I slow the video to half speed using "setpts=2*PTS", then attempt to drop the audio pitch in half, "-af atempo=0.5". It processes without errors, and syncs but with zero pitch change.
  • no pitch change: "asetpts". It will adapt the audio, sometimes with strange effects, to the new speed, but the pitch will still be whatever.The timebase and so on will still be perfect sync with audio.

pitch change with sox (audio only)

Sox default is to change pitch when slowing or accelerating. Speeding-up audio is easier to match with video, since slowing the video is a repeating number. Sox can do four decimal places of precision(!)

17% slowing, w/pitch change.

$ ffmpeg -i input.mp4 -vf "setpts=1.2*PTS,yadif" -b:v 5M -vcodec copy -an slowedoutput.mp4
$ sox input.wav slowedoutput.wav speed 0.8333
$ ffmpeg -i video.mp4 -i audio.wav -vcodec copy recombined.mp4

30% slowing and pitch change.

$ ffmpeg -i input.mp4 -vf "setpts=1.5*PTS,yadif" -b:v 4M -vcodec copy -an slowedoutput.mp4
$ sox input.wav slowedoutput.wav speed 0.667
$ ffmpeg -i video.mp4 -i audio.wav -vcodec copy recombined.mp4

An output made 20% faster, and pitch change, that syncs perfectly.

$ ffmpeg -i input.mp4 -vf "setpts=0.8*PTS" -b:v 4M -vcodec mpeg2video fasteroutput.mp4
$ sox input.wav fasteroutput.wav speed 1.25
$ ffmpeg -i video.mp4 -i audio.wav -vcodec copy recombined.mp4

bitrate C flag

Sox defaults to 128Kb, so need the "C" flag. Eg to get 320K and slow it to 92%...

sox foo.wav -C 320 foo90.mp3 speed 0.92

pulling from DVD

Be sure to install libdvdcss

single title, "VTS_01_2.VOB".
vobcopy -i /run/media/foo/SOMETITLE -O VTS_01_2.VOB -o /home/foo/SOMEFOLDER
entire disc:

problems

On occasion, if you backup a DVD, you don't need the nav stream anymore and you'll have extra work on filters if you leave it in.
$ ffmpeg -i input.mp4
Input #0, mpeg, from 'input.mp4':
 Duration: etc
 Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, etc) 
 Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
 Stream #0:2[0x1bf]: Data: dvd_nav_packet

Delete the audio and data streams:

ffmpeg -i input.mp4 -map 0:v -c copy output.mp4

Saturday, January 30, 2016

vaapi and vdpau api's - dvd playback

Using VLC, I recently played a commercial 2 DVD set (720P) on a reliable optical drive. One DVD chapter would not play and the disk appeared to have a small scratch. Before returning it for a refund, I thought I should try something besides VLC to rule-out those random situations where it's a software glitch. The command line version of Mplayer used to be a great equalizer, for example. However, I don't know VAAPI and VDPAU parameters, or say, XvMC. Situation seemed worthy of a trail of crumbs here.

overview

It's important to know one's hardware in this situation. To my understanding, VAAPI is a native Intel API, VDPAU is a native NVidia API.
$ lspci |grep -i vga
01:05.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] RS780MC [Mobility Radeon HD 3100]
And so of course, I get "Radeon", lol. At any rate, both VDPAU and VAAPI pass video encoding to a GPU from a CPU. Each is available to any software (scroll down), though some software is crafted with a preference. There is a lot of information out there that we don't want to use VDPAU as a wrapper, and should pick native VAAPI or VDPAU, not a wrapper accessed through the other. Then configure all software to work on that basis.

settings beyond the API

Besides the API, another playback parameter is setting cache and framedrop flags when running Mplayer. Running VLC, playback was clean, except that it paused on the scratched disc. Using Mplayer, I experienced no pauses, but had tearing or pixellation throughout, aka, a configuration issue.

troubleshoot

$ mplayer dvd:// /dev/sr0 -nosound -framedrop
[pixellation, tearing, sync errors]

$ strace mplayer dvd:// /dev/sr0 -nosound -framedrop &> vidfail.txt

$ grep -in "vidp*" vidfail.txt
3136:open("/usr/lib/vdpau/libvdpau_r600.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
3141:open("/usr/lib/libvdpau_r600.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
3143:write(2, "Failed to open VDPAU backend lib"..., 105Failed to open VDPAU backend libvdpau_r600.so: cannot open shared object file: No such file or directory
3145:write(2, "[vdpau] Error when calling vdp_d"..., 52[vdpau] Error when calling vdp_device_create_x11: 1

$ find -name "libvd*"
/usr/lib/libvdpau.so.1.0.0
./usr/lib/libvdpau.so
./usr/lib/libvdpau.so.1

vaapi checks

VAAPI is less desirable these days, for example according to this post. But we can check to see if it's operational, in case we had MPlayer or VLC configured to use it -- it might explain the fail.
$ vainfo
libva info: VA-API version 0.38.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/dri/r600_drv_video.so
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit
In this case, we see that VAAPI is not loading VDPAU, which VAAPI can only use as a wrapper. We know this because r600 is part of VDPAU, typically loaded along with Mesa or GStreamer. It appears the order of loading ins VAAPI, then an attempt to call the VDPAU wrapper. We know this because:
$ vlc --avcodec-hw=/usr/lib/xorg/modules/dri/r600_dri.so video.mp4
VLC media player 2.2.1 Terry Pratchett (Weatherwax) (revision 2.2.1-0-ga425c42)
Failed to open VDPAU backend libvdpau_r600.so: cannot open shared object file: No such file or directory.
I'm pointing VLC directly at the r600.so lib, yet it continues not to "exist". It appears VAAPI is loading but can't find this backend lib, even with a path supplied. This will require additional investigation.

vdpau checks

$ grep -i vdpau ~/.local/share/xorg/Xorg.0.log
[ 34.798] (II) RADEON(0): [DRI2] VDPAU driver: r600
I see the r600 driver is there, and is apparently operational. Not that I care about wrappers, but the reason VAAPI cannot find VDPAU to use as a wrapper, is I probably do not have a line to export the VDPAU variable export VDPAU_DRIVER=r600 in my ~/.bashrc file. Since I know r600 is operational, I merely need to configure VLC and MPLayer to work exclusively with VDPAU, or install gallium.

Monday, December 20, 2010

backup data disk

Links: command line howto

It seemed there should be an easy way to back-up copies of data disks. Of course, one can just copy the files to the system, and then create another DVD, but it makes sense there should be a more efficient way to duplicate data disks for back-ups. I found a way that takes only two commands.

terminal commands
It appears difficult to get started without at least copying the DVD data to the drive in the form of an .iso. Still, an .iso is more efficient than copying over all of the files and creating a new iso. Start by putting the data DVD into the drive and unmount it if it auto-mounts. Next,eg:
$ dd if=/dev/hdc of=somename.iso
On some systems, this might be
$ dd if=/dev/sr0 of=somename.iso
Now that we have the .iso, we can just burn as many copies as we'd like.

Friday, February 12, 2010

cdrecord/wodim woes

Links: Bug w/wodim info  Firmware info


Apparently there has been a fork in what previously was cdrtools. What's apparently happened is the previously robust cdrecord may have had licensing issues so that what's now called cdrecord is actually an alias for wodim. Wodim appears to be Jörg Schilling's freely licensed forefather to his more developed offspring cdrecord. It seems that, once the licensing problems with cdrecord became evident in 2006, the freely licensed, and more rudimentary, wodim was resurrected and included in cdrkit nee cdrtools.

This came up in an attempt to upgrade firmware on an old Pioneer drive that, for some reason, was only burning at about a 1/10th of its rated speeds. When I ran the reliable and familiar
$ cdrecord -scanbus
just to get a part number, I found results under the command wodim, which caused concern. On a web-facing PC, any time I enter one command and another appears, I'm going to ponder the worst scenario. Ah, but it's just a licensing issue.

But a real concern are any limitations with wodim not present in cdrecord. For example, in the same box that I used to have good results with cdrecord, I get these results with wodim.

$ wodim -scanbus

wodim: No such file or directory.
Cannot open SCSI driver!
For possible targets try 'wodim --devices' or 'wodim -scanbus'.
For possible transport specifiers try 'wodim dev=help'.
For IDE/ATAPI devices configuration, see the file README.ATAPI.setup from
the wodim documentation.


$ find -name README.ATAPI

./usr/doc/cdrkit-1.1.9/READMEs/README.ATAPI

Saturday, December 19, 2009

dvd-burning burn-out

Links: Firmware info   Firmware   Latest DVRFlash
It used to be that DVD-burning was pretty straightforward under various distributions:
$ growisofs -dvd-compat -Z /dev/hdc=myvacation.iso
Mostly, all would go smoothly. However, hardware driver advances have been uneven, such as for drives and cables and I/0 ports, firmware, and the BIOS. A DVD drive might read OK, yet might encounter glitches when burning:
$ growisofs -dvd-compat -Z /dev/hdc=myvacation.iso Executing 'builtin_dd if=myvacation.iso of=/dev/sr0 obs=32k seek=0' :-[ PERFORM OPC failed with SK=3h/POWER CALIBRATION AREA ERROR]: Input/output error

A user could run a burn program (eg. Brasero) to overcome manual settings. However, the next problem is the DVD drive, which is supposed to burn at, say, 4-16x, is burning instead at about .5x. That would be something like 680 KbSec, if we agree 1x is supposed to be about 1.32 MB/Sec. This is annoying, to be sure. (Note: one good thing about Brasero, it seems a rare non-K3b burner which will do video, at least if configured properly.

Is the cable the problem, the DVD firmware... some other? The burner only working at 1/8 of its lowest burn speed is going to cause I/O problems and user delays. We could also test the burner's native capacity, as described here, to provide a rough view.

# hdparm -i /dev/sr0
Model=PIONEER DVD-RW DVR-108 , FwRev=1.18 , SerialNo=
Config={ Fixed Removeable DTR<=5Mbs DTR>10Mbs nonMagnetic }
RawCHS=0/0/0, TrkSize=0, SectSize=0, ECCbytes=0
BuffType=13395, BuffSize=64kB, MaxMultSect=0
(maybe): CurCHS=0/0/0, CurSects=0, LBA=yes, LBAsects=0
IORDY=on/off, tPIO={min:240,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes: pio0 pio1 pio2 pio3 pio4
DMA modes: mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 udma2 udma3 *udma4
AdvancedPM=no
Drive conforms to: Unspecified: ATA/ATAPI-2,3,4,5

* signifies the current active mode

# hdparm -I /dev/sr0

ATAPI CD-ROM, with removable media
Model Number: PIONEER DVD-RW DVR-108
Serial Number: DKDC451400WL
Firmware Revision: 1.18
Standards:
Likely used CD-ROM ATAPI-1
Configuration:
DRQ response: 50us.
Packet size: 12 bytes
cache/buffer size = unknown
Capabilities:
LBA, IORDY(can be disabled)
Buffer size: 64.0kB
DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 *udma4
Cycle time: min=120ns recommended=120ns
PIO: pio0 pio1 pio2 pio3 pio4
Cycle time: no flow control=240ns IORDY flow control=120ns
Commands/features:
Enabled Supported:
* Power Management feature set
* PACKET command feature set
* DEVICE_RESET command
HW reset results:
CBLID- above Vih
Device num = 0 determined by the jumper

# hdparm -tT /dev/sr0

Timing cached reads: 1234 MB in 2.00 seconds = 616.60 MB/sec
Timing buffered disk reads: 22 MB in 3.23 seconds = 6.82 MB/sec

Speed

With an advertised 12x reading speed, a speed of about 16 MB/sec, we see that the true, uncached read speed of 6.82 MB/sec is not coming close. And, as noted above, a write speed of about .682 MB/sec, is anywhere between 1/8 to 1/32 of the advertised 4x-16x write speed range. Hmm...

DMA

The first two checks confirm UDMA (Ultra Direct Memory Access) is working, and that in fact UDMA4, one of the faster forms of UDMA, has been selected. It's also worth the reading the IDE ffile with $ cat /proc/ide/piix.

Cable

UDMA4 requires an 80 pin cable to transfer reliably at the 66 MB/Sec transfer rate. Apparently, avoiding capacitive interference is the issue for using the 80 pin over its 40 pin predecessor. I haven't opened the box, but it's unlikely that an 80 pin cable was used for this drive, since I simply cannibalized two drives from older systems when constructing the system. The 80 pin cables are more reliable as well as backwards-compatible to earlier drives. At any rate, I can note this as potentially a problem, but perhaps not a full explanation.