Data loss due to transcoding video[ffmpeg]

1

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 ?

gaurav

Posted 2016-03-03T13:39:38.937

Reputation: 13

In short: yes. It will make a lossy video even lossy-er. – MonkeyZeus – 2016-03-03T14:04:21.227

What's the processing you do, how much fidelity is required, what's the purpose of the end result? – Gyan – 2016-03-03T14:36:09.447

@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 – 2016-03-03T15:01:55.010

Then lower CRF value to between 12 and 15 and use that. For casual use, it's fine. – Gyan – 2016-03-03T15:05:40.927

Answers

1

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

Shane Harrelson

Posted 2016-03-03T13:39:38.937

Reputation: 117

If the source is H.264, the OP can just proceed with their current workflow i.e. process the input itself. – Gyan – 2016-03-04T19:13:24.563

yeah this is a good idea ie to probe the source and then decide if transcode step is needed. Thanks guys. – gaurav – 2016-03-05T20:08:58.667