leandromoreira / ffmpeg-libav-tutorial

FFmpeg libav tutorial - learn how media works from basic to transmuxing, transcoding and more. Translations: πŸ‡ΊπŸ‡Έ πŸ‡¨πŸ‡³ πŸ‡°πŸ‡· πŸ‡ͺπŸ‡Έ πŸ‡»πŸ‡³ πŸ‡§πŸ‡·
https://github.com/leandromoreira/ffmpeg-libav-tutorial
BSD 3-Clause "New" or "Revised" License
9.94k stars 956 forks source link

copy in ffmpeg c++ #65

Closed Niek-Okido closed 4 years ago

Niek-Okido commented 4 years ago

dear,

i am currently stuck now for almost 1 month and still not get the solution , in the commandline tool the following command is what i want ffmpeg -i "video.mp4" -i "audio.mp4" -codec copy -shortest output.mp4

i want to add a new generated video with no sound in it (greated with opencv). to the original video what i need to do in c++ i really stuck now on this for 4 weeks (learn a lot of new things).

i hope you can help me with this , it seems to be very easy but my headache is on the -codec copy -shortest how i can get this succeeded in ffmpeg?

thank in advance if you want to help me with this,

Kind regards Niek Tuytel,

Niek-Okido commented 4 years ago

i hope you will open it if you want to help , thanks in advance

leandromoreira commented 4 years ago

Hey @Niek-Okido

Greeping the FFmpeg source code (git grep shortest) I noticed that shortest is "translated" by this function and there seem to exist a filter for shortest as well:

static void close_output_stream(OutputStream *ost)
{
    OutputFile *of = output_files[ost->file_index];

    ost->finished |= ENCODER_FINISHED;
    if (of->shortest) {
        int64_t end = av_rescale_q(ost->sync_opts - ost->first_pts, ost->enc_ctx->time_base, AV_TIME_BASE_Q);
        of->recording_time = FFMIN(of->recording_time, end);
    }
}
leandromoreira commented 4 years ago

but in reality you could check the duration of the shortest stream and stop to process packets/frames there.

Niek-Okido commented 4 years ago

thank you very much, really needed this help :) thank you very much get it working now ❀️