I have a app which takes in user's video and does some processing. the processing pipeline consists of multiple steps. The code which i have written so far assumes h264 codec for input video. But user's input cant be assumed to be in a particular format/codec so i am thinking of adding one more step at the start of pipeline ie to transcode any given input video to h264. But i am trying to minimise the dataloss in the video because of this step. Also it is possible that user's uploaded video will not be a lossless one infact mostly likely it will be a lossy h264 video.

I can use crf=0 while transcoding the input video

ffmpeg -i input.mp4 -c:v h264 -crf 0 output.mp4

but this results in huge file sizes which impacts the next steps in the pipeline.

Now lets say i use crf=18 for above mentioned transcoding step

ffmpeg -i input.mp4 -c:v h264 -crf 18 output.mp4

and also lets assume the input video also had crf=18 so in this case will this transcoding step result in data loss ?

  • In short: yes. It will make a lossy video even lossy-er. – MonkeyZeus Mar 3 '16 at 14:04
  • What's the processing you do, how much fidelity is required, what's the purpose of the end result? – Gyan Mar 3 '16 at 14:36
  • @Mulvya the tool is supposed to post process a video ie adding text or image overlays on top of videos. its intended to be used by casual users (end videos might end up being shared by users on their social networks etc). – gaurav Mar 3 '16 at 15:01
  • Then lower CRF value to between 12 and 15 and use that. For casual use, it's fine. – Gyan Mar 3 '16 at 15:05

If the source video contains H.264 video, you can simply use -map and -c:v copy to extract the desired stream without transcoding. I would first "probe" the source video to see what streams it contains, then build the "transcode" pipe command with ffmpeg as appropriate:

ffmpeg -i input.mp4 -map 0:1 -c:v copy output.mp4
  • If the source is H.264, the OP can just proceed with their current workflow i.e. process the input itself. – Gyan Mar 4 '16 at 19:13
  • yeah this is a good idea ie to probe the source and then decide if transcode step is needed. Thanks guys. – gaurav Mar 5 '16 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.