How i could cut the last 7 second of my video with ffmpeg?

4

0

I captured a video from my camera, but I don't know exactly how long it is. I want to use ffmpeg to keep and cut only the last 7 seconds of the video. Is this possible?

I tried the command:

ffmpeg -t 00:00:07 -i input.avi -vcodec copy newfile.avi

but it only skips the first 7 seconds of the video, and displays the video flipped.

NickName

Posted 2014-04-22T22:32:02.853

Reputation: 51

1I wonder why it shows the video flipped. But to know the duration of the video use the command ffmpeg -i input.avi without output file name. That will show duration. Then you can use duration - 7 to use for the -ss flag. Provide the complete console output here. – Rajib – 2014-04-23T12:53:12.300

I know that but i am trying to use ffmpeg from my C# code so i am trying to do it without know the duration of video. I just want to cut the last 7 seconds – NickName – 2014-04-23T13:22:52.553

I'm not at all learned about C# but why can't you query the duration from C#- ffmpeg/ffprobe (check the modules which provide duration in the code) and then pass the information back? – Rajib – 2014-04-23T15:51:21.763

Answers

4

You have to find out the total duration of the video (either with parsing ffmpeg output or using other libraries such as MediaInfo, etc.), d and then subtract the time manually from that.

Say your video is 40 seconds long and you want to cut 7 seconds, you need to encode only 33 seconds, so do:

ffmpeg -i input.avi -t 33 -c copy output.avi

slhck

Posted 2014-04-22T22:32:02.853

Reputation: 182 472