Log in

View Full Version : FFMPEG - Adding splash image to front of video


lyinawake
28th March 2014, 00:39
I have tried many different ways to try to create a 10 second video file out of an image file and have used all the same switches and codecs as I used to encode my video file. However, when I concat the two using anything but complex_filter (which forces the video through another round of transcoding), the resulting video file is corrupt. I believe this is due to the inherent differences of the 10 second clip that ffmpeg created from the image, but there must be some way to get it to encode the exact same way as my video file.

Here is the command I am using to turn the image into a 10s video clip (I added a silent mp3 because I thought that an audio stream starting partway through the video was messing things up):

ffmpeg -loop 1 -i splash.jpg -i silence.mp3 -c:v libx264 -preset slow -g 60 -r 29.97 -crf 16 -c:a libfdk_aac -b:a 256k -cutoff 18000 -t 5 tmpoutput1.mp4

Here is the command I am using to encode my video:

ffmpeg -i input.f4v -c:v libx264 -preset slow -g 60 -r 29.97 -crf 16 -c:a libfdk_aac -b:a 256k -cutoff 18000 tmpoutput2.mp4

Here is the command I use to convert both of them to .ts to get ready for concat:

ffmpeg -i tmpoutput1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts tmpoutput1.ts

And finally the concat (which is where I get crazy video corruption, everything along the way looks fine):

ffmpeg -i "concat:tmpoutput1.ts|tmpoutput2.ts" -c copy output.mp4

Again, the issue is that I'm already transcoding everything once and I should be able to get it to transcode in a similar enough structure so that it can be concatenated without another transcode tacked onto the end.

Has anyone successfully added a full-frame splash graphic to the front of a video with ffmpeg before? I am using a brand new cross-compile of ffmpeg as I thought that might be the issue, but alas, the issue persists after the update.

Thanks!

poisondeathray
28th March 2014, 01:10
1) It's recommended to use concat demuxer, which works at the stream level, instead of concat protocol which works at the container level
http://trac.ffmpeg.org/wiki/How%20to%20concatenate%20%28join,%20merge%29%20media%20files

2) When using x264, encoding with --stitchable may improve your chances of successfully appending segments. In ffmpeg libx264 it would be -x264-params stitchable

3) There is always a chance something may go wrong when appending segments for whatever reason. A foolproof way would be to join before with a script (eg. avisynth), and encode in 1 go with ffmpeg. ffmpeg can be compiled with avs support.

foxyshadis
28th March 2014, 01:39
Try it with:

ffmpeg .... <input and x264 options> -x264opts sps-id=X <other options>

Where the id is different for each segment (0-31, 0 is default). I certainly hope ffmpeg's concat will keep both SPS parameter sets, I haven't tested. Changing the ID resets the decoder.

Edit: Ah, yes, I forgot about stitchable. With identical settings you won't need different sps-ids in that case.

oxyViz
28th March 2014, 19:02
Just tested what your advised. It works. Commands was:

ffmpeg -i seg01.mkv -c:v libx264 ... -x264opts sps-id=1 ... seg01-sps1.mkv
ffmpeg -i seg02.mkv -c:v libx264 ... -x264opts sps-id=2 ... seg01-sps2.mkv
ffmpeg -i seg03.mkv -c:v libx264 ... -x264opts sps-id=3 ... seg01-sps3.mkv

for f in *.mkv; do ffmpeg -i "$f" -c copy -bsf:v h264_mp4toannexb -sn "$f".ts; done

for f in *.ts; do echo "file '$f'" >> flist.txt; done

ffmpeg -f concat -i flist.txt -c copy -sn concat.mkv I also try concat on *.mkv without remuxing into TS - it doesn't work.

Have one question about SPS ID's - they must be different for all segments or may be reused for segments where encoders params are the same?

Guest
29th March 2014, 23:37
[bump after post approved from mod queue]

lyinawake
31st March 2014, 19:48
Thanks so much for all of your helpful feedback! The answer was actually a very simple one. I did not explicitly set the profile (main), level (3.1), and pix_fmt (yuv420p) in my command line. This has never been a problem for me until trying to work with image files turned to video. For these image videos, ffmpeg autodetects the parameters as a 4:4:4 Predictive L3.1 instead of 4:2:0 Main L3.1. I only found out when I tried to upload my merged videos to be streamed and it only played audio, but trusty ol' VLC played it no problem while I was testing.

After adding those 3 parameters to the command to generate the image video file, I was able to merge the pieces using the basic concat method and did not have to transcode to get everything put together.