How to get fragment of mp4 file? How to properly concatenate mp4 files?

James jam at tigger.ws
Wed Aug 23 14:42:16 UTC 2023



> On 23 Aug 2023, at 7:13 pm, James via gstreamer-devel <gstreamer-devel at lists.freedesktop.org> wrote:
> 
> 
> 
>> On 23 Aug 2023, at 5:57 pm, Антон Шаров via gstreamer-devel <gstreamer-devel at lists.freedesktop.org> wrote:
>> 
>> Hi.
>> 
>> 	• Given some mp4 file, I need to retrive fragment from it. Say I’m interested of a fragment on k second of a video file, I need to retrieve video fragment from k-2 second to k+2 second, namely few seconds before interested event, few second after interested event. What is the best approach (pipeline) to do that?
>> 	• What is the correct way to concatenate mp4 files, is it simple stream concatenation — append one file to another or there could be corner cases?
> 
> ffmpeg is your friend.
> Stackoverflow has lots of examples. (google)
> James 

As I said I use ffmpeg for cutting, not gstreamer, here are a few snips

Each segment

mythffmpeg -i ${RECDIR}/${BASENAME} -acodec copy -vcodec copy -ss $start -t $duration ${workdir}/${tmp}_${clipcount}.ts

then to join them

mythffmpeg -hide_banner -ignore_unknown -fflags +genpts -f concat -safe 0 -i $workdir/file -c copy "$dir$usename"

the file list:

file /store/TScut_work/10074_20230626143300_1.ts
file /store/TScut_work/10074_20230626143300_2.ts
file /store/TScut_work/10074_20230626143300_3.ts
file /store/TScut_work/10074_20230626143300_4.ts
file /store/TScut_work/10074_20230626143300_5.ts
file /store/TScut_work/10074_20230626143300_6.ts
file /store/TScut_work/10074_20230626143300_7.ts
file /store/TScut_work/10074_20230626143300_8.ts
file /store/TScut_work/10074_20230626143300_9.ts
file /store/TScut_work/10074_20230626143300_10.ts

I use ts because of lip-sync problems with shotcut but mp4's work the same
You also want to cut on keyframes. Maybe the gstreamer mail list can help

ffmpeg -ss start -i file does that

James

ps this is where I use https://tigger.ws/downloads/h264cut.sh


More information about the gstreamer-devel mailing list