How do I select the audio corresponding to a set of filter-selected videoframes?
E.g. at the moment I am sampling 1 in every 100 frames of a video (running at 15fps) using the FFMpeg select
filter. When I try to select the audio of those frames with the aselect
filter, the total audio duration is not equal to the video duration (2 or 3 seconds difference depending on which frames I selected). The audio sampling rate is listed as 22050Hz.
I tried using various -vsync
and -async
combinations but it made no difference. Is there a more accurate way of using aselect
?
A quick example command:
ffmpeg -i %INPUT% -vf select='between(n\,200\,399)',setpts='PTS-STARTPTS' -af aselect='between(n\,200\,399)',asetpts='PTS-STARTPTS'-y test.mkv
where 'INPUT' is the name of some file containing compressed video and audio. I am testing with the file AV36_1.avi found on this site hosting video samples. I get a video duration of 13.3 seconds and audio duration of 12 seconds.
output:
ffmpeg version N-77045-ga16243a Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 5.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-l
ibilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --en
able-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --ena
ble-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc
--enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enabl
e-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --
enable-lzma --enable-decklink --enable-zlib
libavutil 55. 9.100 / 55. 9.100
libavcodec 57. 16.101 / 57. 16.101
libavformat 57. 19.100 / 57. 19.100
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 20.100 / 6. 20.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Guessed Channel Layout for Input Stream #0.1 : stereo
Input #0, avi, from 'AV36_1.avi':
Duration: 00:00:32.93, start: 0.000000, bitrate: 2372 kb/s
Stream #0:0: Video: indeo5 (IV50 / 0x30355649), yuv410p, 320x240, 2058 kb/s,
15 fps, 15 tbr, 15 tbn, 15 tbc
Metadata:
title : Steyr.avi ┬ΦΣσε #1
Stream #0:1: Audio: adpcm_ms ([2][0][0][0] / 0x0002), 22050 Hz, 2 channels,
s16, 176 kb/s
Metadata:
title : Sound Forge 4.0 Audio
Output #0, avi, to 'test.avi':
Metadata:
ISFT : Lavf57.19.100
Stream #0:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 320x240, q=2-31, 200
kb/s, 15 fps, 15 tbn, 15 tbc
Metadata:
title : Steyr.avi ┬ΦΣσε #1
encoder : Lavc57.16.101 mpeg4
Stream #0:1: Audio: mp3 (libmp3lame) (U[0][0][0] / 0x0055), 22050 Hz, stereo
, s16p
Metadata:
title : Sound Forge 4.0 Audio
encoder : Lavc57.16.101 libmp3lame
Stream mapping:
Stream #0:0 -> #0:0 (indeo5 (native) -> mpeg4 (native))
Stream #0:1 -> #0:1 (adpcm_ms (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
frame= 98 fps=0.0 q=9.6 size= 294kB time=00:00:09.03 bitrate= 266.1kbits/s
frame= 200 fps=0.0 q=11.7 Lsize= 525kB time=00:00:13.33 bitrate= 322.5kbits
/s
video:429kB audio:72kB subtitle:0kB other streams:0kB global headers:0kB muxing
overhead: 4.625268%
I think I'm using the aselect filter wrong...
not(mod(n,100)) -vsync 0
). It would also be harder to select the corresponding audio frames.