ffmpeg-gl-transition icon indicating copy to clipboard operation
ffmpeg-gl-transition copied to clipboard

How Modify So Videos Remain Origin Length With Audio?

Open MotionDesignStudio opened this issue 5 years ago β€’ 15 comments

Using the example ffmpeg from this source. How can I modify it so it does not remove the audio and trim the video file lengths to 3 seconds? I already have the videos at the correct length.

` ./ffmpeg
-i c40.mov
-i c42.mov
-i c44.mov
-filter_complex "
[0:v]split[v000][v010];
[1:v]split[v100][v110];
[2:v]split[v200][v210];
[v000]trim=0:3[v001];
[v010]trim=3:4[v011t];
[v011t]setpts=PTS-STARTPTS[v011];
[v100]trim=0:3[v101];
[v110]trim=3:4[v111t];
[v111t]setpts=PTS-STARTPTS[v111];
[v200]trim=0:3[v201];
[v210]trim=3:4[v211t];
[v211t]setpts=PTS-STARTPTS[v211];
[v011][v101]gltransition=duration=1:source=/home/lex/share/python/ffmpegHelper/gl-transitions/transitions/burn.glsl[vt0];
[v111][v201]gltransition=duration=1[vt1];
[v001][vt0][vt1][v211]concat=n=4[outv]"
-map "[outv]"
-c:v libx264 -profile:v baseline -preset slow -movflags faststart -pix_fmt yuv420p
-y out.mp4

`

MotionDesignStudio avatar Apr 12 '19 20:04 MotionDesignStudio

Is there a solution?

jerryname2022 avatar Jun 06 '19 09:06 jerryname2022

Yes I solved it. Would you like the solution?


From: xiaomingzhong [email protected] Sent: Thursday, June 6, 2019 5:38 AM To: transitive-bullshit/ffmpeg-gl-transition Cc: Motion Design Studio; Author Subject: Re: [transitive-bullshit/ffmpeg-gl-transition] How Modify So Videos Remain Origin Length With Audio? (#38)

Is there a solution?

β€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/transitive-bullshit/ffmpeg-gl-transition/issues/38?email_source=notifications&email_token=ABRPUWUKM57RKX62GGJGMRDPZDLJ7A5CNFSM4HFUPSHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXCJXJA#issuecomment-499424164, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABRPUWTUF2X4NZ5WB3YEMOLPZDLJ7ANCNFSM4HFUPSHA.

MotionDesignStudio avatar Jun 06 '19 19:06 MotionDesignStudio

@MotionDesignStudio I'm sure many people would find your solution useful.

Thanks! πŸ˜„

transitive-bullshit avatar Jun 07 '19 02:06 transitive-bullshit

@MotionDesignStudio How did you do it?

jerryname2022 avatar Jun 07 '19 08:06 jerryname2022

./ffmpeg -i c1.mov -i c2.mov -i c3.mov   \
-filter_complex \
" [0:a]atrim=0:9.01[a0]; [1:a]atrim=0:7.007999999999999[a1];  \
[2:a]atrim=0:10.01[a2];  [0:v]split[v0][v10];  \
[1:v]split[v20][v30]; [2:v]split[v40][v50];  \
[v0]trim=0:9.01[v1];  \
[v10]trim=9.01:10.01,setpts=PTS-STARTPTS[v11];  \
[v20]trim=0:7.007999999999999[v21];  \
[v30]trim=7.007999999999999:8.008,setpts=PTS-STARTPTS[v31];  \
[v40]trim=0:9.01[v41]; \
[v50]trim=9.01:10.01,setpts=PTS-STARTPTS[v51];  \
[v11][v21]gltransition=duration=1:source=./FilmBurn.glsl[vt0]; \
[v31][v41]gltransition=duration=1:source=./FilmBurn.glsl[vt1];  \
[v1][vt0][vt1][v51]concat=n=4 [v];  \
[a0][a1][a2]concat=n=3:v=0:a=1[audio]" -map "[v]" -map "[audio]" \
-vcodec libx264 -crf 23 -preset medium -acodec aac -strict experimental -ac 2 -ar 44100 -ab 128k -y out.mp4

Let me explain how this works.

./ffmpeg -i c1.mov -i c2.mov -i c3.mov   \  

# These are my three seperate videos to combine.

-filter_complex \
" [0:a]atrim=0:9.01[a0]; [1:a]atrim=0:7.007999999999999[a1]; [2:a]atrim=0:10.01[a2]; \ 

# These three audio trims are necessary.  The length of your gl-transition dictates how much audio to trim.  In this situation I will loose the last 1 second of each video.  The last video in my input requires losing nothing so I can keep it full length and the audio will all align with the final video.

[0:v]split[v0][v10]; [1:v]split[v20][v30]; [2:v]split[v40][v50];  \ 

# Split command makes two duplicate copies of each input video.  The second split video is the one gl-transition will work on.

[v0]trim=0:9.01[v1];  \

# Because my transition lasts 1 second I need to trim off one second from the first duplicated video ( c1.mov ) and store it in the variable [v1]

[v10]trim=9.01:10.01,setpts=PTS-STARTPTS[v11];  \

# This split stores the the last one second of video c1.mov and stores it in the variable [v11].
# Below the process is repeated for each video.

[v20]trim=0:7.007999999999999[v21];  \
[v30]trim=7.007999999999999:8.008,setpts=PTS-STARTPTS[v31];  \
[v40]trim=0:9.01[v41]; \
[v50]trim=9.01:10.01,setpts=PTS-STARTPTS[v51];  \

[v11][v21]gltransition=duration=1:source=./FilmBurn.glsl[vt0]; \

# [v11] is the variable storing the last 1 second of video c1.mov.  [v21] is the variable storing the beginning of the second video minus its last 1 second.  gl-transition needs two videos to perform its transition on.  Once complete it stores the transition video into the variable [vt0]

# Below I repeat this for the next video(s).  The very last video in your inputs has no candidate to transition to so you can see how I do not replicate the process.

[v31][v41]gltransition=duration=1:source=./FilmBurn.glsl[vt1];  \

[v1][vt0][vt1][v51]concat=n=4 [v];  \

# Let us concat the the videos [v1] first video c1.mov minus the last 1 second of it.  [vt0] the gl-transition from the last 1 second of video c1.mov and the first part of c2.mov without the last 1 second.

[a0][a1][a2]concat=n=3:v=0:a=1[audio]" -map "[v]" -map "[audio]" \

# Let us concat the audio and use map to combine the audio and video.

-vcodec libx264 -crf 23 -preset medium -acodec aac -strict experimental -ac 2 -ar 44100 -ab 128k -y out.mp4

I made this python script to help easy some effect with ffmpeg. The source is here.

https://github.com/MotionDesignStudio/commandlinemediahelper

In the version 3 directory β€œver3” this file ffmpegHelper.py will concat your video with audio for you.

How to use this. Place all the videos you want to concat into the same directory name in order like this c1.mp4, c22.mp4 c23.mkv, c45.mov on and on. The script will place them in order.

You must also use the special stand alone ffmpeg I compiled with gl-transition in the same folder or reference to its path. You also need a transition you would like to use. I like FilmBurn.glsl . Directory transitions contains transitions from gl-transition project.

The ffmpeg I compiled was done for Debian 64 bit buster. If it complains about dependencies do the following to see what it needs.

# ld fffmpeg

And install those.

Use this concat the videos with audio.

# ./ffmpegHelper.py -c8 ./ffmpeg ./FilmBurn.glsl 1 Y out.mp4

Want to see what other things the code automates with ffmpeg. Do the following.

# ./ffmpegHelper.py -h

MotionDesignStudio avatar Jun 07 '19 17:06 MotionDesignStudio

(updated @MotionDesignStudio's markdown formatting to be a bit more readable)

Thanks a lot @MotionDesignStudio -- this is a really great and thorough breakdown that I'm sure many people will find useful! πŸ˜ƒ

transitive-bullshit avatar Jun 07 '19 21:06 transitive-bullshit

transitive-bullshit, thanks for editing. How did you format the code that way? I used the insert code and that did not format it.

Thanks

MotionDesignStudio avatar Jun 07 '19 23:06 MotionDesignStudio

You can click on the ... in the upper right hand corner of your message to edit it and view the markdown that I used.

transitive-bullshit avatar Jun 07 '19 23:06 transitive-bullshit

@MotionDesignStudio Thanks

jerryname2022 avatar Jun 08 '19 00:06 jerryname2022

@MotionDesignStudio i forked your project

jerryname2022 avatar Jun 08 '19 00:06 jerryname2022

Good it truly needs more input.

I am going to redo the architect to use more classes, get rid of the dependency, more flexible ffmpeg detection, a whole lot more error handling and how functions are called from command line.

I want to add more affects such as slowmo code and that trendy boomerang effect.

I also want add a text alert after rendering is complete because it can take 12 plus hours to render a video.

I have batch processing way I have been thinking of I need to add.

Long term which I have never done is build a GUI.


From: xiaomingzhong [email protected] Sent: Friday, June 7, 2019 8:27:49 PM To: transitive-bullshit/ffmpeg-gl-transition Cc: Motion Design Studio; Mention Subject: Re: [transitive-bullshit/ffmpeg-gl-transition] How Modify So Videos Remain Origin Length With Audio? (#38)

@MotionDesignStudiohttps://github.com/MotionDesignStudio i forked your project

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/transitive-bullshit/ffmpeg-gl-transition/issues/38?email_source=notifications&email_token=ABRPUWXYX7YMULASJ7DDTZDPZL4ILA5CNFSM4HFUPSHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXHJCMY#issuecomment-500076851, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABRPUWTVXM2UE3GWWWOYSN3PZL4ILANCNFSM4HFUPSHA.

MotionDesignStudio avatar Jun 08 '19 14:06 MotionDesignStudio

./ffmpeg -i c1.mov -i c2.mov -i c3.mov   \
-filter_complex \
" [0:a]atrim=0:9.01[a0]; [1:a]atrim=0:7.007999999999999[a1];  \
[2:a]atrim=0:10.01[a2];  [0:v]split[v0][v10];  \
[1:v]split[v20][v30]; [2:v]split[v40][v50];  \
[v0]trim=0:9.01[v1];  \
[v10]trim=9.01:10.01,setpts=PTS-STARTPTS[v11];  \
[v20]trim=0:7.007999999999999[v21];  \
[v30]trim=7.007999999999999:8.008,setpts=PTS-STARTPTS[v31];  \
[v40]trim=0:9.01[v41]; \
[v50]trim=9.01:10.01,setpts=PTS-STARTPTS[v51];  \
[v11][v21]gltransition=duration=1:source=./FilmBurn.glsl[vt0]; \
[v31][v41]gltransition=duration=1:source=./FilmBurn.glsl[vt1];  \
[v1][vt0][vt1][v51]concat=n=4 [v];  \
[a0][a1][a2]concat=n=3:v=0:a=1[audio]" -map "[v]" -map "[audio]" \
-vcodec libx264 -crf 23 -preset medium -acodec aac -strict experimental -ac 2 -ar 44100 -ab 128k -y out.mp4

Let me explain how this works.

./ffmpeg -i c1.mov -i c2.mov -i c3.mov   \  

# These are my three seperate videos to combine.

-filter_complex \
" [0:a]atrim=0:9.01[a0]; [1:a]atrim=0:7.007999999999999[a1]; [2:a]atrim=0:10.01[a2]; \ 

# These three audio trims are necessary.  The length of your gl-transition dictates how much audio to trim.  In this situation I will loose the last 1 second of each video.  The last video in my input requires losing nothing so I can keep it full length and the audio will all align with the final video.

[0:v]split[v0][v10]; [1:v]split[v20][v30]; [2:v]split[v40][v50];  \ 

# Split command makes two duplicate copies of each input video.  The second split video is the one gl-transition will work on.

[v0]trim=0:9.01[v1];  \

# Because my transition lasts 1 second I need to trim off one second from the first duplicated video ( c1.mov ) and store it in the variable [v1]

[v10]trim=9.01:10.01,setpts=PTS-STARTPTS[v11];  \

# This split stores the the last one second of video c1.mov and stores it in the variable [v11].
# Below the process is repeated for each video.

[v20]trim=0:7.007999999999999[v21];  \
[v30]trim=7.007999999999999:8.008,setpts=PTS-STARTPTS[v31];  \
[v40]trim=0:9.01[v41]; \
[v50]trim=9.01:10.01,setpts=PTS-STARTPTS[v51];  \

[v11][v21]gltransition=duration=1:source=./FilmBurn.glsl[vt0]; \

# [v11] is the variable storing the last 1 second of video c1.mov.  [v21] is the variable storing the beginning of the second video minus its last 1 second.  gl-transition needs two videos to perform its transition on.  Once complete it stores the transition video into the variable [vt0]

# Below I repeat this for the next video(s).  The very last video in your inputs has no candidate to transition to so you can see how I do not replicate the process.

[v31][v41]gltransition=duration=1:source=./FilmBurn.glsl[vt1];  \

[v1][vt0][vt1][v51]concat=n=4 [v];  \

# Let us concat the the videos [v1] first video c1.mov minus the last 1 second of it.  [vt0] the gl-transition from the last 1 second of video c1.mov and the first part of c2.mov without the last 1 second.

[a0][a1][a2]concat=n=3:v=0:a=1[audio]" -map "[v]" -map "[audio]" \

# Let us concat the audio and use map to combine the audio and video.

-vcodec libx264 -crf 23 -preset medium -acodec aac -strict experimental -ac 2 -ar 44100 -ab 128k -y out.mp4

I made this python script to help easy some effect with ffmpeg. The source is here.

https://github.com/MotionDesignStudio/commandlinemediahelper

In the version 3 directory β€œver3” this file ffmpegHelper.py will concat your video with audio for you.

How to use this. Place all the videos you want to concat into the same directory name in order like this c1.mp4, c22.mp4 c23.mkv, c45.mov on and on. The script will place them in order.

You must also use the special stand alone ffmpeg I compiled with gl-transition in the same folder or reference to its path. You also need a transition you would like to use. I like FilmBurn.glsl . Directory transitions contains transitions from gl-transition project.

The ffmpeg I compiled was done for Debian 64 bit buster. If it complains about dependencies do the following to see what it needs.

# ld fffmpeg

And install those.

Use this concat the videos with audio.

# ./ffmpegHelper.py -c8 ./ffmpeg ./FilmBurn.glsl 1 Y out.mp4

Want to see what other things the code automates with ffmpeg. Do the following.

# ./ffmpegHelper.py -h

How can we Merge Video like 1 video have audio another Video have no audio ..then how can we merge this please Provide Command for this

mansiJspaceo avatar Feb 13 '20 12:02 mansiJspaceo

on Above command there is one issue no concate for silent audio in video file.

merge 2 file like 1 video file have sound & another video file have silent audio

mansiJspaceo avatar Feb 19 '20 04:02 mansiJspaceo

Mansi_spaceO , I forgot to mention this. Yes both video files must have an audio track. If you have a silent video add a silent audio track to it. Currently I do not know of any other way to concat videos using ffmpeg when some have audio tracks while others do not. It is probably possible but what I described was my solution.


From: Mansi_spaceO [email protected] Sent: Tuesday, February 18, 2020 11:10:09 PM To: transitive-bullshit/ffmpeg-gl-transition [email protected] Cc: Motion Design Studio [email protected]; Mention [email protected] Subject: Re: [transitive-bullshit/ffmpeg-gl-transition] How Modify So Videos Remain Origin Length With Audio? (#38)

on Above command there is one issue no concate for silent audio in video file.

merge 2 file like 1 video file have sound & another video file have silent audio

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/transitive-bullshit/ffmpeg-gl-transition/issues/38?email_source=notifications&email_token=ABRPUWSHHXWUDZIXJDR64YDRDSWKDA5CNFSM4HFUPSHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMGI55I#issuecomment-588025589, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABRPUWUQGHX6RXP6JTI72ZLRDSWKDANCNFSM4HFUPSHA.

MotionDesignStudio avatar Feb 19 '20 04:02 MotionDesignStudio

how can i add silent audio ... same length as my Video. can you please share command for this

On Wed, Feb 19, 2020 at 10:03 AM Motion Design Studio < [email protected]> wrote:

Mansi_spaceO , I forgot to mention this. Yes both video files must have an audio track. If you have a silent video add a silent audio track to it. Currently I do not know of any other way to concat videos using ffmpeg when some have audio tracks while others do not. It is probably possible but what I described was my solution.


From: Mansi_spaceO [email protected] Sent: Tuesday, February 18, 2020 11:10:09 PM To: transitive-bullshit/ffmpeg-gl-transition < [email protected]> Cc: Motion Design Studio [email protected]; Mention < [email protected]> Subject: Re: [transitive-bullshit/ffmpeg-gl-transition] How Modify So Videos Remain Origin Length With Audio? (#38)

on Above command there is one issue no concate for silent audio in video file.

merge 2 file like 1 video file have sound & another video file have silent audio

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub< https://github.com/transitive-bullshit/ffmpeg-gl-transition/issues/38?email_source=notifications&email_token=ABRPUWSHHXWUDZIXJDR64YDRDSWKDA5CNFSM4HFUPSHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMGI55I#issuecomment-588025589>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/ABRPUWUQGHX6RXP6JTI72ZLRDSWKDANCNFSM4HFUPSHA

.

β€” You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/transitive-bullshit/ffmpeg-gl-transition/issues/38?email_source=notifications&email_token=ANCAZ4KI3UJ6NAAPICQ4ZITRDSZAZA5CNFSM4HFUPSHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMGKD4A#issuecomment-588030448, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANCAZ4OUKJWWC7LHZ4GSF4LRDSZAZANCNFSM4HFUPSHA .

mansiJspaceo avatar Feb 19 '20 04:02 mansiJspaceo