[FFmpeg-user] the trim filter

Jim DeLaHunt list+ffmpeg-user at jdlh.com
Fri Jul 5 21:34:30 EEST 2024


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.

Maybe you should rewrite the filtergraph so that you break apart the 
video and audio parts of your input media into separate flows? Then 
apply `trim` to the video media, and separately apply `atrim` to the 
audio media.  Then recombine the video and audio into your output.

I think the documentation is not doing you any favours here.  As I read 
the `trim` filter doc <https://ffmpeg.org/ffmpeg-filters.html#trim> and 
the `atrim` doc <https://ffmpeg.org/ffmpeg-filters.html#atrim>, neither 
talk about being limited to video or audio types of media.

I don't know enough about `ffmpeg` to say off the top of my head how to 
separate the audio media from the video media and feed them to each 
their own filters. Maybe the documentation on "Stream Selection" 
<https://ffmpeg.org/ffmpeg-all.html#Stream-selection> has the answer. 
Maybe you can append stream specifiers like [i5:v] and [i5:a] to get the 
video and audio streams separately.  I will leave that to others to 
figure out.

I hope this helps,
     —Jim DeLaHunt


More information about the ffmpeg-user mailing list