When clipping by exact frame, how to get correct audio to match that clip?
I am trying to extract a clip of a video by the exact frames. I tried ffmpeg -i "InputFile.mp4" -vf select="between(n\, 1069\, 1263),setpts=PTS-STARTPTS" "OutputAttempt1.mp4" and ffmpeg -i "InputFile.mp4" -vf trim=start_frame=1069:end_frame=1264,setpts=PTS-STARTPTS "OutputAttempt2.mp4" (In the second command, the ending frame is 1 greater than in the first command because the documentation indicates "end_frame" is the first frame that gets dropped, and I want to include frame 1263.) The video in the output files is correct and covers the frames that I want. The problem is that in both my attempts, the ENTIRE audio track is copied over to the output file, when I only want the portion of the audio track that plays at the same time (in the input video) as the video frames that I extracted for the output video. How do I get ONLY that portion of the audio into the output?
Am 24.05.2023 um 05:37 schrieb Sam Logan:
I am trying to extract a clip of a video by the exact frames.
I tried
ffmpeg -i "InputFile.mp4" -vf select="between(n\, 1069\, 1263),setpts=PTS-STARTPTS" "OutputAttempt1.mp4"
and
ffmpeg -i "InputFile.mp4" -vf trim=start_frame=1069:end_frame=1264,setpts=PTS-STARTPTS "OutputAttempt2.mp4"
(In the second command, the ending frame is 1 greater than in the first command because the documentation indicates "end_frame" is the first frame that gets dropped, and I want to include frame 1263.)
The video in the output files is correct and covers the frames that I want. The problem is that in both my attempts, the ENTIRE audio track is copied over to the output file, when I only want the portion of the audio track that plays at the same time (in the input video) as the video frames that I extracted for the output video. How do I get ONLY that portion of the audio into the output?
Have a look at the commands -af, aselect and atrim. Michael
But -aselect and -atrim select by audio sample numbers or timestamp, rather than by video frame numbers, so how do I determine what arguments to pass to -aselect and -atrim? Could someone please show me a command line with exactly what arguments to pass to -aselect or -atrim, based on my original post of wanting to clip video frames 1069 to 1263? Thanks. On Wed, May 24, 2023 at 1:03 AM Michael Koch <astroelectronic@t-online.de> wrote:
I am trying to extract a clip of a video by the exact frames.
I tried
ffmpeg -i "InputFile.mp4" -vf select="between(n\, 1069\, 1263),setpts=PTS-STARTPTS" "OutputAttempt1.mp4"
and
ffmpeg -i "InputFile.mp4" -vf trim=start_frame=1069:end_frame=1264,setpts=PTS-STARTPTS "OutputAttempt2.mp4"
(In the second command, the ending frame is 1 greater than in the first command because the documentation indicates "end_frame" is the first frame that gets dropped, and I want to include frame 1263.)
The video in the output files is correct and covers the frames that I want. The problem is that in both my attempts, the ENTIRE audio track is copied over to the output file, when I only want the portion of the audio track that
Am 24.05.2023 um 05:37 schrieb Sam Logan: plays
at the same time (in the input video) as the video frames that I extracted for the output video. How do I get ONLY that portion of the audio into the output?
Have a look at the commands -af, aselect and atrim.
Michael
_______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user
To unsubscribe, visit link above, or email ffmpeg-user-request@ffmpeg.org with subject "unsubscribe".
On 12 Jun 2023, at 07:15, Sam Logan <shapableline@gmail.com> wrote:
Could someone please show me a command line with exactly what arguments to pass to -aselect or -atrim, based on my original post of wanting to clip video frames 1069 to 1263?
Thanks.
The numbers obviously depend on framerate and audio sample rate. Bouke
On 12 Jun 2023, at 07:33, Edit 'B <bouke@editb.nl> wrote:
On 12 Jun 2023, at 07:15, Sam Logan <shapableline@gmail.com> wrote:
Could someone please show me a command line with exactly what arguments to pass to -aselect or -atrim, based on my original post of wanting to clip video frames 1069 to 1263?
Thanks.
The numbers obviously depend on framerate and audio sample rate.
Bouke
So the math is: frame number / frame rate * audio sample rate For speeds other than integers, use the 1000/1001 math. (23,976 vs 23,98 makes a huge difference on large numbers…) Bouke
I tried ffmpeg -i "InputFile.mp4" -vf "select='between(n, 1069, 1263)', setpts=PTS-STARTPTS" -af "aselect='between(t, 1069, 1263)', asetpts=N/SR/TB" "OutputAttempt.mp4" but this just results in an output file that has no audio track at all. What can I do to fix this? On Mon, Jun 12, 2023 at 3:13 AM Bouke / edit 'B <bouke@editb.nl> wrote:
On 12 Jun 2023, at 07:33, Edit 'B <bouke@editb.nl> wrote:
On 12 Jun 2023, at 07:15, Sam Logan <shapableline@gmail.com> wrote:
Could someone please show me a command line with exactly what arguments to pass to -aselect or -atrim, based on my original post of wanting to clip video frames 1069 to 1263?
Thanks.
The numbers obviously depend on framerate and audio sample rate.
Bouke
So the math is: frame number / frame rate * audio sample rate For speeds other than integers, use the 1000/1001 math. (23,976 vs 23,98 makes a huge difference on large numbers…)
Bouke _______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user
To unsubscribe, visit link above, or email ffmpeg-user-request@ffmpeg.org with subject "unsubscribe".
On 7/15/2023 11:04 PM, Sam Logan wrote:
ffmpeg -i "InputFile.mp4" -vf "select='between(n, 1069, 1263)', setpts=PTS-STARTPTS" -af "aselect='between(t, 1069, 1263)', asetpts=N/SR/TB" "OutputAttempt.mp4"
but this just results in an output file that has no audio track at all.
For a start 't' is not a frame number - "The PTS of the filtered frame, expressed in seconds." Example from the doc- Select only frames contained in the 10-20 time interval: select=between(t\,10\,20) (and you probably need to escape the commas) Looks like you need 'n' - "The (sequential) number of the filtered frame, starting from 0." (See example in the doc https://ffmpeg.org/ffmpeg-filters.html#select_002c-aselect
What can I do to fix this?
Please check the doc on the select filter, and post the complete and unedited output. Later, z!
participants (5)
-
Bouke / edit 'B -
Carl Zwanzig -
Edit 'B -
Michael Koch -
Sam Logan