[FFmpeg-user] the trim filter

Mark Filipak markfilipak.imdb at gmail.com
Sat Jul 6 04:18:31 EEST 2024


On 05/07/2024 15.41, Mark Filipak wrote:
> On 05/07/2024 14.34, Jim DeLaHunt wrote:
>> On 2024-07-04 15:50, Mark Filipak wrote:
>>
>>> ...Here's the interesting terminal output (slightly beautified):
>>>
>>> [Parsed_trim_1 @ 0000000000620040]
>>>  Media type mismatch between the 'Parsed_trim_1' filter output pad 0 (video) and the 
>>> 'Parsed_atrim_2' filter input pad 0 (audio)
>>>
>>> [AVFilterGraph @ 000000000061c7c0] Error linking filters
>>>
>>> Failed to set value
>>>  'split=2[i5][i6],
>>>  [i5]trim=start_frame=481:end_frame=134047, atrim=start_sample=962962:end_sample=268360092[o5],
>>>  [i6]trim=start_frame=138745:end_frame=246719[o6],
>>>  [o5][o6]concat=n=2'
>>> for option 'filter_complex': Invalid argument
>>> Error parsing global options: Invalid argument
>>
>> I think there is a clue in the previous part of the output:
>>
>>> [Parsed_trim_1 @ 0000000000620040] Media type mismatch between the 'Parsed_trim_1' filter output 
>>> pad 0 (video) and the 'Parsed_atrim_2' filter input pad 0 (audio)
>> I see "media type mismatch", so what is not matched?  I see a mention of "filter output pad 0 
>> (video)" and "filter input pad 0 (audio)". I can imagine that media "video" does not match media 
>> "audio".
>>
>>> ...Here's my trim commands for the first segment:
>>>
>>> trim=start_frame=481:end_frame=134047,atrim=start_sample=962962:end_sample=268360093
>>
>> Consulting the filtergraph syntax documentation 
>> <https://ffmpeg.org/ffmpeg-filters.html#Filtergraph-syntax-1>,
>>
>>> A filterchain consists of a sequence of connected filters, each one connected to the previous one 
>>> in the sequence. A filterchain is represented by a list of ","-separated filter descriptions. 
>> It looks like your trim commands for the first segment consist of a `trim` filter which reads 
>> video media from input pad [i5] and writes video media to an implicit output pad, connected to an 
>> `atrim` filter which wants reads audio media from an implicit input pad. But the implicit output 
>> pad is giving video media to a filter which wants audio media.
>>
>> That looks like a type mismatch to me.
> 
> I agree. I expected that
> [i5]trim=start_frame=481:end_frame=134047, atrim=start_sample=962962:end_sample=268360092[o5]
> was a stream and that atrim would operate only on the audio part of that stream. But it appears that 
> I may have to split the video and audio streams into two discrete streams (or maybe more if there 
> were more than one video stream and/or more than one audio stream). This is an architectural 
> shortcoming of FFmpeg and is something OFFmpeg does not suffer.
> 
> When I find the time, I'll explore this further and I'll try some of your good ideas.

Well, I separated video & audio into separate streams but got the same result:
"Media type mismatch between the 'Parsed_split_0' filter output pad 1 (video) and the 
'Parsed_atrim_2' filter input pad 0 (audio)"
So, the video stream is going right through '[o5v],[i5a]'

I've never had to do this before. I'm in unknown territory.

--Mark.


THE SCRIPT:

set F=split=8[i5v][i5a][i6v][i6a][i7v][i7a][i8v][i8a],

: sexagesimal 5:            20.062..1:33:10.835
: frames 5:        20.062*24/1.001..5590.835*24/1.001  = 481..134046

set F=%F% [i5v]trim=start_frame=481:end_frame=134047[o5v],
set F=%F% [i5a]atrim=start=20.062:end=5590.835[o5a],
set F=%F% [o5v][o5a]interleave[o5],

: sexagesimal 6:       1:36:26.823..2:51:30.197
: frames 6:      5786.823*24/1.001..10290.197*24/1.001 = 138745..246718

set F=%F% [i6v]trim=start_frame=138745:end_frame=246719[o6v],
set F=%F% [i6a]atrim=start=5786.823:end=10290.197[o6a],
set F=%F% [o6v][o6a]interleave[o6],

: sexagesimal 7:       2:54:49.062..3:51:41.805
: frames 7:     10489.062*24/1.001..13901.805*24/1.001 = 251486..333310

set F=%F% [i7v]trim=start_frame=251486:end_frame=333310[o7v],
set F=%F% [i7a]atrim=start=10489.062:end=13901.805[o7a],
set F=%F% [o7v][o7a]interleave[o7],

: sexagesimal 8:       3:54:58.167..
: frames 8:     14098.167*24/1.001..                   = 338018..

set F=%F% [i8v]trim=start_frame=338018[o8v],
set F=%F% [i8a]atrim=start=14098.167[o8a],
set F=%F% [o8v][o8a]interleave[o8],

set F=%F%[o5][o6][o7][o8]concat=n=4[o]
set C=-c:v libx265 -x265-params crf=16 -c:a dts -strict -2 -sn
ffmpeg -i g:\00305+00306+00307+00308.m2ts -filter_complex "%F%" -map "[o]" %C% -start_at_zero 
e:\00305+00306+00307+00308.mp4
pause


THE TERMINAL OUTPUT:

G:\>ffmpeg -i g:\00305+00306+00307+00308.m2ts -filter_complex 
"split=8[i5v][i5a][i6v][i6a][i7v][i7a][i8v][i8a], [i5v]trim=start_frame=481:end_frame=134047[o5v], 
[i5a]atrim=start=20.062:end=5590.835[o5a], [o5v][o5a]interleave[o5], 
[i6v]trim=start_frame=138745:end_frame=246719[o6v], [i6a]atrim=start=5786.823:end=10290.197[o6a], 
[o6v][o6a]interleave[o6], [i7v]trim=start_frame=251486:end_frame=333310[o7v], 
[i7a]atrim=start=10489.062:end=13901.805[o7a], [o7v][o7a]interleave[o7], 
[i8v]trim=start_frame=338018[o8v], [i8a]atrim=start=14098.167[o8a], 
[o8v][o8a]interleave[o8],[o5][o6][o7][o8]concat=n=4[o]" -map "[o]" -c:v libx265 -x265-params crf=16 
-c:a dts -strict -2 -sn -start_at_zero e:\00305+00306+00307+00308.mp4
ffmpeg version 2024-05-20-git-127ded5078-full_build-www.gyan.dev Copyright (c) 2000-2024 the FFmpeg 
developers
   built with gcc 13.2.0 (Rev5, Built by MSYS2 project)
   configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads 
--disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 
--enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist 
--enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray 
--enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d 
--enable-libdavs2 --enable-libuavs3d --enable-libxevd --enable-libzvbi --enable-librav1e 
--enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 
--enable-libxeve --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg 
--enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype 
--enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf 
--enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va 
--enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi 
--enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio 
--enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb 
--enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc 
--enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus 
--enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite 
--enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
   libavutil      59. 19.100 / 59. 19.100
   libavcodec     61.  5.104 / 61.  5.104
   libavformat    61.  3.103 / 61.  3.103
   libavdevice    61.  2.100 / 61.  2.100
   libavfilter    10.  2.102 / 10.  2.102
   libswscale      8.  2.100 /  8.  2.100
   libswresample   5.  2.100 /  5.  2.100
   libpostproc    58.  2.100 / 58.  2.100
[Parsed_split_0 @ 00000000004bab40] Media type mismatch between the 'Parsed_split_0' filter output 
pad 1 (video) and the 'Parsed_atrim_2' filter input pad 0 (audio)
[AVFilterGraph @ 00000000004afe80] Error linking filters
Failed to set value 'split=8[i5v][i5a][i6v][i6a][i7v][i7a][i8v][i8a], 
[i5v]trim=start_frame=481:end_frame=134047[o5v], [i5a]atrim=start=20.062:end=5590.835[o5a], 
[o5v][o5a]interleave[o5], [i6v]trim=start_frame=138745:end_frame=246719[o6v], 
[i6a]atrim=start=5786.823:end=10290.197[o6a], [o6v][o6a]interleave[o6], 
[i7v]trim=start_frame=251486:end_frame=333310[o7v], [i7a]atrim=start=10489.062:end=13901.805[o7a], 
[o7v][o7a]interleave[o7], [i8v]trim=start_frame=338018[o8v], [i8a]atrim=start=14098.167[o8a], 
[o8v][o8a]interleave[o8],[o5][o6][o7][o8]concat=n=4[o]' for option 'filter_complex': Invalid argument
Error parsing global options: Invalid argument



More information about the ffmpeg-user mailing list