Page 3 of 11 FirstFirst 12345 ... LastLast
Results 21 to 30 of 108

Thread: FFmpeg Mplayer VLC - News & Howtos

  1. #21
    Join Date
    Oct 2010
    Location
    London
    Beans
    481
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Concatenation script.....

    After a small amount of tinkering with the examples given in the (typically newbie-unfriendly :/ ) ffmpeg filter documentation, I've found that this command will concatenate two videos:

    Code:
    ffmpeg -i input1.mp4 -i input2.mp4 \
    -filter_complex '[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]' \
    -map '[v]' -map '[a]' <encoding options> output.mp4
    I'll break apart the -filter_complex section, to make it easier to follow

    Code:
    '[0:0] [0:1] [1:0] [1:1]
    This fragment tells ffmpeg what streams to send to the concat filter; in this case, streams 0 and 1 from input 0 (ffmpeg starts counting from 0, so that's the first and second streams from the first input file, input1.mp4 in this example), and streams 0 and 1 from input 1 (input2.mp4).

    Code:
    concat=n=2:v=1:a=1 [v] [a]'
    This is the concat filter itself. n=2 is telling the filter that there are two input files; v=1 is telling it that there will be one video stream; a=1 is telling it that there will be one audio stream (I know I said that ffmpeg starts counting from 0, but apparently the writer of this filter decided to do this instead).

    [v] and [a] are names for the output streams, to allow the rest of the ffmpeg line to use the output of the concat filter. I think they can have arbitrary names; which one is video and which one is audio is probably determined by their relative positions, but I haven't tested that out.

    Note that the single quotes ' ' around the whole filter section are required.

    Code:
    -map '[v]' -map '[a]'
    This tells ffmpeg to use the results of the concat filter rather than the streams directly from the input files.

    Note that filters are incompatible with stream copying; you can't use -c copy with this method. I also think that it can't handle soft subtitles, though I haven't tested that: there's no hint about it in the documentation, but ffmpeg documentation is often incomplete or obfuscated, so that's not a sure sign either way.

    This can concatenate files encoded in different formats (I've tested with a h264/aac MP4 and a vpx/vorbis WEBM, worked perfectly), though they need to be the same video frame size and audio sample rate and etc. So the concat filter can be used instead of that script. Here are some examples that should come in useful.

    To concatenate two files into a decent-quality h264 video/AAC audio MP4:

    Code:
    ffmpeg -i input1.mp4 -i input2.webm \
    -filter_complex '[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]' \
    -map '[v]' -map '[a]' -c:v libx264 -crf 25 -preset veryfast -c:a libfdk_aac -vbr 3 output.mp4
    Three files, same output settings:

    Code:
    ffmpeg -i input1.mp4 -i input2.webm -i input3.ogg \
    -filter_complex '[0:0] [0:1] [1:0] [1:1] [2:0] [2:1] concat=n=3:v=1:a=1 [v] [a]' \
    -map '[v]' -map '[a]' -c:v libx264 -crf 25 -preset veryfast -c:a libfdk_aac -vbr 3 output.mp4
    Three files, but with two audio streams (e.g. different languages) rather than one:

    Code:
    ffmpeg -i input1.mp4 -i input2.webm -i input3.ogg \
    -filter_complex '[0:0] [0:1] [0:2] [1:0] [1:1] [1:2] [2:0] [2:1] [2:2] concat=n=3:v=1:a=2 [v] [a1] [a2]' \
    -map '[v]' -map '[a1]' -map '[a2]' -c:v libx264 -crf 25 -preset veryfast -c:a libfdk_aac -vbr 3 output.mp4
    THE FOLLOWING IS UNTESTED, AND I'M 90% SURE IT WON'T WORK, but if anyone wants to test it out, feel free - if it is possible, this should concatenate a subtitle stream as well:

    Code:
    ffmpeg -i input1.mp4 -i input2.mp4 \
    -filter_complex '[0:0] [0:1] [0:2] [1:0] [1:1] [1:2] concat=n=2:v=1:a=1:s=1 [v] [a] [s]' \
    -map '[v]' -map '[a]' -map '[s]' -c:v libx264 -crf 25 -preset veryfast -c:a libfdk_aac -vbr 3 -c:s *** output.mp4
    Last edited by evilsoup; January 3rd, 2013 at 02:20 PM.

  2. #22
    Join Date
    Oct 2010
    Location
    London
    Beans
    481
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: FFmpeg Mplayer VLC - News & Howtos

    Quote Originally Posted by andrew.46 View Post
    I keep a relatively clean Quantal VM and it is not there
    Well, that's annoying. One more reason for people to upgrade to ffmpeg, I suppose.

    Would it be possible for you to do the same thing with the ffmpeg from Jon Severinsson's PPA?

  3. #23
    Join Date
    Oct 2010
    Location
    London
    Beans
    481
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: audio bulk convert

    To recursively convert files (so do every *flac in a directory, and in directory within that directory), you can use find. This will convert all FLACs to MP3 with a quality setting of 2 (indiscernible from CD quality for most people):

    Code:
    find . -type f -name *.flac -exec bash -c 'ffmpeg -i "$0" -c:a libmp3lame -q:a 2 "${0/%flac/mp3}"' {} \;

  4. #24
    Join Date
    Jul 2012
    Beans
    318
    Distro
    Xubuntu 16.04 Xenial Xerus

    Re: Concatenation script.....

    Nice work on the concat stuff evilsoup - without you explaining it all I'd have given up after the first line of explanation in the examples
    The best things in life are free, so what are we paying for?

  5. #25
    Join Date
    Sep 2006
    Beans
    3,713

    Re: FFmpeg Mplayer VLC - News & Howtos

    Quote Originally Posted by evilsoup View Post
    Would it be possible for you to do the same thing with the ffmpeg from Jon Severinsson's PPA?
    The concat filter is also not available in ffmpeg from Jon Severinsson's PPA.

  6. #26
    Join Date
    Oct 2010
    Location
    London
    Beans
    481
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: FFmpeg Mplayer VLC - News & Howtos

    What about the subtitles filter?

  7. #27
    Join Date
    Sep 2006
    Beans
    3,713

    Re: FFmpeg Mplayer VLC - News & Howtos

    No, unfortunately. It's too new for the current PPA build and I don't know if it has been backported to any releases. See the filter list for the PPA ffmpeg for more info.

  8. #28
    Join Date
    Oct 2010
    Location
    London
    Beans
    481
    Distro
    Ubuntu 12.04 Precise Pangolin

    Speeding up / slowing down video & audio

    Note: these filters may or may not be available in the repo or Jon-Severinsson version, I'm not sure how new they are.

    You can speed up video with the setpts video filter:

    Code:
    ffmpeg -i input.mkv -an -filter:v 'setpts=0.5*PTS' [output options] output.mkv
    Generally, use it like this: 'setpts=x*PTS', where x is 1/the speed you want. So if you want to double the speed, then 1/2 gets you 'setpts=0.5*PTS'; if you want to halve the speed, then 1/0.5 gets you 'setpts=2*PTS'.

    You can speed up audio with the atempo audio filter:

    Code:
    ffmpeg -i input.mkv -vn -filter:a 'atempo=2.0' [output options] output.mkv
    The value here works in the exact opposite way to the setpts example; if you want to double the speed, put in 2.0, and if you want to halve it use 0.5. This filter is limited to the range 0.5-2.0; if you need to work outside that range, you have to chain multiple atempo filters together. To quadruple the speed of some audio:

    Code:
    ffmpeg -i input.mkv -vn -filter:a 'atempo=2.0,atempo=2.0' [output options] output.mkv
    Note that this can be tricky: the two atempo filters effectively multiply their values, rather than adding them together. Some arithmatic would be needed.

    You can combine these two filters together in a complex filtergraph. To double the speed of both video and audio at the same time:

    Code:
    ffmpeg -i input.mkv -filter_complex '[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]' \
    -map '[v]' -map '[a]' [output options] output.mkv
    If you have two audio streams, and you want to speed up both of them, you can use:

    Code:
    ffmpeg -i input.mkv \
    -filter_complex '[0:v]setpts=0.5*PTS[v];[0:a:0]atempo=2.0[a0];[0:a:1]atempo=2.0[a1]' \
    -map '[v]' -map '[a0]' -map '[a1]' [output options] output.mkv
    I've also put this information (well, the atempo stuff; the setpts stuff was there already) up on the ffmpeg community wiki
    Last edited by evilsoup; January 9th, 2013 at 02:19 PM.

  9. #29
    Join Date
    Sep 2006
    Beans
    3,713

    Re: Speeding up / slowing down video & audio

    x264 minimum Yasm version now appears to be 1.2.0 as of the latest push. I updated How To Compile FFmpeg and x264 on Ubuntu to include Yasm compilation since repository versions are old.

  10. #30
    Join Date
    Oct 2010
    Location
    London
    Beans
    481
    Distro
    Ubuntu 12.04 Precise Pangolin

    Ripping DVDs with FFmpeg and Vobcopy

    If you have a decrypted ISO of a DVD movie, you can use ffmpeg's concat protocol (the demuxer will also work, but I've found the protocol to be more reliable for these things).

    Code:
    sudo mkdir /media/fakedvd
    sudo mount -o loop movie.iso /media/fakedvd
    cd /media/fakedvd
    ffmpeg -i "concat:VTS_02_1.VOB|VTS_02_2.VOB|VTS_02_3.VOB|VTS_02_4.VOB|VTS_02_5.VOB" \
    -c:a copy -c:v libx264 -crf:v 22 -preset:v veryfast ~/Videos/output.mp4
    Normally, the VTS_xx_n.VOB with the most entries is the main feature of the DVD (the rest are anti-piracy warnings, trailers, deleted scenes, etc). VTS_xx_0.VOB is normally the DVD menu, so you can ignore it.

    Obviously, the above method involves creating a huge intermediate ISO file. FFmpeg has no way of reading encrypted DVDs. Fortunately, there's another command-line program that can use the libdvdcss stuff, and avoid having to use ffmpeg's concat protocol: vobcopy.

    Code:
    vobcopy -l -o - | ffmpeg -i - -c:a copy -c:v libx264 -crf:v 22 -preset:v veryfast output.mp4
    Vobcopy should automatically detect where your DVD is mounted, and it can normally detect which VOB files to use automatically. The `-l` option tells vobcopy to output a single, large file (normally it outputs to 2GB files, to be safe on older systems that don't support large files); `-o -` tells vobcopy to output to STDOUT, which this command pipes into ffmpeg. For more information on vobcopy, look at its man page.

Page 3 of 11 FirstFirst 12345 ... LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •