사용자 도구

사이트 도구


ffmpegjoin

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

ffmpegjoin [2013/12/20 20:08]
minetech
ffmpegjoin [2015/04/27 18:41] (현재)
minetech
줄 3: 줄 3:
  
   * 영상을 합칠때는 경험상 먼저 ts 파일로 변환하여 ts로합쳐야 정상으로 플레이됨,​ 그렇치 않으면 싱크가 안맞음)   * 영상을 합칠때는 경험상 먼저 ts 파일로 변환하여 ts로합쳐야 정상으로 플레이됨,​ 그렇치 않으면 싱크가 안맞음)
-<WRAP center round box 80%>+<code>
 C:​\JangDoc\MediaTown\ffmpeg-20130205\bin\ffmpeg -i 20131212-3교시-정은경1_720.f4v.mp4 -i 20131212-3교시-정은경2_720.f4v.mp4 ​ -c copy 20131212-3교시-정은경_720.f4v.mp4 C:​\JangDoc\MediaTown\ffmpeg-20130205\bin\ffmpeg -i 20131212-3교시-정은경1_720.f4v.mp4 -i 20131212-3교시-정은경2_720.f4v.mp4 ​ -c copy 20131212-3교시-정은경_720.f4v.mp4
  
-</WRAP>+</code>
  
   * 영상합치기 위해 먼저 mp4 파일을 ts 파일로 먼저 변환   * 영상합치기 위해 먼저 mp4 파일을 ts 파일로 먼저 변환
-<WRAP center round box 80%>+<code>
 C:​\JangDoc\MediaTown\ffmpeg-20130205\bin\ffmpeg -i 20131212-3교시-정은경1_720.f4v.mp4 -c copy -bsf h264_mp4toannexb temp0.ts C:​\JangDoc\MediaTown\ffmpeg-20130205\bin\ffmpeg -i 20131212-3교시-정은경1_720.f4v.mp4 -c copy -bsf h264_mp4toannexb temp0.ts
 C:​\JangDoc\MediaTown\ffmpeg-20130205\bin\ffmpeg -i 20131212-3교시-정은경2_720.f4v.mp4 -c copy -bsf h264_mp4toannexb temp1.ts C:​\JangDoc\MediaTown\ffmpeg-20130205\bin\ffmpeg -i 20131212-3교시-정은경2_720.f4v.mp4 -c copy -bsf h264_mp4toannexb temp1.ts
-</WRAP>+</code>
  
   * 두 개의 ts 파일을 이용해 영상합친후 mp4파일로 변환하여 생성   * 두 개의 ts 파일을 이용해 영상합친후 mp4파일로 변환하여 생성
-<WRAP center round box 80%>+<code>
 C:​\JangDoc\MediaTown\ffmpeg-20130205\bin\ffmpeg -i "​concat:​temp0.ts|temp1.ts"​ -c copy -absf aac_adtstoasc 20131212-3교시-정은경_720.f4v.mp4 C:​\JangDoc\MediaTown\ffmpeg-20130205\bin\ffmpeg -i "​concat:​temp0.ts|temp1.ts"​ -c copy -absf aac_adtstoasc 20131212-3교시-정은경_720.f4v.mp4
  
-</WRAP>+</code>
  
  
-= Concatenating media files =+===== 여기서 부터 추가 내용 ===== 
 + 
 +=== Concatenating media files ===
  
 [[PageOutline(2-3,​ Contents)]] [[PageOutline(2-3,​ Contents)]]
줄 28: 줄 30:
  
  
-== Concatenation of files with same codecs ==#​samecodec+== Concatenation of files with same codecs == 
 +#samecodec
  
 There are two methods within ffmpeg that can be used to concatenate files of the same type: [#demuxer the concat ''​demuxer''​] and [#protocol the concat ''​protocol''​]. The demuxer is more flexible - it requires the same codecs, but different container formats can be used; and it can be used with any container formats, while the protocol only works with a select few containers. However, the concat protocol is available in older versions of ffmpeg, where the demuxer isn't. There are two methods within ffmpeg that can be used to concatenate files of the same type: [#demuxer the concat ''​demuxer''​] and [#protocol the concat ''​protocol''​]. The demuxer is more flexible - it requires the same codecs, but different container formats can be used; and it can be used with any container formats, while the protocol only works with a select few containers. However, the concat protocol is available in older versions of ffmpeg, where the demuxer isn't.
  
-=== Concat demuxer ===#demuxer+=== Concat demuxer === 
 +#demuxer
  
 The concat demuxer was added to ffmpeg 1.1 . You can read about it in the [http://​ffmpeg.org/​ffmpeg-formats.html#​concat documentation]. The concat demuxer was added to ffmpeg 1.1 . You can read about it in the [http://​ffmpeg.org/​ffmpeg-formats.html#​concat documentation].
줄 39: 줄 43:
  
 Create a file "​mylist.txt"​ with all the files you want to have concatenated in the following form ( Lines starting with a dash are ignored ) : Create a file "​mylist.txt"​ with all the files you want to have concatenated in the following form ( Lines starting with a dash are ignored ) :
-{{{+ 
 +<​code>​
 # this is a comment # this is a comment
 file '/​path/​to/​file1'​ file '/​path/​to/​file1'​
 file '/​path/​to/​file2'​ file '/​path/​to/​file2'​
 file '/​path/​to/​file3'​ file '/​path/​to/​file3'​
-}}}+</​code>​ 
  
 Note that these can be either relative or absolute paths. Then you can encode your files with: Note that these can be either relative or absolute paths. Then you can encode your files with:
-{{{+ 
 +<​code>​
 ffmpeg -f concat -i mylist.txt -c copy output ffmpeg -f concat -i mylist.txt -c copy output
-}}}+</​code>​
  
 It is possible to generate this list file with a bash for loop, or using printf. Either one of the following would generate a list file containing every *.wav in the working directory: It is possible to generate this list file with a bash for loop, or using printf. Either one of the following would generate a list file containing every *.wav in the working directory:
  
-{{{+<​code>​
 for f in ./*.wav; do echo "file '​$f'"​ >> mylist.txt; done for f in ./*.wav; do echo "file '​$f'"​ >> mylist.txt; done
 printf "file '​%s'​\n"​ ./*.wav > mylist.txt printf "file '​%s'​\n"​ ./*.wav > mylist.txt
-}}}+</​code>​
  
 If your shell supports process substitution (like Bash and Zsh), you can avoid explicitly creating a list file and do the whole thing in a single line. This would be impossible with the concat protocol (see below): If your shell supports process substitution (like Bash and Zsh), you can avoid explicitly creating a list file and do the whole thing in a single line. This would be impossible with the concat protocol (see below):
  
-{{{+<​code>​
 ffmpeg -f concat -i <(for f in ./*.wav; do echo "file '​$f'";​ done) -c copy output.wav ffmpeg -f concat -i <(for f in ./*.wav; do echo "file '​$f'";​ done) -c copy output.wav
 ffmpeg -f concat -i <(printf "file '​%s'​\n"​ ./*.wav) -c copy output.wav ffmpeg -f concat -i <(printf "file '​%s'​\n"​ ./*.wav) -c copy output.wav
 ffmpeg -f concat -i <(find . -name '​*.wav'​ -printf "file '​%p'​\n"​) -c copy output.wav ffmpeg -f concat -i <(find . -name '​*.wav'​ -printf "file '​%p'​\n"​) -c copy output.wav
-}}}+</​code>​
  
-=== Concat protocol ===#​protocol+=== Concat protocol === 
 +#protocol
  
 While the demuxer works at the stream level, the concat protocol works at the file level. Certain files (mpg and mpeg transport streams, possibly others) can be concatenated. This is analogous to using cat on UNIX-like systems or copy on Windows. In general, the demuxer is the better option. While the demuxer works at the stream level, the concat protocol works at the file level. Certain files (mpg and mpeg transport streams, possibly others) can be concatenated. This is analogous to using cat on UNIX-like systems or copy on Windows. In general, the demuxer is the better option.
줄 72: 줄 80:
 ==== Instructions ==== ==== Instructions ====
  
-{{{+<​code>​
 ffmpeg -i "​concat:​input1.mpg|input2.mpg|input3.mpg"​ -c copy output.mpg ffmpeg -i "​concat:​input1.mpg|input2.mpg|input3.mpg"​ -c copy output.mpg
-}}}+</​code>​
  
 If you have MP4 files, these could be losslessly concatenated by first transcoding them to mpeg transport streams. With h.264 video and AAC audio, the following can be used: If you have MP4 files, these could be losslessly concatenated by first transcoding them to mpeg transport streams. With h.264 video and AAC audio, the following can be used:
  
-{{{+<​code>​
 ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
 ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
 ffmpeg -i "​concat:​intermediate1.ts|intermediate2.ts"​ -c copy -bsf:a aac_adtstoasc output.mp4 ffmpeg -i "​concat:​intermediate1.ts|intermediate2.ts"​ -c copy -bsf:a aac_adtstoasc output.mp4
-}}}+</​code>​
  
 If you're using a system that supports named pipes, you can use those to avoid creating intermediate files - this sends stderr (which ffmpeg sends all the written data to) to /dev/null, to avoid cluttering up the command-line:​ If you're using a system that supports named pipes, you can use those to avoid creating intermediate files - this sends stderr (which ffmpeg sends all the written data to) to /dev/null, to avoid cluttering up the command-line:​
  
-{{{+<​code>​
 mkfifo temp1 temp2 mkfifo temp1 temp2
 ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1 2> /dev/null & \ ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1 2> /dev/null & \
 ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp2 2> /dev/null & \ ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp2 2> /dev/null & \
 ffmpeg -f mpegts -i "​concat:​temp1|temp2"​ -c copy -bsf:a aac_adtstoasc output.mp4 ffmpeg -f mpegts -i "​concat:​temp1|temp2"​ -c copy -bsf:a aac_adtstoasc output.mp4
-}}}+</​code>​
  
 All MPEG codecs (h.264, MPEG4/​divx/​xvid,​ MPEG2; MP2, MP3, AAC) are supported in the mpegts container format, though the commands above would require some alteration (the -bsf bitstream filters will have to be changed). All MPEG codecs (h.264, MPEG4/​divx/​xvid,​ MPEG2; MP2, MP3, AAC) are supported in the mpegts container format, though the commands above would require some alteration (the -bsf bitstream filters will have to be changed).
  
-== Concatenation of files with different codecs ==#​differentcodec+== Concatenation of files with different codecs == 
 +#​differentcodec
  
-=== Concat filter ===#filter+=== Concat filter === 
 +#filter
  
 The concat filter is available in recent versions of ffmpeg. [http://​ffmpeg.org/​ffmpeg-filters.html#​concat Here] is the official documentation. The concat filter is available in recent versions of ffmpeg. [http://​ffmpeg.org/​ffmpeg-filters.html#​concat Here] is the official documentation.
줄 105: 줄 115:
 This is easiest to explain using an example: This is easiest to explain using an example:
  
-{{{+<​code>​
 ffmpeg -i input1.mp4 -i input2.webm \ 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]' \ -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.mkv -map '​[v]'​ -map '​[a]'​ <​encoding options> output.mkv
-}}}+</​code>​
  
 On the -filter_complex line, the following: On the -filter_complex line, the following:
  
-{{{+<​code>​
 '[0:0] [0:1] [1:0] [1:1] '[0:0] [0:1] [1:0] [1:1]
-}}}+</​code>​
  
 tells ffmpeg what streams to send to the concat filter; in this case, streams 0 and 1 from input 0 (input1.mp4 in this example), and streams 0 and 1 from input 1 (input2.webm). tells ffmpeg what streams to send to the concat filter; in this case, streams 0 and 1 from input 0 (input1.mp4 in this example), and streams 0 and 1 from input 1 (input2.webm).
  
-{{{+<​code>​
 concat=n=2:​v=1:​a=1 [v] [a]' concat=n=2:​v=1:​a=1 [v] [a]'
-}}}+</​code>​
  
 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. [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. 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. [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.
줄 127: 줄 137:
 Note that the single quotes ' ' around the whole filter section are required. Note that the single quotes ' ' around the whole filter section are required.
  
-{{{+<​code>​
 -map '​[v]'​ -map '​[a]'​ -map '​[v]'​ -map '​[a]'​
-}}}+</​code>​
  
 This tells ffmpeg to use the results of the concat filter rather than the streams directly from the input files. This tells ffmpeg to use the results of the concat filter rather than the streams directly from the input files.
줄 137: 줄 147:
 As you can infer from this example, multiple types of input are supported, anything readable by ffmpeg should work. The inputs have to be of the same frame size, and a handful of other attributes have to match. As you can infer from this example, multiple types of input are supported, anything readable by ffmpeg should work. The inputs have to be of the same frame size, and a handful of other attributes have to match.
  
-=== Using an external script ===#​extscript+=== Using an external script === 
 +#extscript
  
 The following script can be used to concatenate multiple input media files (containing audio/video streams) into one output file (just like as if all the inputs were played in a playlist, one after another). It is based on this FAQ item: [http://​ffmpeg.org/​faq.html#​How-can-I-concatenate-video-files_003f How can I join video files], which also contains other useful information. The following script can be used to concatenate multiple input media files (containing audio/video streams) into one output file (just like as if all the inputs were played in a playlist, one after another). It is based on this FAQ item: [http://​ffmpeg.org/​faq.html#​How-can-I-concatenate-video-files_003f How can I join video files], which also contains other useful information.
줄 146: 줄 157:
  
 Save the script in a file named "​mmcat"​ (or some other name), make it executable (chmod +x mmcat) and run it, using the syntax: Save the script in a file named "​mmcat"​ (or some other name), make it executable (chmod +x mmcat) and run it, using the syntax:
-{{{+ 
 +<​code>​
 ./mmcat <​input1>​ <​input2>​ <​input3>​ ... <​output>​ ./mmcat <​input1>​ <​input2>​ <​input3>​ ... <​output>​
-}}}+</​code>​ 
  
 If you get an error like this: If you get an error like this:
-{{{+ 
 +<​code>​
 #/​tmp/​mcs_v_all:​ Operation not permitted #/​tmp/​mcs_v_all:​ Operation not permitted
-}}}+</​code>​ 
 that could mean that you don't have correct permissions set on /tmp directory (or whatever you set in TMP variable) or that decoding of your input media has failed for some reason. In this case, it would be the best to turn on the logging (described in the script'​s comments) that could mean that you don't have correct permissions set on /tmp directory (or whatever you set in TMP variable) or that decoding of your input media has failed for some reason. In this case, it would be the best to turn on the logging (described in the script'​s comments)
  
 ==== Script ==== ==== Script ====
  
-{{{+<​code>​
 #!/bin/bash #!/bin/bash
  
줄 295: 줄 310:
 ################################################################################​ ################################################################################​
 rm -f $TMP/mcs_* rm -f $TMP/mcs_*
-}}}+</​code>​ 
ffmpegjoin.1387537726.txt.gz · 마지막으로 수정됨: 2013/12/20 20:08 저자 minetech