File: test-audio.R

package info (click to toggle)
r-cran-av 0.5.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 324 kB
  • sloc: ansic: 1,353; sh: 83; makefile: 6
file content (41 lines) | stat: -rw-r--r-- 1,722 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
context("Convert Audio")

wonderland <- system.file('samples/Synapsis-Wonderland.mp3', package='av', mustWork = TRUE)

test_that("Audio can be converted to various formats", {
  tmp_wav <- normalizePath(tempfile(fileext = '.wav'), mustWork = FALSE)
  tmp_mp3 <- normalizePath(tempfile(fileext = '.mp3'), mustWork = FALSE)
  tmp_mp4 <- normalizePath(tempfile(fileext = '.mp4'), mustWork = FALSE)
  tmp_mkv <- normalizePath(tempfile(fileext = '.mkv'), mustWork = FALSE)
  input_info <- av_media_info(wonderland)

  # Convert mp3 to mkv (defaults to libvorbis audio)
  expect_equal(av_audio_convert(wonderland, tmp_mkv, verbose = FALSE), tmp_mkv)
  expect_true(file.exists(tmp_mkv))
  mkv_info <- av_media_info(tmp_mkv)
  expect_equal(input_info$duration, mkv_info$duration, tolerance = 0.1)
  expect_equal(nrow(mkv_info$audio), 1)

  # Convert mp3 to mp4 (defaults to aac audio)
  expect_equal(av_audio_convert(wonderland, tmp_mp4, verbose = FALSE), tmp_mp4)
  expect_true(file.exists(tmp_mp4))
  mp4_info <- av_media_info(tmp_mp4)
  expect_equal(input_info$duration, mp4_info$duration, tolerance = 0.1)
  expect_equal(nrow(mp4_info$audio), 1)

  # Convert mp3 to wav
  expect_equal(av_audio_convert(wonderland, tmp_wav, verbose = FALSE), tmp_wav)
  expect_true(file.exists(tmp_wav))
  wav_info <- av_media_info(tmp_wav)
  expect_equal(input_info$duration, wav_info$duration, tolerance = 0.1)
  expect_equal(nrow(wav_info$audio), 1)

  # Convert wav to mp3
  expect_equal(av_audio_convert(tmp_wav, tmp_mp3, verbose = FALSE), tmp_mp3)
  expect_true(file.exists(tmp_mp3))
  mp3_info <- av_media_info(tmp_mp3)
  expect_equal(input_info$duration, mp3_info$duration, tolerance = 0.1)
  expect_equal(nrow(mp3_info$audio), 1)

})