FFmpeg中使用reverse滤镜实现视频局部反转的技术咨询
Hey there! Let's get that partial video reversal working for you. The command you tried didn't hit the mark because the reverse filter's enable parameter doesn't function the way you might expect—it doesn't isolate and reverse a specific time segment, but instead toggles the reverse effect on/off for the entire stream, which isn't what you want.
The Correct Approach: Split, Reverse, Concatenate
To reverse only a portion of your video, you need to split the input into segments, reverse the target segment, then stitch everything back together. We'll handle both video and audio to keep them in sync.
Scenario 1: Reverse from 3 Seconds to the End of the Video
Use this command if you want everything after the 3-second mark reversed:
ffmpeg -y -i input.mp4 -filter_complex "\ [0:v]trim=start=0:end=3,setpts=PTS-STARTPTS[v1];\ [0:a]atrim=start=0:end=3,asetpts=PTS-STARTPTS[a1];\ [0:v]trim=start=3,setpts=PTS-STARTPTS[v2];\ [0:a]atrim=start=3,asetpts=PTS-STARTPTS[a2];\ [v2]reverse[v2r];\ [a2]areverse[a2r];\ [v1][a1][v2r][a2r]concat=n=2:v=1:a=1[v][a]\ " -map "[v]" -map "[a]" -vcodec libx264 -pix_fmt yuv420p -r 30 -g 60 -b:v 1200k -acodec libmp3lame -b:a 128k -ar 44100 -preset superfast output.mp4
Scenario 2: Reverse a Specific Middle Segment (e.g., 3–10 Seconds)
If you only want to reverse the segment between 3 and 10 seconds (keep the start and end normal), use this adjusted command:
ffmpeg -y -i input.mp4 -filter_complex "\ [0:v]trim=0:3,setpts=PTS-STARTPTS[v1];\ [0:a]atrim=0:3,asetpts=PTS-STARTPTS[a1];\ [0:v]trim=3:10,setpts=PTS-STARTPTS[v2];\ [0:a]atrim=3:10,asetpts=PTS-STARTPTS[a2];\ [v2]reverse[v2r];\ [a2]areverse[a2r];\ [0:v]trim=10,setpts=PTS-STARTPTS[v3];\ [0:a]atrim=10,asetpts=PTS-STARTPTS[a3];\ [v1][a1][v2r][a2r][v3][a3]concat=n=3:v=1:a=1[v][a]\ " -map "[v]" -map "[a]" -vcodec libx264 -pix_fmt yuv420p -r 30 -g 60 -b:v 1200k -acodec libmp3lame -b:a 128k -ar 44100 -preset superfast output.mp4
Breakdown of Key Filters
trim/atrim: Splits the video/audio into the exact segments you need. Adjust thestart/endvalues to match your desired timestamps.setpts/asetpts: Resets the timestamp of each segment so they play smoothly when concatenated (prevents sync issues or weird jumps).reverse/areverse: Reverses the target video and audio segments—always reverse both to keep them in sync!concat: Stitches all the segments back together into a single video/audio stream.
Why Your Original Command Failed
Your original reverse=enable='gte(t,3)' tells FFmpeg to apply the reverse filter only when the playback time is 3 seconds or later, but the reverse filter operates on the entire input stream, not just that time window. This leads to unexpected results because it's trying to reverse the whole video but only display the reversed version after 3 seconds, which isn't the partial reversal you're aiming for.
内容的提问来源于stack exchange,提问作者Ffmpeg

