Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Modify So Videos Remain Origin Length With Audio? #38

Open
MotionDesignStudio opened this issue Apr 12, 2019 · 15 comments
Open

How Modify So Videos Remain Origin Length With Audio? #38

MotionDesignStudio opened this issue Apr 12, 2019 · 15 comments

Comments

@MotionDesignStudio
Copy link

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

`

@jerryname2022
Copy link

Is there a solution?

@MotionDesignStudio
Copy link
Author

MotionDesignStudio commented Jun 6, 2019 via email

@transitive-bullshit
Copy link
Owner

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

Thanks! 😄

@jerryname2022
Copy link

@MotionDesignStudio How did you do it?

@MotionDesignStudio
Copy link
Author

MotionDesignStudio commented Jun 7, 2019

./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

@transitive-bullshit
Copy link
Owner

(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! 😃

@MotionDesignStudio
Copy link
Author

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

@transitive-bullshit
Copy link
Owner

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

@jerryname2022
Copy link

@MotionDesignStudio Thanks

@jerryname2022
Copy link

@MotionDesignStudio i forked your project

@MotionDesignStudio
Copy link
Author

MotionDesignStudio commented Jun 8, 2019 via email

@mansiJspaceo
Copy link

./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
Copy link

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

@MotionDesignStudio
Copy link
Author

MotionDesignStudio commented Feb 19, 2020 via email

@mansiJspaceo
Copy link

mansiJspaceo commented Feb 19, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants