Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
tool to *merge* video - not convert..
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
Dieter.Soltau
n00b
n00b


Joined: 27 Nov 2011
Posts: 68

PostPosted: Sun Sep 30, 2012 4:50 pm    Post subject: tool to *merge* video - not convert.. Reply with quote

hi folx,
i am looking for a simple tool to *merge* videoclips. all are same size and quality. it could either be commandline, KDE/GTK or even win7 (that i run in vbox).

a really nice tool is *avidemux* - that does its job perfectly.. just merging the clips and doing a copy to disk.. but i can not select *multiple* files to append. adding single files only is a real PIA..

so, anyone has a solution to this problem?
Back to top
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Sun Sep 30, 2012 8:08 pm    Post subject: Reply with quote

Avidemux should work, just drag all files into the window or use the CLI. Alternatively, mencoder (from mplayer package) and ffmpeg can do it, too.
_________________
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Back to top
View user's profile Send private message
salahx
Guru
Guru


Joined: 12 Mar 2005
Posts: 556

PostPosted: Sun Sep 30, 2012 10:03 pm    Post subject: Reply with quote

Actually several years i created a shell script to do exactly that. It needs ffmpeg and mplayer.

ffmpeg-concat.sh:

#!/bin/bash

cleanup()
{
   kill `ps --ppid $$ -o pid --no-header` > /dev/null 2>&1
   find -maxdepth 1 -mindepth 1 -type p -delete
}

trap cleanup 0

declare -a INPUTFILES
declare -a INPUT_VIDEO_HEIGHT
declare -a INPUT_VIDEO_WIDTH
declare -a INPUT_VIDEO_FPS
declare -a INPUT_AUDIO_RATE
declare -a INPUT_AUDIO_NCH
declare -i INPUTCOUNT=0

while getopts :i: MYOPTS
do
   case $MYOPTS in
   i)   if [ -z "$INPUTTRAP" ]
      then
         INPUTFILES[${INPUTCOUNT}]="${OPTARG}"
         (( INPUTCOUNT++ ))
      else
         echo "Error: All input files must procede ffmpeg options"
         exit 1
      fi
      ;;   
   :)   echo "Error: -i requires an argument"
      exit;
      ;;
   \?)   INPUTTRAP=1
      ;;
   esac
done

if [ "$INPUTCOUNT" -le 0 ]
then
   echo "Error: You must specificy at least 1 input file!"
   exit 1
fi

shift $(expr "$INPUTCOUNT" \* 2 )

for ((I = 0; I < "$INPUTCOUNT"; I++))
do
   while read MPLAYERIDENTIFY
   do
      case "${MPLAYERIDENTIFY/%=*/}" in
         ID_VIDEO_HEIGHT) INPUT_VIDEO_HEIGHT[${I}]="${MPLAYERIDENTIFY/#*=/}" ;;
         ID_VIDEO_WIDTH)  INPUT_VIDEO_WIDTH[${I}]="${MPLAYERIDENTIFY/#*=/}" ;;
         ID_VIDEO_FPS)    INPUT_VIDEO_FPS[${I}]="${MPLAYERIDENTIFY/#*=/}" ;;
         ID_AUDIO_RATE)   INPUT_AUDIO_RATE[${I}]="${MPLAYERIDENTIFY/#*=/}" ;;
         ID_AUDIO_NCH)    INPUT_AUDIO_NCH[${I}]="${MPLAYERIDENTIFY/#*=/}" ;;
      esac
   done < <(mplayer -identify -frames 0 "${INPUTFILES[${I}]}" 2> /dev/null)
done

{
   for ((I = 0; I < "$INPUTCOUNT"; I++))
   do
      mkfifo    "${INPUTFILES[${I}]}".{yuv,pcm}
      ffmpeg  -i "${INPUTFILES[${I}]}" -an -f rawvideo - > "${INPUTFILES[${I}]}.yuv" &
      ffmpeg  -i "${INPUTFILES[${I}]}" -vn -f s16le -acodec pcm_s16le \
         -ac "${INPUT_AUDIO_NCH[${I}]}" -ar "${INPUT_AUDIO_RATE[${I}]}" - > "${INPUTFILES[${I}]}.pcm"  &
   done

   mkfifo video.yuv
   mkfifo audio.pcm

   cat "${INPUTFILES[@]/%/.yuv}" > video.yuv &
   cat "${INPUTFILES[@]/%/.pcm}" > audio.pcm &
} 0</dev/null 1>/dev/null 2>&1

ffmpeg   -f rawvideo -r "${INPUT_VIDEO_FPS[0]}" -s "${INPUT_VIDEO_WIDTH[0]}"x"${INPUT_VIDEO_HEIGHT[0]}" -pix_fmt yuv420p -i video.yuv \
   -f s16le -acodec pcm_s16le -ac "${INPUT_AUDIO_NCH[0]}" -ar "${INPUT_AUDIO_RATE[0]}" -i audio.pcm \
   "$@"


To use it, do something like "ffmpeg-conat.sh" -i file1 -i file2 -i file3 ... and the usual ffmpeg options after the input files. So, for example:
Code:

./ffmpeg-concat.sh i "9/11 2000 AND FUN - Starring James Woods - CD1.avi" -i  "9/11 2000 AND FUN - Starring James Woods - CD2.avi" -target ntsc-dvd -aspect 16:9 -y "9/11 2000 AND FUN - Starring James Woods.mpg"
Back to top
View user's profile Send private message
Dieter.Soltau
n00b
n00b


Joined: 27 Nov 2011
Posts: 68

PostPosted: Wed Oct 03, 2012 3:08 pm    Post subject: Reply with quote

avx wrote:
Avidemux should work, just drag all files into the window or use the CLI. Alternatively, mencoder (from mplayer package) and ffmpeg can do it, too.

duh! looks like avidemux actuallx does that.. however.. those movies are done with a canon powershot, and avidemux complains everytime that the B field is preference.. and if i would like to fix that. so i have to deny this for every single clip.. hmm..
Back to top
View user's profile Send private message
Dieter.Soltau
n00b
n00b


Joined: 27 Nov 2011
Posts: 68

PostPosted: Wed Oct 03, 2012 3:10 pm    Post subject: Reply with quote

salahx wrote:

To use it, do something like "ffmpeg-conat.sh" -i file1 -i file2 -i file3 ... and the usual ffmpeg options after the input files. So, for example:
Code:

./ffmpeg-concat.sh i "9/11 2000 AND FUN - Starring James Woods - CD1.avi" -i  "9/11 2000 AND FUN - Starring James Woods - CD2.avi" -target ntsc-dvd -aspect 16:9 -y "9/11 2000 AND FUN - Starring James Woods.mpg"


err.. sometimes there are about 64 clips! and i do not want to transcode or convert, just MERGE the files, hm.. nixe script tho ;)
Back to top
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Wed Oct 03, 2012 3:22 pm    Post subject: Reply with quote

Code:
#!/bin/bash

INPUTS=""
for i in ${@} ; do INPUTS+="-i ${i} " ; done
ffmpeg ${INPUTS} -acodec copy -vcodec copy output.file


Call it with `script.sh *.avi`, provided the files follow a logical naming scheme, f.e. 000.avi ... 099.avi.
_________________
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Back to top
View user's profile Send private message
Dieter.Soltau
n00b
n00b


Joined: 27 Nov 2011
Posts: 68

PostPosted: Wed Oct 03, 2012 3:48 pm    Post subject: Reply with quote

avx wrote:
Code:
#!/bin/bash

INPUTS=""
for i in ${@} ; do INPUTS+="-i ${i} " ; done
ffmpeg ${INPUTS} -acodec copy -vcodec copy output.file


Call it with `script.sh *.avi`, provided the files follow a logical naming scheme, f.e. 000.avi ... 099.avi.


that looks pretty slick.. they are blabla1671.mov to blabla1972.mov - inbetween some are missing, hope that doesnt matter, but i get your drift.. will try asap, thx

bash FTW ;)
Back to top
View user's profile Send private message
Dieter.Soltau
n00b
n00b


Joined: 27 Nov 2011
Posts: 68

PostPosted: Wed Oct 03, 2012 3:54 pm    Post subject: Reply with quote

hmm..

Code:
[NULL @ 0x30c1b20] Unable to find a suitable output format for 'output.file'
output.file: Invalid argument
Back to top
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Wed Oct 03, 2012 4:00 pm    Post subject: Reply with quote

Sure, you need to set it to 'output.avi' or 'output.mpg' or whatever container you have.
_________________
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Back to top
View user's profile Send private message
Dieter.Soltau
n00b
n00b


Joined: 27 Nov 2011
Posts: 68

PostPosted: Wed Oct 03, 2012 4:03 pm    Post subject: Reply with quote

avx wrote:
Sure, you need to set it to 'output.avi' or 'output.mpg' or whatever container you have.

i did, but then only the first file is exported.. ?? i set it to "new.mov"

however, i see on the screen it is reading in all files fine..
Back to top
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Wed Oct 03, 2012 4:19 pm    Post subject: Reply with quote

Strange, but ok. You can try [url=http://ffmpeg.org/trac/ffmpeg/wiki/How%20to%20concatenate%20(join,%20merge)%20media%20files]this script[/url] - it's pretty well documented, just need to make some changes.

If you don't need to keep the container as .mov, you could do it easily with `mkvmerge`(cli) or `mmg`, both from media-video/mkvtoolnix.
_________________
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Back to top
View user's profile Send private message
Dieter.Soltau
n00b
n00b


Joined: 27 Nov 2011
Posts: 68

PostPosted: Wed Oct 03, 2012 4:28 pm    Post subject: Reply with quote

avx wrote:
Strange, but ok. You can try [url=http://ffmpeg.org/trac/ffmpeg/wiki/How%20to%20concatenate%20(join,%20merge)%20media%20files]this script[/url] - it's pretty well documented, just need to make some changes.

If you don't need to keep the container as .mov, you could do it easily with `mkvmerge`(cli) or `mmg`, both from media-video/mkvtoolnix.

above link pls put in
Code:
 ..
.. totaly broken.

mkvmerge i did, gives warnings, and results in no output neither with vlc nor dragon player..
anyway, i would love to keep the format it was in.. why bother with containers, hmm..

it is just supposed to be a backup of my sourcemovie(s) - and i dislike to have that many files in my folders.....
Back to top
View user's profile Send private message
salahx
Guru
Guru


Joined: 12 Mar 2005
Posts: 556

PostPosted: Thu Oct 04, 2012 4:55 pm    Post subject: Reply with quote

By "merge" do you mean concatenate them together? If so the transcoding step is generally unavoidable - most formats are not concatenatable, they have converted to a format that is (like raw yuv/pcm), cat'd together then re-encoded. The decoding is loseless but hte re-encoding is lossy if the original format was.

You can still use the script even with 64 movies fairly easily:
Code:
./ffmpeg-concat "-i file00"{00..63}.avi
Back to top
View user's profile Send private message
Fitzcarraldo
Advocate
Advocate


Joined: 30 Aug 2008
Posts: 2055
Location: United Kingdom

PostPosted: Fri Oct 05, 2012 10:45 am    Post subject: Reply with quote

Just in case it's still of any use: How to join together several Flash video (flv) files.
It discusses several GUI tools and command line techniques with examples. Despite the title, they do not only apply to Flash video.
_________________
Clevo W230SS: amd64, VIDEO_CARDS="intel modesetting nvidia".
Compal NBLB2: ~amd64, xf86-video-ati. Dual boot Win 7 Pro 64-bit.
OpenRC systemd-utils[udev] elogind KDE on both.

My blog
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Fri Oct 05, 2012 1:45 pm    Post subject: Reply with quote

My video recorder records television programmes to FAT filesystem and splits files every 2G

I join them back together using ffmpeg using the concat syntax. also reencode to x264 but I guess it should work with copy codecs.

Code:

    inputs=`echo *.ts | sed -e "s@ @|@g"`

    ffmpeg -i concat:"$inputs" -map 0:v -map 0:a -threads 2 -vf yadif=0:-1:1 -vcodec libx264 -vpre fast -crf 22 -nr 300 -c:a libvorbis -aq 4 -async 1024 -y "$TARGET"/"$block".mkv


if the source format is a pure stream you could also just cat a b c > abc
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum